@@ -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 && $this->capture ) ? '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 && $this->capture) ? '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_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
563 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
564 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
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_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
563 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
564 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
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,45 +631,45 @@ 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 ); |
|
636 | + $order = wc_get_order($order_id); |
|
637 | 637 | |
638 | 638 | // This comes from the create account checkbox in the checkout page. |
639 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
639 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
640 | 640 | |
641 | - if ( $create_account ) { |
|
641 | + if ($create_account) { |
|
642 | 642 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
643 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
643 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
644 | 644 | $new_stripe_customer->create_customer(); |
645 | 645 | } |
646 | 646 | |
647 | 647 | $source_object = $this->create_source_object(); |
648 | 648 | |
649 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source ); |
|
649 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source); |
|
650 | 650 | |
651 | 651 | // Check if we don't allow prepaid credit cards. |
652 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
653 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
654 | - $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' ); |
|
655 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
652 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
653 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
654 | + $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'); |
|
655 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
656 | 656 | } |
657 | 657 | } |
658 | 658 | |
659 | - if ( empty( $prepared_source->source ) ) { |
|
660 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
661 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
659 | + if (empty($prepared_source->source)) { |
|
660 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
661 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | // Store source to order meta. |
665 | - $this->save_source( $order, $prepared_source ); |
|
665 | + $this->save_source($order, $prepared_source); |
|
666 | 666 | |
667 | 667 | // Result from Stripe API request. |
668 | 668 | $response = null; |
669 | 669 | |
670 | - if ( $order->get_total() > 0 ) { |
|
670 | + if ($order->get_total() > 0) { |
|
671 | 671 | // This will throw exception if not valid. |
672 | - $this->validate_minimum_order_amount( $order ); |
|
672 | + $this->validate_minimum_order_amount($order); |
|
673 | 673 | |
674 | 674 | /** |
675 | 675 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -678,83 +678,83 @@ discard block |
||
678 | 678 | * Note that if we need to save source, the original source must be first |
679 | 679 | * attached to a customer in Stripe before it can be charged. |
680 | 680 | */ |
681 | - if ( ( $source_object && ! empty( $source_object->card ) ) && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) { |
|
681 | + if (($source_object && ! empty($source_object->card)) && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) { |
|
682 | 682 | |
683 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
683 | + $response = $this->create_3ds_source($order, $source_object); |
|
684 | 684 | |
685 | - if ( ! empty( $response->error ) ) { |
|
685 | + if ( ! empty($response->error)) { |
|
686 | 686 | $localized_message = $response->error->message; |
687 | 687 | |
688 | - $order->add_order_note( $localized_message ); |
|
688 | + $order->add_order_note($localized_message); |
|
689 | 689 | |
690 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
690 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | // Update order meta with 3DS source. |
694 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
695 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
694 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
695 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
696 | 696 | } else { |
697 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
697 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
698 | 698 | $order->save(); |
699 | 699 | } |
700 | 700 | |
701 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
701 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
702 | 702 | |
703 | 703 | return array( |
704 | 704 | 'result' => 'success', |
705 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
705 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
706 | 706 | ); |
707 | 707 | } |
708 | 708 | |
709 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
709 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
710 | 710 | |
711 | 711 | // Make the request. |
712 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
712 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
713 | 713 | |
714 | - if ( ! empty( $response->error ) ) { |
|
714 | + if ( ! empty($response->error)) { |
|
715 | 715 | // If it is an API error such connection or server, let's retry. |
716 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
717 | - if ( $retry ) { |
|
718 | - sleep( 5 ); |
|
719 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
716 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
717 | + if ($retry) { |
|
718 | + sleep(5); |
|
719 | + return $this->process_payment($order_id, false, $force_save_source); |
|
720 | 720 | } else { |
721 | 721 | $localized_message = 'API connection error and retries exhausted.'; |
722 | - $order->add_order_note( $localized_message ); |
|
723 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
722 | + $order->add_order_note($localized_message); |
|
723 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
724 | 724 | } |
725 | 725 | } |
726 | 726 | |
727 | 727 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
728 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
729 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
728 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
729 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
730 | 730 | |
731 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
732 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
731 | + return $this->process_payment($order_id, false, $force_save_source); |
|
732 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
733 | 733 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
734 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
734 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
735 | 735 | $wc_token->delete(); |
736 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
737 | - $order->add_order_note( $localized_message ); |
|
738 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
736 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
737 | + $order->add_order_note($localized_message); |
|
738 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
742 | 742 | |
743 | - if ( 'card_error' === $response->error->type ) { |
|
744 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
743 | + if ('card_error' === $response->error->type) { |
|
744 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
745 | 745 | } else { |
746 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
746 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
747 | 747 | } |
748 | 748 | |
749 | - $order->add_order_note( $localized_message ); |
|
749 | + $order->add_order_note($localized_message); |
|
750 | 750 | |
751 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
751 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
752 | 752 | } |
753 | 753 | |
754 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
754 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
755 | 755 | |
756 | 756 | // Process valid response. |
757 | - $this->process_response( $response, $order ); |
|
757 | + $this->process_response($response, $order); |
|
758 | 758 | } else { |
759 | 759 | $order->payment_complete(); |
760 | 760 | } |
@@ -765,17 +765,17 @@ discard block |
||
765 | 765 | // Return thank you page redirect. |
766 | 766 | return array( |
767 | 767 | 'result' => 'success', |
768 | - 'redirect' => $this->get_return_url( $order ), |
|
768 | + 'redirect' => $this->get_return_url($order), |
|
769 | 769 | ); |
770 | 770 | |
771 | - } catch ( WC_Stripe_Exception $e ) { |
|
772 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
773 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
771 | + } catch (WC_Stripe_Exception $e) { |
|
772 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
773 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
774 | 774 | |
775 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
775 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
776 | 776 | |
777 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
778 | - $this->send_failed_order_email( $order_id ); |
|
777 | + if ($order->has_status(array('pending', 'failed'))) { |
|
778 | + $this->send_failed_order_email($order_id); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | 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,15 +17,15 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return float|int |
19 | 19 | */ |
20 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
21 | - if ( ! $currency ) { |
|
20 | + public static function get_stripe_amount($total, $currency = '') { |
|
21 | + if ( ! $currency) { |
|
22 | 22 | $currency = get_woocommerce_currency(); |
23 | 23 | } |
24 | 24 | |
25 | - if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
26 | - return absint( $total ); |
|
25 | + if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
26 | + return absint($total); |
|
27 | 27 | } else { |
28 | - return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
28 | + return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
@@ -37,25 +37,25 @@ discard block |
||
37 | 37 | * @return array |
38 | 38 | */ |
39 | 39 | public static function get_localized_messages() { |
40 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
41 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
42 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
43 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
44 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
45 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
46 | - 'incomplete_number' => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
47 | - 'incomplete_cvc' => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
48 | - 'incomplete_expiry' => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ), |
|
49 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
50 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
51 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
52 | - 'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
53 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
54 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
55 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
56 | - 'invalid_request_error' => __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ), |
|
57 | - 'invalid_sofort_country' => __( 'The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe' ), |
|
58 | - ) ); |
|
40 | + return apply_filters('wc_stripe_localized_messages', array( |
|
41 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
42 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
43 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
44 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
45 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
46 | + 'incomplete_number' => __('The card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
47 | + 'incomplete_cvc' => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
48 | + 'incomplete_expiry' => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'), |
|
49 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
50 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
51 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
52 | + 'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
53 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
54 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
55 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
56 | + 'invalid_request_error' => __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'), |
|
57 | + 'invalid_sofort_country' => __('The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe'), |
|
58 | + )); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -92,24 +92,24 @@ discard block |
||
92 | 92 | * @param string $type Type of number to format |
93 | 93 | * @return string |
94 | 94 | */ |
95 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
96 | - if ( ! is_object( $balance_transaction ) ) { |
|
95 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
96 | + if ( ! is_object($balance_transaction)) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
100 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
101 | - if ( 'fee' === $type ) { |
|
100 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
101 | + if ('fee' === $type) { |
|
102 | 102 | return $balance_transaction->fee; |
103 | 103 | } |
104 | 104 | |
105 | 105 | return $balance_transaction->net; |
106 | 106 | } |
107 | 107 | |
108 | - if ( 'fee' === $type ) { |
|
109 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
108 | + if ('fee' === $type) { |
|
109 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
110 | 110 | } |
111 | 111 | |
112 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
112 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public static function get_minimum_amount() { |
119 | 119 | // Check order amount |
120 | - switch ( get_woocommerce_currency() ) { |
|
120 | + switch (get_woocommerce_currency()) { |
|
121 | 121 | case 'USD': |
122 | 122 | case 'CAD': |
123 | 123 | case 'EUR': |
@@ -162,14 +162,14 @@ discard block |
||
162 | 162 | * @param string $method The payment method to get the settings from. |
163 | 163 | * @param string $setting The name of the setting to get. |
164 | 164 | */ |
165 | - public static function get_settings( $method = null, $setting = null ) { |
|
166 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
165 | + public static function get_settings($method = null, $setting = null) { |
|
166 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
167 | 167 | |
168 | - if ( null === $setting ) { |
|
168 | + if (null === $setting) { |
|
169 | 169 | return $all_settings; |
170 | 170 | } |
171 | 171 | |
172 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
172 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @return bool |
181 | 181 | */ |
182 | 182 | public static function is_pre_30() { |
183 | - return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
183 | + return version_compare(WC_VERSION, '3.0.0', '<'); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @return string |
194 | 194 | */ |
195 | 195 | public static function get_webhook_url() { |
196 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
196 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | * @version 4.0.0 |
204 | 204 | * @param string $source_id |
205 | 205 | */ |
206 | - public static function get_order_by_source_id( $source_id ) { |
|
206 | + public static function get_order_by_source_id($source_id) { |
|
207 | 207 | global $wpdb; |
208 | 208 | |
209 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) ); |
|
209 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id)); |
|
210 | 210 | |
211 | - if ( ! empty( $order_id ) ) { |
|
212 | - return wc_get_order( $order_id ); |
|
211 | + if ( ! empty($order_id)) { |
|
212 | + return wc_get_order($order_id); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return false; |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | * @version 4.0.0 |
223 | 223 | * @param string $charge_id |
224 | 224 | */ |
225 | - public static function get_order_by_charge_id( $charge_id ) { |
|
225 | + public static function get_order_by_charge_id($charge_id) { |
|
226 | 226 | global $wpdb; |
227 | 227 | |
228 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id ) ); |
|
228 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id)); |
|
229 | 229 | |
230 | - if ( ! empty( $order_id ) ) { |
|
231 | - return wc_get_order( $order_id ); |
|
230 | + if ( ! empty($order_id)) { |
|
231 | + return wc_get_order($order_id); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | return false; |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | * @param string $statement_descriptor |
245 | 245 | * @return string $statement_descriptor Sanitized statement descriptor |
246 | 246 | */ |
247 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
248 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
247 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
248 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
249 | 249 | |
250 | 250 | // Remove special characters. |
251 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
251 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
252 | 252 | |
253 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
253 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
254 | 254 | |
255 | 255 | return $statement_descriptor; |
256 | 256 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 3.1.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -56,35 +56,35 @@ discard block |
||
56 | 56 | * @version 4.0.0 |
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
60 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
61 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
62 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
63 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
64 | - |
|
65 | - if ( $this->testmode ) { |
|
66 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
59 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
60 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
61 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
62 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
63 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
64 | + |
|
65 | + if ($this->testmode) { |
|
66 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | // If both site title and statement descriptor is not set. Fallback. |
70 | - if ( empty( $this->total_label ) ) { |
|
70 | + if (empty($this->total_label)) { |
|
71 | 71 | $this->total_label = $_SERVER['SERVER_NAME']; |
72 | 72 | } |
73 | 73 | |
74 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
74 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
75 | 75 | |
76 | 76 | // Checks if Stripe Gateway is enabled. |
77 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
77 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Checks if Payment Request is enabled. |
82 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
82 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Don't load for change payment method page. |
87 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
87 | + if (isset($_GET['change_payment_method'])) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
@@ -98,41 +98,41 @@ discard block |
||
98 | 98 | * @version 4.0.0 |
99 | 99 | */ |
100 | 100 | protected function init() { |
101 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
102 | - add_action( 'wp', array( $this, 'set_session' ) ); |
|
101 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
102 | + add_action('wp', array($this, 'set_session')); |
|
103 | 103 | |
104 | 104 | /* |
105 | 105 | * In order to display the Payment Request button in the correct position, |
106 | 106 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
107 | 107 | * CSS is used to position the button. |
108 | 108 | */ |
109 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
110 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
111 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
109 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
110 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
111 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
112 | 112 | } else { |
113 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
114 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
113 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
114 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
115 | 115 | } |
116 | 116 | |
117 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
118 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
117 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
118 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
119 | 119 | |
120 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
121 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
120 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
121 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
122 | 122 | |
123 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
124 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
125 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
126 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
127 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
128 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
129 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
130 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
123 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
124 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
125 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
126 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
127 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
128 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
129 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
130 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
131 | 131 | |
132 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
133 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
132 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
133 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
134 | 134 | |
135 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 ); |
|
135 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @since 4.0.0 |
143 | 143 | */ |
144 | 144 | public function set_session() { |
145 | - if ( ! is_user_logged_in() ) { |
|
145 | + if ( ! is_user_logged_in()) { |
|
146 | 146 | $wc_session = new WC_Session_Handler(); |
147 | 147 | |
148 | - if ( ! $wc_session->has_session() ) { |
|
149 | - $wc_session->set_customer_session_cookie( true ); |
|
148 | + if ( ! $wc_session->has_session()) { |
|
149 | + $wc_session->set_customer_session_cookie(true); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @return string |
160 | 160 | */ |
161 | 161 | public function get_button_type() { |
162 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
162 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @return string |
171 | 171 | */ |
172 | 172 | public function get_button_theme() { |
173 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
173 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @return string |
182 | 182 | */ |
183 | 183 | public function get_button_height() { |
184 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
184 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -191,40 +191,40 @@ discard block |
||
191 | 191 | * @version 4.0.0 |
192 | 192 | */ |
193 | 193 | public function get_product_data() { |
194 | - if ( ! is_product() ) { |
|
194 | + if ( ! is_product()) { |
|
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | |
198 | 198 | global $post; |
199 | 199 | |
200 | - $product = wc_get_product( $post->ID ); |
|
200 | + $product = wc_get_product($post->ID); |
|
201 | 201 | |
202 | 202 | $data = array(); |
203 | 203 | $items = array(); |
204 | 204 | |
205 | 205 | $items[] = array( |
206 | 206 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
207 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
207 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
208 | 208 | ); |
209 | 209 | |
210 | - if ( wc_tax_enabled() ) { |
|
210 | + if (wc_tax_enabled()) { |
|
211 | 211 | $items[] = array( |
212 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
212 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
213 | 213 | 'amount' => 0, |
214 | 214 | 'pending' => true, |
215 | 215 | ); |
216 | 216 | } |
217 | 217 | |
218 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
218 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
219 | 219 | $items[] = array( |
220 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
220 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
221 | 221 | 'amount' => 0, |
222 | 222 | 'pending' => true, |
223 | 223 | ); |
224 | 224 | |
225 | - $data['shippingOptions'] = array( |
|
225 | + $data['shippingOptions'] = array( |
|
226 | 226 | 'id' => 'pending', |
227 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
227 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
228 | 228 | 'detail' => '', |
229 | 229 | 'amount' => 0, |
230 | 230 | ); |
@@ -233,40 +233,40 @@ discard block |
||
233 | 233 | $data['displayItems'] = $items; |
234 | 234 | $data['total'] = array( |
235 | 235 | 'label' => $this->total_label, |
236 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
236 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
237 | 237 | 'pending' => true, |
238 | 238 | ); |
239 | 239 | |
240 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
241 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
242 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
240 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
241 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
242 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
243 | 243 | |
244 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
244 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
248 | 248 | * Filters the gateway title to reflect Payment Request type |
249 | 249 | * |
250 | 250 | */ |
251 | - public function filter_gateway_title( $title, $id ) { |
|
251 | + public function filter_gateway_title($title, $id) { |
|
252 | 252 | global $post; |
253 | 253 | |
254 | - if ( ! is_object( $post ) ) { |
|
254 | + if ( ! is_object($post)) { |
|
255 | 255 | return $title; |
256 | 256 | } |
257 | 257 | |
258 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
259 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
258 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
259 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
260 | 260 | } else { |
261 | - $order = wc_get_order( $post->ID ); |
|
262 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
261 | + $order = wc_get_order($post->ID); |
|
262 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
263 | 263 | } |
264 | 264 | |
265 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
265 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
266 | 266 | return $method_title; |
267 | 267 | } |
268 | 268 | |
269 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
269 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
270 | 270 | return $method_title; |
271 | 271 | } |
272 | 272 | |
@@ -279,16 +279,16 @@ discard block |
||
279 | 279 | * @since 3.1.4 |
280 | 280 | * @version 4.0.0 |
281 | 281 | */ |
282 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
282 | + public function postal_code_validation($valid, $postcode, $country) { |
|
283 | 283 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
284 | 284 | |
285 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
285 | + if ( ! isset($gateways['stripe'])) { |
|
286 | 286 | return $valid; |
287 | 287 | } |
288 | 288 | |
289 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
289 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
290 | 290 | |
291 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
291 | + if ('apple_pay' !== $payment_request_type) { |
|
292 | 292 | return $valid; |
293 | 293 | } |
294 | 294 | |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * the order and not let it go through. The remedy for now is just to remove this validation. |
299 | 299 | * Note that this only works with shipping providers that don't validate full postal codes. |
300 | 300 | */ |
301 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
301 | + if ('GB' === $country || 'CA' === $country) { |
|
302 | 302 | return true; |
303 | 303 | } |
304 | 304 | |
@@ -314,27 +314,27 @@ discard block |
||
314 | 314 | * @param array $posted_data The posted data from checkout form. |
315 | 315 | * @param object $order |
316 | 316 | */ |
317 | - public function add_order_meta( $order_id, $posted_data, $order ) { |
|
318 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
317 | + public function add_order_meta($order_id, $posted_data, $order) { |
|
318 | + if (empty($_POST['payment_request_type'])) { |
|
319 | 319 | return; |
320 | 320 | } |
321 | 321 | |
322 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
322 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
323 | 323 | |
324 | - if ( 'apple_pay' === $payment_request_type ) { |
|
325 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
326 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
324 | + if ('apple_pay' === $payment_request_type) { |
|
325 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
326 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
327 | 327 | } else { |
328 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
328 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
329 | 329 | $order->save(); |
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
333 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
334 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
335 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
333 | + if ('payment_request_api' === $payment_request_type) { |
|
334 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
335 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
336 | 336 | } else { |
337 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
337 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
338 | 338 | $order->save(); |
339 | 339 | } |
340 | 340 | } |
@@ -348,11 +348,11 @@ discard block |
||
348 | 348 | * @return array |
349 | 349 | */ |
350 | 350 | public function supported_product_types() { |
351 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
351 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
352 | 352 | 'simple', |
353 | 353 | 'variable', |
354 | 354 | 'variation', |
355 | - ) ); |
|
355 | + )); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -363,15 +363,15 @@ discard block |
||
363 | 363 | * @return bool |
364 | 364 | */ |
365 | 365 | public function allowed_items_in_cart() { |
366 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
367 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
366 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
367 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
368 | 368 | |
369 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
369 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
370 | 370 | return false; |
371 | 371 | } |
372 | 372 | |
373 | 373 | // Pre Orders compatbility where we don't support charge upon release. |
374 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
374 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | } |
@@ -386,71 +386,71 @@ discard block |
||
386 | 386 | * @version 4.0.0 |
387 | 387 | */ |
388 | 388 | public function scripts() { |
389 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
389 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
390 | 390 | return; |
391 | 391 | } |
392 | 392 | |
393 | - if ( is_product() ) { |
|
393 | + if (is_product()) { |
|
394 | 394 | global $post; |
395 | 395 | |
396 | - $product = wc_get_product( $post->ID ); |
|
396 | + $product = wc_get_product($post->ID); |
|
397 | 397 | |
398 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
398 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
399 | 399 | return; |
400 | 400 | } |
401 | 401 | |
402 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
402 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
403 | 403 | return; |
404 | 404 | } |
405 | 405 | } |
406 | 406 | |
407 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
407 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
408 | 408 | |
409 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
410 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
409 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
410 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
411 | 411 | |
412 | 412 | wp_localize_script( |
413 | 413 | 'wc_stripe_payment_request', |
414 | 414 | 'wc_stripe_payment_request_params', |
415 | 415 | array( |
416 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
416 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
417 | 417 | 'stripe' => array( |
418 | 418 | 'key' => $this->publishable_key, |
419 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
419 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
420 | 420 | ), |
421 | 421 | 'nonce' => array( |
422 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
423 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
424 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
425 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
426 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
427 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
428 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
429 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
422 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
423 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
424 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
425 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
426 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
427 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
428 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
429 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
430 | 430 | ), |
431 | 431 | 'i18n' => array( |
432 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
432 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
433 | 433 | /* translators: Do not translate the [option] placeholder */ |
434 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
434 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
435 | 435 | ), |
436 | 436 | 'checkout' => array( |
437 | 437 | 'url' => wc_get_checkout_url(), |
438 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
439 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
438 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
439 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
440 | 440 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
441 | 441 | ), |
442 | 442 | 'button' => array( |
443 | 443 | 'type' => $this->get_button_type(), |
444 | 444 | 'theme' => $this->get_button_theme(), |
445 | 445 | 'height' => $this->get_button_height(), |
446 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
446 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
447 | 447 | ), |
448 | 448 | 'is_product_page' => is_product(), |
449 | 449 | 'product' => $this->get_product_data(), |
450 | 450 | ) |
451 | 451 | ); |
452 | 452 | |
453 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
453 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -462,39 +462,39 @@ discard block |
||
462 | 462 | public function display_payment_request_button_html() { |
463 | 463 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
464 | 464 | |
465 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
465 | + if ( ! isset($gateways['stripe'])) { |
|
466 | 466 | return; |
467 | 467 | } |
468 | 468 | |
469 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
469 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
470 | 470 | return; |
471 | 471 | } |
472 | 472 | |
473 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
473 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
474 | 474 | return; |
475 | 475 | } |
476 | 476 | |
477 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
477 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
478 | 478 | return; |
479 | 479 | } |
480 | 480 | |
481 | - if ( is_product() ) { |
|
481 | + if (is_product()) { |
|
482 | 482 | global $post; |
483 | 483 | |
484 | - $product = wc_get_product( $post->ID ); |
|
484 | + $product = wc_get_product($post->ID); |
|
485 | 485 | |
486 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
486 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
487 | 487 | return; |
488 | 488 | } |
489 | 489 | |
490 | 490 | // Pre Orders charge upon release not supported. |
491 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
492 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
491 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
492 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
493 | 493 | return; |
494 | 494 | } |
495 | 495 | } else { |
496 | - if ( ! $this->allowed_items_in_cart() ) { |
|
497 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
496 | + if ( ! $this->allowed_items_in_cart()) { |
|
497 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
498 | 498 | return; |
499 | 499 | } |
500 | 500 | } |
@@ -516,44 +516,44 @@ discard block |
||
516 | 516 | public function display_payment_request_button_separator_html() { |
517 | 517 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
518 | 518 | |
519 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
519 | + if ( ! isset($gateways['stripe'])) { |
|
520 | 520 | return; |
521 | 521 | } |
522 | 522 | |
523 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
523 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
524 | 524 | return; |
525 | 525 | } |
526 | 526 | |
527 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
527 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
528 | 528 | return; |
529 | 529 | } |
530 | 530 | |
531 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
531 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
532 | 532 | return; |
533 | 533 | } |
534 | 534 | |
535 | - if ( is_product() ) { |
|
535 | + if (is_product()) { |
|
536 | 536 | global $post; |
537 | 537 | |
538 | - $product = wc_get_product( $post->ID ); |
|
538 | + $product = wc_get_product($post->ID); |
|
539 | 539 | |
540 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
540 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
541 | 541 | return; |
542 | 542 | } |
543 | 543 | |
544 | 544 | // Pre Orders charge upon release not supported. |
545 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
546 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
545 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
546 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
547 | 547 | return; |
548 | 548 | } |
549 | 549 | } else { |
550 | - if ( ! $this->allowed_items_in_cart() ) { |
|
551 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
550 | + if ( ! $this->allowed_items_in_cart()) { |
|
551 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
552 | 552 | return; |
553 | 553 | } |
554 | 554 | } |
555 | 555 | ?> |
556 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
556 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p> |
|
557 | 557 | <?php |
558 | 558 | } |
559 | 559 | |
@@ -564,11 +564,11 @@ discard block |
||
564 | 564 | * @version 4.0.0 |
565 | 565 | */ |
566 | 566 | public function ajax_log_errors() { |
567 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
567 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
568 | 568 | |
569 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
569 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
570 | 570 | |
571 | - WC_Stripe_Logger::log( $errors ); |
|
571 | + WC_Stripe_Logger::log($errors); |
|
572 | 572 | |
573 | 573 | exit; |
574 | 574 | } |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @version 4.0.0 |
581 | 581 | */ |
582 | 582 | public function ajax_clear_cart() { |
583 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
583 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
584 | 584 | |
585 | 585 | WC()->cart->empty_cart(); |
586 | 586 | exit; |
@@ -590,10 +590,10 @@ discard block |
||
590 | 590 | * Get cart details. |
591 | 591 | */ |
592 | 592 | public function ajax_get_cart_details() { |
593 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
593 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
594 | 594 | |
595 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
596 | - define( 'WOOCOMMERCE_CART', true ); |
|
595 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
596 | + define('WOOCOMMERCE_CART', true); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | WC()->cart->calculate_totals(); |
@@ -604,14 +604,14 @@ discard block |
||
604 | 604 | $data = array( |
605 | 605 | 'shipping_required' => WC()->cart->needs_shipping(), |
606 | 606 | 'order_data' => array( |
607 | - 'currency' => strtolower( $currency ), |
|
608 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
607 | + 'currency' => strtolower($currency), |
|
608 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
609 | 609 | ), |
610 | 610 | ); |
611 | 611 | |
612 | 612 | $data['order_data'] += $this->build_display_items(); |
613 | 613 | |
614 | - wp_send_json( $data ); |
|
614 | + wp_send_json($data); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -622,47 +622,47 @@ discard block |
||
622 | 622 | * @see WC_Shipping::get_packages(). |
623 | 623 | */ |
624 | 624 | public function ajax_get_shipping_options() { |
625 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
625 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
626 | 626 | |
627 | 627 | try { |
628 | 628 | // Set the shipping package. |
629 | - $posted = filter_input_array( INPUT_POST, array( |
|
629 | + $posted = filter_input_array(INPUT_POST, array( |
|
630 | 630 | 'country' => FILTER_SANITIZE_STRING, |
631 | 631 | 'state' => FILTER_SANITIZE_STRING, |
632 | 632 | 'postcode' => FILTER_SANITIZE_STRING, |
633 | 633 | 'city' => FILTER_SANITIZE_STRING, |
634 | 634 | 'address' => FILTER_SANITIZE_STRING, |
635 | 635 | 'address_2' => FILTER_SANITIZE_STRING, |
636 | - ) ); |
|
636 | + )); |
|
637 | 637 | |
638 | - $this->calculate_shipping( $posted ); |
|
638 | + $this->calculate_shipping($posted); |
|
639 | 639 | |
640 | 640 | // Set the shipping options. |
641 | 641 | $data = array(); |
642 | 642 | $packages = WC()->shipping->get_packages(); |
643 | 643 | |
644 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
645 | - foreach ( $packages as $package_key => $package ) { |
|
646 | - if ( empty( $package['rates'] ) ) { |
|
647 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
644 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
645 | + foreach ($packages as $package_key => $package) { |
|
646 | + if (empty($package['rates'])) { |
|
647 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
648 | 648 | } |
649 | 649 | |
650 | - foreach ( $package['rates'] as $key => $rate ) { |
|
650 | + foreach ($package['rates'] as $key => $rate) { |
|
651 | 651 | $data['shipping_options'][] = array( |
652 | 652 | 'id' => $rate->id, |
653 | 653 | 'label' => $rate->label, |
654 | 654 | 'detail' => '', |
655 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
655 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
656 | 656 | ); |
657 | 657 | } |
658 | 658 | } |
659 | 659 | } else { |
660 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
660 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
661 | 661 | } |
662 | 662 | |
663 | - if ( isset( $data[0] ) ) { |
|
663 | + if (isset($data[0])) { |
|
664 | 664 | // Auto select the first shipping method. |
665 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
665 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | WC()->cart->calculate_totals(); |
@@ -670,12 +670,12 @@ discard block |
||
670 | 670 | $data += $this->build_display_items(); |
671 | 671 | $data['result'] = 'success'; |
672 | 672 | |
673 | - wp_send_json( $data ); |
|
674 | - } catch ( Exception $e ) { |
|
673 | + wp_send_json($data); |
|
674 | + } catch (Exception $e) { |
|
675 | 675 | $data += $this->build_display_items(); |
676 | 676 | $data['result'] = 'invalid_shipping_address'; |
677 | 677 | |
678 | - wp_send_json( $data ); |
|
678 | + wp_send_json($data); |
|
679 | 679 | } |
680 | 680 | } |
681 | 681 | |
@@ -683,22 +683,22 @@ discard block |
||
683 | 683 | * Update shipping method. |
684 | 684 | */ |
685 | 685 | public function ajax_update_shipping_method() { |
686 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
686 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
687 | 687 | |
688 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
689 | - define( 'WOOCOMMERCE_CART', true ); |
|
688 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
689 | + define('WOOCOMMERCE_CART', true); |
|
690 | 690 | } |
691 | 691 | |
692 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
693 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
692 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
693 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
694 | 694 | |
695 | - if ( is_array( $shipping_method ) ) { |
|
696 | - foreach ( $shipping_method as $i => $value ) { |
|
697 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
695 | + if (is_array($shipping_method)) { |
|
696 | + foreach ($shipping_method as $i => $value) { |
|
697 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
698 | 698 | } |
699 | 699 | } |
700 | 700 | |
701 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
701 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
702 | 702 | |
703 | 703 | WC()->cart->calculate_totals(); |
704 | 704 | |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | $data += $this->build_display_items(); |
707 | 707 | $data['result'] = 'success'; |
708 | 708 | |
709 | - wp_send_json( $data ); |
|
709 | + wp_send_json($data); |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | /** |
@@ -717,31 +717,31 @@ discard block |
||
717 | 717 | * @return array $data |
718 | 718 | */ |
719 | 719 | public function ajax_get_selected_product_data() { |
720 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
720 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
721 | 721 | |
722 | - $product_id = absint( $_POST['product_id'] ); |
|
723 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
722 | + $product_id = absint($_POST['product_id']); |
|
723 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
724 | 724 | |
725 | - $product = wc_get_product( $product_id ); |
|
725 | + $product = wc_get_product($product_id); |
|
726 | 726 | |
727 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
728 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
727 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
728 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
729 | 729 | |
730 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
731 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
730 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
731 | + $variation_id = $product->get_matching_variation($attributes); |
|
732 | 732 | } else { |
733 | - $data_store = WC_Data_Store::load( 'product' ); |
|
734 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
733 | + $data_store = WC_Data_Store::load('product'); |
|
734 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
735 | 735 | } |
736 | 736 | |
737 | - if ( ! empty( $variation_id ) ) { |
|
738 | - $product = wc_get_product( $variation_id ); |
|
737 | + if ( ! empty($variation_id)) { |
|
738 | + $product = wc_get_product($variation_id); |
|
739 | 739 | } |
740 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
741 | - $product = wc_get_product( $product_id ); |
|
740 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
741 | + $product = wc_get_product($product_id); |
|
742 | 742 | } |
743 | 743 | |
744 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
744 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
745 | 745 | |
746 | 746 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
747 | 747 | |
@@ -749,28 +749,28 @@ discard block |
||
749 | 749 | $items = array(); |
750 | 750 | |
751 | 751 | $items[] = array( |
752 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
753 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
752 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
753 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
754 | 754 | ); |
755 | 755 | |
756 | - if ( wc_tax_enabled() ) { |
|
756 | + if (wc_tax_enabled()) { |
|
757 | 757 | $items[] = array( |
758 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
758 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
759 | 759 | 'amount' => 0, |
760 | 760 | 'pending' => true, |
761 | 761 | ); |
762 | 762 | } |
763 | 763 | |
764 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
764 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
765 | 765 | $items[] = array( |
766 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
766 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
767 | 767 | 'amount' => 0, |
768 | 768 | 'pending' => true, |
769 | 769 | ); |
770 | 770 | |
771 | - $data['shippingOptions'] = array( |
|
771 | + $data['shippingOptions'] = array( |
|
772 | 772 | 'id' => 'pending', |
773 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
773 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
774 | 774 | 'detail' => '', |
775 | 775 | 'amount' => 0, |
776 | 776 | ); |
@@ -779,15 +779,15 @@ discard block |
||
779 | 779 | $data['displayItems'] = $items; |
780 | 780 | $data['total'] = array( |
781 | 781 | 'label' => $this->total_label, |
782 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
782 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
783 | 783 | 'pending' => true, |
784 | 784 | ); |
785 | 785 | |
786 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
787 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
788 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
786 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
787 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
788 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
789 | 789 | |
790 | - wp_send_json( $data ); |
|
790 | + wp_send_json($data); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | /** |
@@ -798,37 +798,37 @@ discard block |
||
798 | 798 | * @return array $data |
799 | 799 | */ |
800 | 800 | public function ajax_add_to_cart() { |
801 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
801 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
802 | 802 | |
803 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
804 | - define( 'WOOCOMMERCE_CART', true ); |
|
803 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
804 | + define('WOOCOMMERCE_CART', true); |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | WC()->shipping->reset_shipping(); |
808 | 808 | |
809 | - $product_id = absint( $_POST['product_id'] ); |
|
810 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
809 | + $product_id = absint($_POST['product_id']); |
|
810 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
811 | 811 | |
812 | - $product = wc_get_product( $product_id ); |
|
812 | + $product = wc_get_product($product_id); |
|
813 | 813 | |
814 | 814 | // First empty the cart to prevent wrong calculation. |
815 | 815 | WC()->cart->empty_cart(); |
816 | 816 | |
817 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
818 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
817 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
818 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
819 | 819 | |
820 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
821 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
820 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
821 | + $variation_id = $product->get_matching_variation($attributes); |
|
822 | 822 | } else { |
823 | - $data_store = WC_Data_Store::load( 'product' ); |
|
824 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
823 | + $data_store = WC_Data_Store::load('product'); |
|
824 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
825 | 825 | } |
826 | 826 | |
827 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
827 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
828 | 828 | } |
829 | 829 | |
830 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
831 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
830 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
831 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | WC()->cart->calculate_totals(); |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | $data += $this->build_display_items(); |
838 | 838 | $data['result'] = 'success'; |
839 | 839 | |
840 | - wp_send_json( $data ); |
|
840 | + wp_send_json($data); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
@@ -850,31 +850,31 @@ discard block |
||
850 | 850 | * @version 4.0.0 |
851 | 851 | */ |
852 | 852 | public function normalize_state() { |
853 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
854 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
855 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
856 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
853 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
854 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
855 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
856 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
857 | 857 | |
858 | - if ( $billing_state && $billing_country ) { |
|
859 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
858 | + if ($billing_state && $billing_country) { |
|
859 | + $valid_states = WC()->countries->get_states($billing_country); |
|
860 | 860 | |
861 | 861 | // Valid states found for country. |
862 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
863 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
864 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
862 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
863 | + foreach ($valid_states as $state_abbr => $state) { |
|
864 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
865 | 865 | $_POST['billing_state'] = $state_abbr; |
866 | 866 | } |
867 | 867 | } |
868 | 868 | } |
869 | 869 | } |
870 | 870 | |
871 | - if ( $shipping_state && $shipping_country ) { |
|
872 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
871 | + if ($shipping_state && $shipping_country) { |
|
872 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
873 | 873 | |
874 | 874 | // Valid states found for country. |
875 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
876 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
877 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
875 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
876 | + foreach ($valid_states as $state_abbr => $state) { |
|
877 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
878 | 878 | $_POST['shipping_state'] = $state_abbr; |
879 | 879 | } |
880 | 880 | } |
@@ -889,19 +889,19 @@ discard block |
||
889 | 889 | * @version 4.0.0 |
890 | 890 | */ |
891 | 891 | public function ajax_create_order() { |
892 | - if ( WC()->cart->is_empty() ) { |
|
893 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
892 | + if (WC()->cart->is_empty()) { |
|
893 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
894 | 894 | } |
895 | 895 | |
896 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
897 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
896 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
897 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | $this->normalize_state(); |
901 | 901 | |
902 | 902 | WC()->checkout()->process_checkout(); |
903 | 903 | |
904 | - die( 0 ); |
|
904 | + die(0); |
|
905 | 905 | } |
906 | 906 | |
907 | 907 | /** |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | * @version 4.0.0 |
912 | 912 | * @param array $address |
913 | 913 | */ |
914 | - protected function calculate_shipping( $address = array() ) { |
|
914 | + protected function calculate_shipping($address = array()) { |
|
915 | 915 | global $states; |
916 | 916 | |
917 | 917 | $country = $address['country']; |
@@ -928,28 +928,28 @@ discard block |
||
928 | 928 | * In some versions of Chrome, state can be a full name. So we need |
929 | 929 | * to convert that to abbreviation as WC is expecting that. |
930 | 930 | */ |
931 | - if ( 2 < strlen( $state ) ) { |
|
932 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
931 | + if (2 < strlen($state)) { |
|
932 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
933 | 933 | } |
934 | 934 | |
935 | 935 | WC()->shipping->reset_shipping(); |
936 | 936 | |
937 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
938 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
937 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
938 | + $postcode = wc_format_postcode($postcode, $country); |
|
939 | 939 | } |
940 | 940 | |
941 | - if ( $country ) { |
|
942 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
943 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
941 | + if ($country) { |
|
942 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
943 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
944 | 944 | } else { |
945 | 945 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
946 | 946 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
947 | 947 | } |
948 | 948 | |
949 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
950 | - WC()->customer->calculated_shipping( true ); |
|
949 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
950 | + WC()->customer->calculated_shipping(true); |
|
951 | 951 | } else { |
952 | - WC()->customer->set_calculated_shipping( true ); |
|
952 | + WC()->customer->set_calculated_shipping(true); |
|
953 | 953 | WC()->customer->save(); |
954 | 954 | } |
955 | 955 | |
@@ -966,17 +966,17 @@ discard block |
||
966 | 966 | $packages[0]['destination']['address'] = $address_1; |
967 | 967 | $packages[0]['destination']['address_2'] = $address_2; |
968 | 968 | |
969 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
970 | - if ( $item['data']->needs_shipping() ) { |
|
971 | - if ( isset( $item['line_total'] ) ) { |
|
969 | + foreach (WC()->cart->get_cart() as $item) { |
|
970 | + if ($item['data']->needs_shipping()) { |
|
971 | + if (isset($item['line_total'])) { |
|
972 | 972 | $packages[0]['contents_cost'] += $item['line_total']; |
973 | 973 | } |
974 | 974 | } |
975 | 975 | } |
976 | 976 | |
977 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
977 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
978 | 978 | |
979 | - WC()->shipping->calculate_shipping( $packages ); |
|
979 | + WC()->shipping->calculate_shipping($packages); |
|
980 | 980 | } |
981 | 981 | |
982 | 982 | /** |
@@ -985,19 +985,19 @@ discard block |
||
985 | 985 | * @since 3.1.0 |
986 | 986 | * @version 4.0.0 |
987 | 987 | */ |
988 | - protected function build_shipping_methods( $shipping_methods ) { |
|
989 | - if ( empty( $shipping_methods ) ) { |
|
988 | + protected function build_shipping_methods($shipping_methods) { |
|
989 | + if (empty($shipping_methods)) { |
|
990 | 990 | return array(); |
991 | 991 | } |
992 | 992 | |
993 | 993 | $shipping = array(); |
994 | 994 | |
995 | - foreach ( $shipping_methods as $method ) { |
|
995 | + foreach ($shipping_methods as $method) { |
|
996 | 996 | $shipping[] = array( |
997 | 997 | 'id' => $method['id'], |
998 | 998 | 'label' => $method['label'], |
999 | 999 | 'detail' => '', |
1000 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1000 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1001 | 1001 | ); |
1002 | 1002 | } |
1003 | 1003 | |
@@ -1011,69 +1011,69 @@ discard block |
||
1011 | 1011 | * @version 4.0.0 |
1012 | 1012 | */ |
1013 | 1013 | protected function build_display_items() { |
1014 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1015 | - define( 'WOOCOMMERCE_CART', true ); |
|
1014 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1015 | + define('WOOCOMMERCE_CART', true); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | $items = array(); |
1019 | 1019 | $subtotal = 0; |
1020 | 1020 | |
1021 | 1021 | // Default show only subtotal instead of itemization. |
1022 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1023 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1022 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1023 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1024 | 1024 | $amount = $cart_item['line_subtotal']; |
1025 | - $subtotal += $cart_item['line_subtotal']; |
|
1025 | + $subtotal += $cart_item['line_subtotal']; |
|
1026 | 1026 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1027 | 1027 | |
1028 | 1028 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1029 | 1029 | |
1030 | 1030 | $item = array( |
1031 | 1031 | 'label' => $product_name . $quantity_label, |
1032 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1032 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1033 | 1033 | ); |
1034 | 1034 | |
1035 | 1035 | $items[] = $item; |
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1040 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1041 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1042 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1043 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1039 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1040 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1041 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1042 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1043 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1044 | 1044 | |
1045 | - if ( wc_tax_enabled() ) { |
|
1045 | + if (wc_tax_enabled()) { |
|
1046 | 1046 | $items[] = array( |
1047 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1048 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1047 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1048 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1049 | 1049 | ); |
1050 | 1050 | } |
1051 | 1051 | |
1052 | - if ( WC()->cart->needs_shipping() ) { |
|
1052 | + if (WC()->cart->needs_shipping()) { |
|
1053 | 1053 | $items[] = array( |
1054 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1055 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1054 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1055 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1056 | 1056 | ); |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - if ( WC()->cart->has_discount() ) { |
|
1059 | + if (WC()->cart->has_discount()) { |
|
1060 | 1060 | $items[] = array( |
1061 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1062 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1061 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1062 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1063 | 1063 | ); |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1066 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1067 | 1067 | $cart_fees = WC()->cart->fees; |
1068 | 1068 | } else { |
1069 | 1069 | $cart_fees = WC()->cart->get_fees(); |
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | // Include fees and taxes as display items. |
1073 | - foreach ( $cart_fees as $key => $fee ) { |
|
1073 | + foreach ($cart_fees as $key => $fee) { |
|
1074 | 1074 | $items[] = array( |
1075 | 1075 | 'label' => $fee->name, |
1076 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1076 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1077 | 1077 | ); |
1078 | 1078 | } |
1079 | 1079 | |
@@ -1081,7 +1081,7 @@ discard block |
||
1081 | 1081 | 'displayItems' => $items, |
1082 | 1082 | 'total' => array( |
1083 | 1083 | 'label' => $this->total_label, |
1084 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1084 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1085 | 1085 | 'pending' => false, |
1086 | 1086 | ), |
1087 | 1087 | ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_bancontact'; |
60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['bancontact']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-bancontact-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,25 +241,25 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'bancontact'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
254 | - $post_data['bancontact'] = array( 'preferred_language' => substr( get_locale(), 0, 2 ) ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | + $post_data['bancontact'] = array('preferred_language' => substr(get_locale(), 0, 2)); |
|
255 | 255 | |
256 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
257 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
256 | + if ( ! empty($this->statement_descriptor)) { |
|
257 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
258 | 258 | } |
259 | 259 | |
260 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
260 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
261 | 261 | |
262 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
262 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -273,51 +273,51 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return array|void |
275 | 275 | */ |
276 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
276 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
277 | 277 | try { |
278 | - $order = wc_get_order( $order_id ); |
|
278 | + $order = wc_get_order($order_id); |
|
279 | 279 | |
280 | 280 | // This will throw exception if not valid. |
281 | - $this->validate_minimum_order_amount( $order ); |
|
281 | + $this->validate_minimum_order_amount($order); |
|
282 | 282 | |
283 | 283 | // This comes from the create account checkbox in the checkout page. |
284 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
284 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
285 | 285 | |
286 | - if ( $create_account ) { |
|
286 | + if ($create_account) { |
|
287 | 287 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
288 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
288 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
289 | 289 | $new_stripe_customer->create_customer(); |
290 | 290 | } |
291 | 291 | |
292 | - $response = $this->create_source( $order ); |
|
292 | + $response = $this->create_source($order); |
|
293 | 293 | |
294 | - if ( ! empty( $response->error ) ) { |
|
295 | - $order->add_order_note( $response->error->message ); |
|
294 | + if ( ! empty($response->error)) { |
|
295 | + $order->add_order_note($response->error->message); |
|
296 | 296 | |
297 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
297 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
298 | 298 | } |
299 | 299 | |
300 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
301 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
300 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
301 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
302 | 302 | } else { |
303 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
303 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
304 | 304 | $order->save(); |
305 | 305 | } |
306 | 306 | |
307 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
307 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
308 | 308 | |
309 | 309 | return array( |
310 | 310 | 'result' => 'success', |
311 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
311 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
312 | 312 | ); |
313 | - } catch ( WC_Stripe_Exception $e ) { |
|
314 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
315 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
313 | + } catch (WC_Stripe_Exception $e) { |
|
314 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
315 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
316 | 316 | |
317 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
317 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
318 | 318 | |
319 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
320 | - $this->send_failed_order_email( $order_id ); |
|
319 | + if ($order->has_status(array('pending', 'failed'))) { |
|
320 | + $this->send_failed_order_email($order_id); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | 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 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sofort'; |
60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_sofort_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_sofort_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['sofort']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-sofort-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,25 +241,25 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $bank_country = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'sofort'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
254 | - $post_data['sofort'] = array( 'country' => $bank_country, 'preferred_language' => substr( get_locale(), 0, 2 ) ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | + $post_data['sofort'] = array('country' => $bank_country, 'preferred_language' => substr(get_locale(), 0, 2)); |
|
255 | 255 | |
256 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
257 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
256 | + if ( ! empty($this->statement_descriptor)) { |
|
257 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
258 | 258 | } |
259 | 259 | |
260 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
260 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
261 | 261 | |
262 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
262 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -273,59 +273,59 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return array|void |
275 | 275 | */ |
276 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
276 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
277 | 277 | try { |
278 | - $order = wc_get_order( $order_id ); |
|
278 | + $order = wc_get_order($order_id); |
|
279 | 279 | |
280 | 280 | // This will throw exception if not valid. |
281 | - $this->validate_minimum_order_amount( $order ); |
|
281 | + $this->validate_minimum_order_amount($order); |
|
282 | 282 | |
283 | 283 | // This comes from the create account checkbox in the checkout page. |
284 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
284 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
285 | 285 | |
286 | - if ( $create_account ) { |
|
286 | + if ($create_account) { |
|
287 | 287 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
288 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
288 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
289 | 289 | $new_stripe_customer->create_customer(); |
290 | 290 | } |
291 | 291 | |
292 | - $response = $this->create_source( $order ); |
|
292 | + $response = $this->create_source($order); |
|
293 | 293 | |
294 | - if ( ! empty( $response->error ) ) { |
|
295 | - $order->add_order_note( $response->error->message ); |
|
294 | + if ( ! empty($response->error)) { |
|
295 | + $order->add_order_note($response->error->message); |
|
296 | 296 | |
297 | 297 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
298 | 298 | |
299 | - if ( 'invalid_sofort_country' === $response->error->code ) { |
|
300 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
299 | + if ('invalid_sofort_country' === $response->error->code) { |
|
300 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
301 | 301 | } else { |
302 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
302 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
303 | 303 | } |
304 | 304 | |
305 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
305 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
306 | 306 | } |
307 | 307 | |
308 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
309 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
308 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
309 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
310 | 310 | } else { |
311 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
311 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
312 | 312 | $order->save(); |
313 | 313 | } |
314 | 314 | |
315 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
315 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
316 | 316 | |
317 | 317 | return array( |
318 | 318 | 'result' => 'success', |
319 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
319 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
320 | 320 | ); |
321 | - } catch ( WC_Stripe_Exception $e ) { |
|
322 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
323 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
321 | + } catch (WC_Stripe_Exception $e) { |
|
322 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
323 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
324 | 324 | |
325 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
325 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
326 | 326 | |
327 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
328 | - $this->send_failed_order_email( $order_id ); |
|
327 | + if ($order->has_status(array('pending', 'failed'))) { |
|
328 | + $this->send_failed_order_email($order_id); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | return array( |
@@ -134,7 +134,6 @@ discard block |
||
134 | 134 | * process_subscription_payment function. |
135 | 135 | * @param mixed $order |
136 | 136 | * @param int $amount (default: 0) |
137 | - * @param string $stripe_token (default: '') |
|
138 | 137 | * @param bool initial_payment |
139 | 138 | */ |
140 | 139 | public function process_subscription_payment( $order = '', $amount = 0 ) { |
@@ -179,7 +178,6 @@ discard block |
||
179 | 178 | * @todo refactor to avoid DRY. |
180 | 179 | * @param mixed $order |
181 | 180 | * @param int $amount (default: 0) |
182 | - * @param string $stripe_token (default: '') |
|
183 | 181 | * @param bool initial_payment |
184 | 182 | */ |
185 | 183 | public function retry_subscription_payment( $order = '', $amount = 0 ) { |
@@ -232,7 +230,7 @@ discard block |
||
232 | 230 | |
233 | 231 | /** |
234 | 232 | * Don't transfer Stripe fee/ID meta to renewal orders. |
235 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
233 | + * @param integer $renewal_order |
|
236 | 234 | */ |
237 | 235 | public function delete_renewal_meta( $renewal_order ) { |
238 | 236 | delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -474,6 +472,8 @@ discard block |
||
474 | 472 | /** |
475 | 473 | * Process the pre-order |
476 | 474 | * @param int $order_id |
475 | + * @param boolean $retry |
|
476 | + * @param boolean $force_save_source |
|
477 | 477 | * @return array |
478 | 478 | */ |
479 | 479 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | 23 | |
24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
26 | 26 | |
27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
32 | 32 | } |
33 | 33 | |
34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @since 4.0.0 |
44 | 44 | * @version 4.0.0 |
45 | 45 | */ |
46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param int $order_id |
57 | 57 | * @return boolean |
58 | 58 | */ |
59 | - public function has_subscription( $order_id ) { |
|
60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
59 | + public function has_subscription($order_id) { |
|
60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @param int $order_id |
66 | 66 | * @return boolean |
67 | 67 | */ |
68 | - protected function is_pre_order( $order_id ) { |
|
69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
68 | + protected function is_pre_order($order_id) { |
|
69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * @param int $order_id |
75 | 75 | * @return array |
76 | 76 | */ |
77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
78 | - if ( $this->has_subscription( $order_id ) ) { |
|
77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
78 | + if ($this->has_subscription($order_id)) { |
|
79 | 79 | // Regular payment with force customer enabled |
80 | - return parent::process_payment( $order_id, true, true ); |
|
81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
80 | + return parent::process_payment($order_id, true, true); |
|
81 | + } elseif ($this->is_pre_order($order_id)) { |
|
82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
83 | 83 | } else { |
84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | * @param array $metadata |
93 | 93 | * @param object $order |
94 | 94 | */ |
95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
96 | - if ( ! $this->has_subscription( $order->get_id() ) ) { |
|
95 | + public function add_subscription_meta_data($metadata, $order) { |
|
96 | + if ( ! $this->has_subscription($order->get_id())) { |
|
97 | 97 | return $metadata; |
98 | 98 | } |
99 | 99 | |
100 | 100 | return $metadata += array( |
101 | 101 | 'payment_type' => 'recurring', |
102 | - 'site_url' => esc_url( get_site_url() ), |
|
102 | + 'site_url' => esc_url(get_site_url()), |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
109 | 109 | * @since 3.1.0 |
110 | 110 | * @version 4.0.0 |
111 | 111 | */ |
112 | - public function save_source( $order, $source ) { |
|
113 | - parent::save_source( $order, $source ); |
|
112 | + public function save_source($order, $source) { |
|
113 | + parent::save_source($order, $source); |
|
114 | 114 | |
115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
116 | 116 | |
117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order |
118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
122 | 122 | } else { |
123 | 123 | $subscriptions = array(); |
124 | 124 | } |
125 | 125 | |
126 | - foreach ( $subscriptions as $subscription ) { |
|
126 | + foreach ($subscriptions as $subscription) { |
|
127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -137,37 +137,37 @@ discard block |
||
137 | 137 | * @param string $stripe_token (default: '') |
138 | 138 | * @param bool initial_payment |
139 | 139 | */ |
140 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
141 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
140 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
141 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
142 | 142 | /* translators: minimum amount */ |
143 | - return new WP_Error( 'stripe_error', 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 ) ) ); |
|
143 | + return new WP_Error('stripe_error', 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))); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | $customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
147 | 147 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
148 | 148 | |
149 | 149 | // Get source from order |
150 | - $prepared_source = $this->prepare_order_source( $order ); |
|
150 | + $prepared_source = $this->prepare_order_source($order); |
|
151 | 151 | |
152 | 152 | // Or fail :( |
153 | - if ( ! $prepared_source->customer ) { |
|
154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
153 | + if ( ! $prepared_source->customer) { |
|
154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
155 | 155 | } |
156 | 156 | |
157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
158 | 158 | |
159 | 159 | // Make the request |
160 | - $request = $this->generate_payment_request( $order, $prepared_source ); |
|
160 | + $request = $this->generate_payment_request($order, $prepared_source); |
|
161 | 161 | $request['capture'] = 'true'; |
162 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
163 | - $response = WC_Stripe_API::request( $request ); |
|
162 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
163 | + $response = WC_Stripe_API::request($request); |
|
164 | 164 | |
165 | 165 | // Process valid response |
166 | - if ( ! empty( $response->error ) ) { |
|
166 | + if ( ! empty($response->error)) { |
|
167 | 167 | return $response; // Default catch all errors. |
168 | 168 | } |
169 | 169 | |
170 | - $this->process_response( $response, $order ); |
|
170 | + $this->process_response($response, $order); |
|
171 | 171 | |
172 | 172 | return $response; |
173 | 173 | } |
@@ -182,61 +182,61 @@ discard block |
||
182 | 182 | * @param string $stripe_token (default: '') |
183 | 183 | * @param bool initial_payment |
184 | 184 | */ |
185 | - public function retry_subscription_payment( $order = '', $amount = 0 ) { |
|
186 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
185 | + public function retry_subscription_payment($order = '', $amount = 0) { |
|
186 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
187 | 187 | /* translators: minimum amount */ |
188 | - return new WP_Error( 'stripe_error', 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 ) ) ); |
|
188 | + return new WP_Error('stripe_error', 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))); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | $customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
192 | 192 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
193 | 193 | |
194 | 194 | // Get source from order |
195 | - $prepared_source = $this->prepare_order_source( $order ); |
|
195 | + $prepared_source = $this->prepare_order_source($order); |
|
196 | 196 | |
197 | 197 | // Or fail :( |
198 | - if ( ! $prepared_source->customer ) { |
|
199 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
198 | + if ( ! $prepared_source->customer) { |
|
199 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | // Passing empty source with charge customer default. |
203 | 203 | $prepared_source->source = ''; |
204 | 204 | |
205 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
205 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
206 | 206 | |
207 | 207 | // Make the request |
208 | - $request = $this->generate_payment_request( $order, $prepared_source ); |
|
208 | + $request = $this->generate_payment_request($order, $prepared_source); |
|
209 | 209 | $request['capture'] = 'true'; |
210 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
211 | - $response = WC_Stripe_API::request( $request ); |
|
210 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
211 | + $response = WC_Stripe_API::request($request); |
|
212 | 212 | |
213 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
213 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
214 | 214 | /* translators: error message */ |
215 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
215 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
216 | 216 | } |
217 | 217 | |
218 | - $this->process_response( $response, $order ); |
|
218 | + $this->process_response($response, $order); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
222 | 222 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
223 | 223 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
224 | 224 | */ |
225 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
226 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
227 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
225 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
226 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
227 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
228 | 228 | // For BW compat will remove in future |
229 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
230 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
229 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
230 | + $this->delete_renewal_meta($resubscribe_order); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Don't transfer Stripe fee/ID meta to renewal orders. |
235 | 235 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
236 | 236 | */ |
237 | - public function delete_renewal_meta( $renewal_order ) { |
|
238 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
239 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
237 | + public function delete_renewal_meta($renewal_order) { |
|
238 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
239 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
240 | 240 | return $renewal_order; |
241 | 241 | } |
242 | 242 | |
@@ -246,21 +246,21 @@ discard block |
||
246 | 246 | * @param $amount_to_charge float The amount to charge. |
247 | 247 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
248 | 248 | */ |
249 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
250 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
249 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
250 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
251 | 251 | |
252 | - if ( is_wp_error( $response ) ) { |
|
252 | + if (is_wp_error($response)) { |
|
253 | 253 | /* translators: error message */ |
254 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
254 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( ! empty( $response->error ) ) { |
|
257 | + if ( ! empty($response->error)) { |
|
258 | 258 | // This is a very generic error to listen for but worth a retry before total fail. |
259 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
260 | - $this->retry_subscription_payment( $renewal_order, $amount_to_charge ); |
|
259 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
260 | + $this->retry_subscription_payment($renewal_order, $amount_to_charge); |
|
261 | 261 | } else { |
262 | 262 | /* translators: error message */ |
263 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
263 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | } |
@@ -269,20 +269,20 @@ discard block |
||
269 | 269 | * Remove order meta |
270 | 270 | * @param object $order |
271 | 271 | */ |
272 | - public function remove_order_source_before_retry( $order ) { |
|
272 | + public function remove_order_source_before_retry($order) { |
|
273 | 273 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
274 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
274 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
275 | 275 | // For BW compat will remove in the future. |
276 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
276 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
280 | 280 | * Remove order meta |
281 | 281 | * @param object $order |
282 | 282 | */ |
283 | - public function remove_order_customer_before_retry( $order ) { |
|
283 | + public function remove_order_customer_before_retry($order) { |
|
284 | 284 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
285 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
285 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
295 | 295 | * @return void |
296 | 296 | */ |
297 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
298 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
299 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
300 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
297 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
298 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
299 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
300 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
301 | 301 | |
302 | 302 | } else { |
303 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
304 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
303 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
304 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
305 | 305 | } |
306 | 306 | } |
307 | 307 | |
@@ -314,21 +314,21 @@ discard block |
||
314 | 314 | * @param WC_Subscription $subscription An instance of a subscription object |
315 | 315 | * @return array |
316 | 316 | */ |
317 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
318 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
317 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
318 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
319 | 319 | |
320 | 320 | // For BW compat will remove in future. |
321 | - if ( empty( $source_id ) ) { |
|
322 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
321 | + if (empty($source_id)) { |
|
322 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
323 | 323 | |
324 | 324 | // Take this opportunity to update the key name. |
325 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
325 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
326 | 326 | } |
327 | 327 | |
328 | - $payment_meta[ $this->id ] = array( |
|
328 | + $payment_meta[$this->id] = array( |
|
329 | 329 | 'post_meta' => array( |
330 | 330 | '_stripe_customer_id' => array( |
331 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
331 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
332 | 332 | 'label' => 'Stripe Customer ID', |
333 | 333 | ), |
334 | 334 | '_stripe_source_id' => array( |
@@ -351,22 +351,22 @@ discard block |
||
351 | 351 | * @param array $payment_meta associative array of meta data required for automatic payments |
352 | 352 | * @return array |
353 | 353 | */ |
354 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
355 | - if ( $this->id === $payment_method_id ) { |
|
354 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
355 | + if ($this->id === $payment_method_id) { |
|
356 | 356 | |
357 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
358 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
359 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
360 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
357 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
358 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
359 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
360 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | if ( |
364 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
365 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
366 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
367 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
364 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
365 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
366 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
367 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
368 | 368 | |
369 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
369 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
370 | 370 | } |
371 | 371 | } |
372 | 372 | } |
@@ -379,91 +379,91 @@ discard block |
||
379 | 379 | * @param WC_Subscription $subscription the subscription details |
380 | 380 | * @return string the subscription payment method |
381 | 381 | */ |
382 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
382 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
383 | 383 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
384 | 384 | |
385 | 385 | // bail for other payment methods |
386 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
386 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
387 | 387 | return $payment_method_to_display; |
388 | 388 | } |
389 | 389 | |
390 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
390 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
391 | 391 | |
392 | 392 | // For BW compat will remove in future. |
393 | - if ( empty( $stripe_source_id ) ) { |
|
394 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
393 | + if (empty($stripe_source_id)) { |
|
394 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
395 | 395 | |
396 | 396 | // Take this opportunity to update the key name. |
397 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
397 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | $stripe_customer = new WC_Stripe_Customer(); |
401 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
401 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
402 | 402 | |
403 | 403 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
404 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
404 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
405 | 405 | $user_id = $customer_user; |
406 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
407 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
406 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
407 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
408 | 408 | |
409 | 409 | // For BW compat will remove in future. |
410 | - if ( empty( $stripe_source_id ) ) { |
|
411 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
410 | + if (empty($stripe_source_id)) { |
|
411 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
412 | 412 | |
413 | 413 | // Take this opportunity to update the key name. |
414 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
414 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | 418 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
419 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
420 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
421 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
419 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
420 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
421 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
422 | 422 | |
423 | 423 | // For BW compat will remove in future. |
424 | - if ( empty( $stripe_source_id ) ) { |
|
425 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
424 | + if (empty($stripe_source_id)) { |
|
425 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
426 | 426 | |
427 | 427 | // Take this opportunity to update the key name. |
428 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
428 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | |
432 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
432 | + $stripe_customer->set_id($stripe_customer_id); |
|
433 | 433 | $sources = $stripe_customer->get_sources(); |
434 | 434 | |
435 | - if ( $sources ) { |
|
435 | + if ($sources) { |
|
436 | 436 | $found_source = false; |
437 | - foreach ( $sources as $source ) { |
|
438 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
437 | + foreach ($sources as $source) { |
|
438 | + if (isset($source->type) && 'card' === $source->type) { |
|
439 | 439 | $card = $source->card; |
440 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
440 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
441 | 441 | $card = $source; |
442 | 442 | } |
443 | 443 | |
444 | - if ( $source->id === $stripe_source_id ) { |
|
444 | + if ($source->id === $stripe_source_id) { |
|
445 | 445 | $found_source = true; |
446 | 446 | |
447 | - if ( $card ) { |
|
447 | + if ($card) { |
|
448 | 448 | /* translators: 1) card brand 2) last 4 digits */ |
449 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
449 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
450 | 450 | } else { |
451 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
451 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
452 | 452 | } |
453 | 453 | break; |
454 | 454 | } |
455 | 455 | } |
456 | 456 | |
457 | - if ( ! $found_source ) { |
|
458 | - if ( 'card' === $sources[0]->type ) { |
|
457 | + if ( ! $found_source) { |
|
458 | + if ('card' === $sources[0]->type) { |
|
459 | 459 | $card = $sources[0]->card; |
460 | 460 | } |
461 | 461 | |
462 | - if ( $card ) { |
|
462 | + if ($card) { |
|
463 | 463 | /* translators: 1) card brand 2) last 4 digits */ |
464 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
464 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
465 | 465 | } else { |
466 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
466 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | } |
@@ -476,43 +476,43 @@ discard block |
||
476 | 476 | * @param int $order_id |
477 | 477 | * @return array |
478 | 478 | */ |
479 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
480 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
479 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
480 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
481 | 481 | try { |
482 | - $order = wc_get_order( $order_id ); |
|
482 | + $order = wc_get_order($order_id); |
|
483 | 483 | |
484 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
484 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
485 | 485 | /* translators: minimum amount */ |
486 | - throw new Exception( 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 ) ) ); |
|
486 | + throw new Exception(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))); |
|
487 | 487 | } |
488 | 488 | |
489 | - $source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), true ); |
|
489 | + $source = $this->prepare_source($this->create_source_object(), get_current_user_id(), true); |
|
490 | 490 | |
491 | 491 | // We need a source on file to continue. |
492 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
493 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
492 | + if (empty($source->customer) || empty($source->source)) { |
|
493 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | // Store source to order meta |
497 | - $this->save_source( $order, $source ); |
|
497 | + $this->save_source($order, $source); |
|
498 | 498 | |
499 | 499 | // Remove cart |
500 | 500 | WC()->cart->empty_cart(); |
501 | 501 | |
502 | 502 | // Is pre ordered! |
503 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
503 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
504 | 504 | |
505 | 505 | // Return thank you page redirect |
506 | 506 | return array( |
507 | 507 | 'result' => 'success', |
508 | - 'redirect' => $this->get_return_url( $order ), |
|
508 | + 'redirect' => $this->get_return_url($order), |
|
509 | 509 | ); |
510 | - } catch ( Exception $e ) { |
|
511 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
510 | + } catch (Exception $e) { |
|
511 | + wc_add_notice($e->getMessage(), 'error'); |
|
512 | 512 | return; |
513 | 513 | } |
514 | 514 | } else { |
515 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
515 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
516 | 516 | } |
517 | 517 | } |
518 | 518 | |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | * @param WC_Order $order |
522 | 522 | * @return void |
523 | 523 | */ |
524 | - public function process_pre_order_release_payment( $order ) { |
|
524 | + public function process_pre_order_release_payment($order) { |
|
525 | 525 | try { |
526 | 526 | // Define some callbacks if the first attempt fails. |
527 | 527 | $retry_callbacks = array( |
@@ -529,33 +529,33 @@ discard block |
||
529 | 529 | 'remove_order_customer_before_retry', |
530 | 530 | ); |
531 | 531 | |
532 | - while ( 1 ) { |
|
533 | - $source = $this->prepare_order_source( $order ); |
|
534 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
532 | + while (1) { |
|
533 | + $source = $this->prepare_order_source($order); |
|
534 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
535 | 535 | |
536 | - if ( ! empty( $response->error ) ) { |
|
537 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
538 | - throw new Exception( $response->error->message ); |
|
536 | + if ( ! empty($response->error)) { |
|
537 | + if (0 === sizeof($retry_callbacks)) { |
|
538 | + throw new Exception($response->error->message); |
|
539 | 539 | } else { |
540 | - $retry_callback = array_shift( $retry_callbacks ); |
|
541 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
540 | + $retry_callback = array_shift($retry_callbacks); |
|
541 | + call_user_func(array($this, $retry_callback), $order); |
|
542 | 542 | } |
543 | 543 | } else { |
544 | 544 | // Successful |
545 | - $this->process_response( $response, $order ); |
|
545 | + $this->process_response($response, $order); |
|
546 | 546 | break; |
547 | 547 | } |
548 | 548 | } |
549 | - } catch ( Exception $e ) { |
|
549 | + } catch (Exception $e) { |
|
550 | 550 | /* translators: error message */ |
551 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
551 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
552 | 552 | |
553 | 553 | // Mark order as failed if not already set, |
554 | 554 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
555 | - if ( ! $order->has_status( 'failed' ) ) { |
|
556 | - $order->update_status( 'failed', $order_note ); |
|
555 | + if ( ! $order->has_status('failed')) { |
|
556 | + $order->update_status('failed', $order_note); |
|
557 | 557 | } else { |
558 | - $order->add_order_note( $order_note ); |
|
558 | + $order->add_order_note($order_note); |
|
559 | 559 | } |
560 | 560 | } |
561 | 561 | } |