@@ -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_sepa'; |
60 | - $this->method_title = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe SEPA Direct Debit', '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', |
@@ -84,25 +84,25 @@ discard block |
||
84 | 84 | // Load the settings. |
85 | 85 | $this->init_settings(); |
86 | 86 | |
87 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
88 | - $this->title = $this->get_option( 'title' ); |
|
89 | - $this->description = $this->get_option( 'description' ); |
|
90 | - $this->enabled = $this->get_option( 'enabled' ); |
|
91 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
92 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
93 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
94 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
95 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
96 | - |
|
97 | - if ( $this->testmode ) { |
|
98 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
99 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
87 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
88 | + $this->title = $this->get_option('title'); |
|
89 | + $this->description = $this->get_option('description'); |
|
90 | + $this->enabled = $this->get_option('enabled'); |
|
91 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
92 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
93 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
94 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
95 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
96 | + |
|
97 | + if ($this->testmode) { |
|
98 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
99 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
100 | 100 | } |
101 | 101 | |
102 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
103 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
104 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
105 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
102 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
103 | + add_action('admin_notices', array($this, 'check_environment')); |
|
104 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
105 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,19 +112,19 @@ discard block |
||
112 | 112 | * @version 4.0.0 |
113 | 113 | */ |
114 | 114 | public function check_environment() { |
115 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
115 | + if ( ! current_user_can('manage_woocommerce')) { |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $environment_warning = $this->get_environment_warning(); |
120 | 120 | |
121 | - if ( $environment_warning ) { |
|
122 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
121 | + if ($environment_warning) { |
|
122 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
123 | 123 | } |
124 | 124 | |
125 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
126 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
127 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
125 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
126 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
127 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
128 | 128 | echo '</p></div>'; |
129 | 129 | } |
130 | 130 | } |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | * @version 4.0.0 |
138 | 138 | */ |
139 | 139 | public function get_environment_warning() { |
140 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
141 | - $message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
140 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
141 | + $message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
142 | 142 | |
143 | 143 | return $message; |
144 | 144 | } |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | * @return array |
155 | 155 | */ |
156 | 156 | public function get_supported_currency() { |
157 | - return apply_filters( 'wc_stripe_sepa_supported_currencies', array( |
|
157 | + return apply_filters('wc_stripe_sepa_supported_currencies', array( |
|
158 | 158 | 'EUR', |
159 | - ) ); |
|
159 | + )); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @return bool |
168 | 168 | */ |
169 | 169 | public function is_available() { |
170 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
170 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
171 | 171 | return false; |
172 | 172 | } |
173 | 173 | |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * @return array |
183 | 183 | */ |
184 | 184 | public function payment_icons() { |
185 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
185 | + return apply_filters('wc_stripe_payment_icons', array( |
|
186 | 186 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
187 | - ) ); |
|
187 | + )); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | |
202 | 202 | $icons_str .= $icons['sepa']; |
203 | 203 | |
204 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
204 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -212,19 +212,19 @@ discard block |
||
212 | 212 | * @access public |
213 | 213 | */ |
214 | 214 | public function payment_scripts() { |
215 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
215 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 | |
219 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
220 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
219 | + wp_enqueue_style('stripe_paymentfonts'); |
|
220 | + wp_enqueue_script('woocommerce_stripe'); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | 224 | * Initialize Gateway Settings Form Fields. |
225 | 225 | */ |
226 | 226 | public function init_form_fields() { |
227 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' ); |
|
227 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php'); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function mandate_display() { |
238 | 238 | /* translators: statement descriptor */ |
239 | - printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) ); |
|
239 | + printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor)); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -247,24 +247,24 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function form() { |
249 | 249 | ?> |
250 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
251 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
250 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
251 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
252 | 252 | <p class="wc-stripe-sepa-mandate"><?php $this->mandate_display(); ?></p> |
253 | 253 | <p class="form-row form-row-wide validate-required"> |
254 | 254 | <label for="stripe-sepa-owner"> |
255 | - <?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?> |
|
255 | + <?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?> |
|
256 | 256 | </label> |
257 | 257 | <input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" /> |
258 | 258 | </p> |
259 | 259 | <p class="form-row form-row-wide validate-required"> |
260 | 260 | <label for="stripe-sepa-iban"> |
261 | - <?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?> |
|
261 | + <?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?> |
|
262 | 262 | </label> |
263 | 263 | <input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" /> |
264 | 264 | </p> |
265 | 265 | <!-- Used to display form errors --> |
266 | 266 | <div class="stripe-source-errors" role="alert"></div> |
267 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
267 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
268 | 268 | <div class="clear"></div> |
269 | 269 | </fieldset> |
270 | 270 | <?php |
@@ -276,42 +276,42 @@ discard block |
||
276 | 276 | public function payment_fields() { |
277 | 277 | $user = wp_get_current_user(); |
278 | 278 | $total = WC()->cart->total; |
279 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
279 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
280 | 280 | |
281 | 281 | // If paying from order, we need to get total from order not cart. |
282 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
283 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
282 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
283 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
284 | 284 | $total = $order->get_total(); |
285 | 285 | } |
286 | 286 | |
287 | - if ( is_add_payment_method_page() ) { |
|
288 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
289 | - $total = ''; |
|
287 | + if (is_add_payment_method_page()) { |
|
288 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
289 | + $total = ''; |
|
290 | 290 | } else { |
291 | 291 | $pay_button_text = ''; |
292 | 292 | } |
293 | 293 | |
294 | 294 | echo '<div |
295 | 295 | id="stripe-sepa_debit-payment-data" |
296 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
297 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
296 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
297 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
298 | 298 | |
299 | - if ( $this->description ) { |
|
300 | - if ( $this->testmode ) { |
|
301 | - $this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' ); |
|
302 | - $this->description = trim( $this->description ); |
|
299 | + if ($this->description) { |
|
300 | + if ($this->testmode) { |
|
301 | + $this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe'); |
|
302 | + $this->description = trim($this->description); |
|
303 | 303 | } |
304 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
304 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
305 | 305 | } |
306 | 306 | |
307 | - if ( $display_tokenization ) { |
|
307 | + if ($display_tokenization) { |
|
308 | 308 | $this->tokenization_script(); |
309 | 309 | $this->saved_payment_methods(); |
310 | 310 | } |
311 | 311 | |
312 | 312 | $this->form(); |
313 | 313 | |
314 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
314 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
315 | 315 | $this->save_payment_method_checkbox(); |
316 | 316 | } |
317 | 317 | |
@@ -329,80 +329,80 @@ discard block |
||
329 | 329 | * |
330 | 330 | * @return array|void |
331 | 331 | */ |
332 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
332 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
333 | 333 | try { |
334 | - $order = wc_get_order( $order_id ); |
|
334 | + $order = wc_get_order($order_id); |
|
335 | 335 | |
336 | 336 | // This comes from the create account checkbox in the checkout page. |
337 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
337 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
338 | 338 | |
339 | - if ( $create_account ) { |
|
339 | + if ($create_account) { |
|
340 | 340 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
341 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
341 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
342 | 342 | $new_stripe_customer->create_customer(); |
343 | 343 | } |
344 | 344 | |
345 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
345 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
346 | 346 | |
347 | 347 | // Store source to order meta. |
348 | - $this->save_source( $order, $prepared_source ); |
|
348 | + $this->save_source($order, $prepared_source); |
|
349 | 349 | |
350 | 350 | // Result from Stripe API request. |
351 | 351 | $response = null; |
352 | 352 | |
353 | - if ( $order->get_total() > 0 ) { |
|
353 | + if ($order->get_total() > 0) { |
|
354 | 354 | // This will throw exception if not valid. |
355 | - $this->validate_minimum_order_amount( $order ); |
|
355 | + $this->validate_minimum_order_amount($order); |
|
356 | 356 | |
357 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
357 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
358 | 358 | |
359 | 359 | // Make the request. |
360 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
360 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
361 | 361 | |
362 | - if ( ! empty( $response->error ) ) { |
|
362 | + if ( ! empty($response->error)) { |
|
363 | 363 | // If it is an API error such connection or server, let's retry. |
364 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
365 | - if ( $retry ) { |
|
366 | - sleep( 5 ); |
|
367 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
364 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
365 | + if ($retry) { |
|
366 | + sleep(5); |
|
367 | + return $this->process_payment($order_id, false, $force_save_source); |
|
368 | 368 | } else { |
369 | 369 | $message = 'API connection error and retries exhausted.'; |
370 | - $order->add_order_note( $message ); |
|
371 | - throw new Exception( $message ); |
|
370 | + $order->add_order_note($message); |
|
371 | + throw new Exception($message); |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
375 | 375 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
376 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
377 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
376 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
377 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
378 | 378 | |
379 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
380 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
379 | + return $this->process_payment($order_id, false, $force_save_source); |
|
380 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
381 | 381 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
382 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
382 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
383 | 383 | $wc_token->delete(); |
384 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
385 | - $order->add_order_note( $message ); |
|
386 | - throw new Exception( $message ); |
|
384 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
385 | + $order->add_order_note($message); |
|
386 | + throw new Exception($message); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
390 | 390 | |
391 | - if ( 'card_error' === $response->error->type ) { |
|
392 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
391 | + if ('card_error' === $response->error->type) { |
|
392 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
393 | 393 | } else { |
394 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
394 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
395 | 395 | } |
396 | 396 | |
397 | - $order->add_order_note( $message ); |
|
397 | + $order->add_order_note($message); |
|
398 | 398 | |
399 | - throw new Exception( $message ); |
|
399 | + throw new Exception($message); |
|
400 | 400 | } |
401 | 401 | |
402 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
402 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
403 | 403 | |
404 | 404 | // Process valid response. |
405 | - $this->process_response( $response, $order ); |
|
405 | + $this->process_response($response, $order); |
|
406 | 406 | } else { |
407 | 407 | $order->payment_complete(); |
408 | 408 | } |
@@ -413,17 +413,17 @@ discard block |
||
413 | 413 | // Return thank you page redirect. |
414 | 414 | return array( |
415 | 415 | 'result' => 'success', |
416 | - 'redirect' => $this->get_return_url( $order ), |
|
416 | + 'redirect' => $this->get_return_url($order), |
|
417 | 417 | ); |
418 | 418 | |
419 | - } catch ( Exception $e ) { |
|
420 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
421 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
419 | + } catch (Exception $e) { |
|
420 | + wc_add_notice($e->getMessage(), 'error'); |
|
421 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
422 | 422 | |
423 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
423 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
424 | 424 | |
425 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
426 | - $this->send_failed_order_email( $order_id ); |
|
425 | + if ($order->has_status(array('pending', 'failed'))) { |
|
426 | + $this->send_failed_order_email($order_id); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @version 4.0.0 |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
20 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | * @version 4.0.0 |
28 | 28 | */ |
29 | 29 | public function check_for_webhook() { |
30 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
31 | - || ! isset( $_GET['wc-api'] ) |
|
32 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
30 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
31 | + || ! isset($_GET['wc-api']) |
|
32 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
33 | 33 | ) { |
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - $request_body = file_get_contents( 'php://input' ); |
|
38 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
37 | + $request_body = file_get_contents('php://input'); |
|
38 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
39 | 39 | |
40 | 40 | // Validate it to make sure it is legit. |
41 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
42 | - $this->process_webhook( $request_body ); |
|
43 | - status_header( 200 ); |
|
41 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
42 | + $this->process_webhook($request_body); |
|
43 | + status_header(200); |
|
44 | 44 | exit; |
45 | 45 | } else { |
46 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
47 | - status_header( 400 ); |
|
46 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
47 | + status_header(400); |
|
48 | 48 | exit; |
49 | 49 | } |
50 | 50 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | * @param string $request_body The request body from Stripe. |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
63 | - if ( null === $request_headers || null === $request_body ) { |
|
62 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
63 | + if (null === $request_headers || null === $request_body) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
67 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @version 4.0.0 |
81 | 81 | */ |
82 | 82 | public function get_request_headers() { |
83 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
83 | + if ( ! function_exists('getallheaders')) { |
|
84 | 84 | $headers = []; |
85 | - foreach ( $_SERVER as $name => $value ) { |
|
86 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
87 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
85 | + foreach ($_SERVER as $name => $value) { |
|
86 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
87 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -103,30 +103,30 @@ discard block |
||
103 | 103 | * @param object $notification |
104 | 104 | * @param bool $retry |
105 | 105 | */ |
106 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
106 | + public function process_webhook_payment($notification, $retry = true) { |
|
107 | 107 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
108 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
108 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
112 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
112 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
113 | 113 | |
114 | - if ( ! $order ) { |
|
115 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
114 | + if ( ! $order) { |
|
115 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
120 | 120 | $source_id = $notification->data->object->id; |
121 | 121 | |
122 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
122 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
123 | 123 | |
124 | 124 | try { |
125 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
125 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
129 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
@@ -134,73 +134,73 @@ discard block |
||
134 | 134 | $response = null; |
135 | 135 | |
136 | 136 | // This will throw exception if not valid. |
137 | - $this->validate_minimum_order_amount( $order ); |
|
137 | + $this->validate_minimum_order_amount($order); |
|
138 | 138 | |
139 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
139 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
140 | 140 | |
141 | 141 | // Prep source object. |
142 | 142 | $source_object = new stdClass(); |
143 | 143 | $source_object->token_id = ''; |
144 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
144 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
145 | 145 | $source_object->source = $source_id; |
146 | 146 | |
147 | 147 | // Make the request. |
148 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
148 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
149 | 149 | |
150 | - if ( ! empty( $response->error ) ) { |
|
150 | + if ( ! empty($response->error)) { |
|
151 | 151 | // If it is an API error such connection or server, let's retry. |
152 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
153 | - if ( $retry ) { |
|
154 | - sleep( 5 ); |
|
155 | - return $this->process_payment( $order_id, false ); |
|
152 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
153 | + if ($retry) { |
|
154 | + sleep(5); |
|
155 | + return $this->process_payment($order_id, false); |
|
156 | 156 | } else { |
157 | 157 | $message = 'API connection error and retries exhausted.'; |
158 | - $order->add_order_note( $message ); |
|
159 | - throw new Exception( $message ); |
|
158 | + $order->add_order_note($message); |
|
159 | + throw new Exception($message); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
164 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
165 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
164 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
165 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
166 | 166 | |
167 | - return $this->process_payment( $order_id, false ); |
|
167 | + return $this->process_payment($order_id, false); |
|
168 | 168 | |
169 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
169 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
170 | 170 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
171 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
171 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
172 | 172 | $wc_token->delete(); |
173 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
174 | - $order->add_order_note( $message ); |
|
175 | - throw new Exception( $message ); |
|
173 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
174 | + $order->add_order_note($message); |
|
175 | + throw new Exception($message); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
179 | 179 | |
180 | - if ( 'card_error' === $response->error->type ) { |
|
181 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
180 | + if ('card_error' === $response->error->type) { |
|
181 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
182 | 182 | } else { |
183 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
183 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
184 | 184 | } |
185 | 185 | |
186 | - $order->add_order_note( $message ); |
|
186 | + $order->add_order_note($message); |
|
187 | 187 | |
188 | - throw new Exception( $message ); |
|
188 | + throw new Exception($message); |
|
189 | 189 | } |
190 | 190 | |
191 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
191 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
192 | 192 | |
193 | - $this->process_response( $response, $order ); |
|
193 | + $this->process_response($response, $order); |
|
194 | 194 | |
195 | - } catch ( Exception $e ) { |
|
196 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
195 | + } catch (Exception $e) { |
|
196 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
197 | 197 | |
198 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
198 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
199 | 199 | |
200 | - $statuses = array( 'pending', 'failed' ); |
|
200 | + $statuses = array('pending', 'failed'); |
|
201 | 201 | |
202 | - if ( $order->has_status( $statuses ) ) { |
|
203 | - $this->send_failed_order_email( $order_id ); |
|
202 | + if ($order->has_status($statuses)) { |
|
203 | + $this->send_failed_order_email($order_id); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | } |
@@ -214,18 +214,18 @@ discard block |
||
214 | 214 | * @version 4.0.0 |
215 | 215 | * @param object $notification |
216 | 216 | */ |
217 | - public function process_webhook_dispute( $notification ) { |
|
218 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
217 | + public function process_webhook_dispute($notification) { |
|
218 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
219 | 219 | |
220 | - if ( ! $order ) { |
|
221 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
220 | + if ( ! $order) { |
|
221 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | |
225 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
225 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
226 | 226 | |
227 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
228 | - $this->send_failed_order_email( $order_id ); |
|
227 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
228 | + $this->send_failed_order_email($order_id); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -236,41 +236,41 @@ discard block |
||
236 | 236 | * @version 4.0.0 |
237 | 237 | * @param object $notification |
238 | 238 | */ |
239 | - public function process_webhook_capture( $notification ) { |
|
240 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
239 | + public function process_webhook_capture($notification) { |
|
240 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
241 | 241 | |
242 | - if ( ! $order ) { |
|
243 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
242 | + if ( ! $order) { |
|
243 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | |
247 | 247 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
248 | 248 | |
249 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
250 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
251 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
249 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
250 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
251 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
252 | 252 | |
253 | - if ( $charge && 'no' === $captured ) { |
|
254 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
253 | + if ($charge && 'no' === $captured) { |
|
254 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
255 | 255 | |
256 | 256 | // Store other data such as fees |
257 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
257 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
258 | 258 | |
259 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
260 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
259 | + if (isset($notification->data->object->balance_transaction)) { |
|
260 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
261 | 261 | } |
262 | 262 | |
263 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
263 | + if (is_callable(array($order, 'save'))) { |
|
264 | 264 | $order->save(); |
265 | 265 | } |
266 | 266 | |
267 | 267 | /* translators: transaction id */ |
268 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
268 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
269 | 269 | |
270 | 270 | // Check and see if capture is partial. |
271 | - if ( $this->is_partial_capture( $notification ) ) { |
|
272 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
273 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
271 | + if ($this->is_partial_capture($notification)) { |
|
272 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
273 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
274 | 274 | $order->save(); |
275 | 275 | } |
276 | 276 | } |
@@ -285,38 +285,38 @@ discard block |
||
285 | 285 | * @version 4.0.0 |
286 | 286 | * @param object $notification |
287 | 287 | */ |
288 | - public function process_webhook_charge_succeeded( $notification ) { |
|
288 | + public function process_webhook_charge_succeeded($notification) { |
|
289 | 289 | // The following payment methods are synchronous so does not need to be handle via webhook. |
290 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
290 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
291 | 291 | return; |
292 | 292 | } |
293 | 293 | |
294 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
294 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
295 | 295 | |
296 | - if ( ! $order ) { |
|
297 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
296 | + if ( ! $order) { |
|
297 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
298 | 298 | return; |
299 | 299 | } |
300 | 300 | |
301 | 301 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
302 | 302 | |
303 | - if ( 'on-hold' !== $order->get_status() ) { |
|
303 | + if ('on-hold' !== $order->get_status()) { |
|
304 | 304 | return; |
305 | 305 | } |
306 | 306 | |
307 | 307 | // Store other data such as fees |
308 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
308 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
309 | 309 | |
310 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
311 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
310 | + if (isset($notification->data->object->balance_transaction)) { |
|
311 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
312 | 312 | } |
313 | 313 | |
314 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
314 | + if (is_callable(array($order, 'save'))) { |
|
315 | 315 | $order->save(); |
316 | 316 | } |
317 | 317 | |
318 | 318 | /* translators: transaction id */ |
319 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
319 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -327,23 +327,23 @@ discard block |
||
327 | 327 | * @version 4.0.0 |
328 | 328 | * @param object $notification |
329 | 329 | */ |
330 | - public function process_webhook_charge_failed( $notification ) { |
|
331 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
330 | + public function process_webhook_charge_failed($notification) { |
|
331 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
332 | 332 | |
333 | - if ( ! $order ) { |
|
334 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
333 | + if ( ! $order) { |
|
334 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | |
338 | 338 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
339 | 339 | |
340 | - if ( 'on-hold' !== $order->get_status() ) { |
|
340 | + if ('on-hold' !== $order->get_status()) { |
|
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
344 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
345 | 345 | |
346 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
346 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
@@ -354,23 +354,23 @@ discard block |
||
354 | 354 | * @version 4.0.0 |
355 | 355 | * @param object $notification |
356 | 356 | */ |
357 | - public function process_webhook_source_canceled( $notification ) { |
|
358 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
357 | + public function process_webhook_source_canceled($notification) { |
|
358 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
359 | 359 | |
360 | - if ( ! $order ) { |
|
361 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
360 | + if ( ! $order) { |
|
361 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
366 | 366 | |
367 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
367 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
371 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
372 | 372 | |
373 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
373 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -381,31 +381,31 @@ discard block |
||
381 | 381 | * @version 4.0.0 |
382 | 382 | * @param object $notification |
383 | 383 | */ |
384 | - public function process_webhook_refund( $notification ) { |
|
385 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
384 | + public function process_webhook_refund($notification) { |
|
385 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
386 | 386 | |
387 | - if ( ! $order ) { |
|
388 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
387 | + if ( ! $order) { |
|
388 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
389 | 389 | return; |
390 | 390 | } |
391 | 391 | |
392 | 392 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
393 | 393 | |
394 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
395 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
396 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
394 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
395 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
396 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
397 | 397 | |
398 | 398 | // Only refund captured charge. |
399 | - if ( $charge && 'yes' === $captured ) { |
|
399 | + if ($charge && 'yes' === $captured) { |
|
400 | 400 | // Create the refund. |
401 | - $refund = wc_create_refund( array( |
|
401 | + $refund = wc_create_refund(array( |
|
402 | 402 | 'order_id' => $order_id, |
403 | - 'amount' => $this->get_refund_amount( $notification ), |
|
404 | - 'reason' => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ), |
|
405 | - ) ); |
|
403 | + 'amount' => $this->get_refund_amount($notification), |
|
404 | + 'reason' => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'), |
|
405 | + )); |
|
406 | 406 | |
407 | - if ( is_wp_error( $refund ) ) { |
|
408 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
407 | + if (is_wp_error($refund)) { |
|
408 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
409 | 409 | } |
410 | 410 | } |
411 | 411 | } |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | * @version 4.0.0 |
419 | 419 | * @param object $notification |
420 | 420 | */ |
421 | - public function is_partial_capture( $notification ) { |
|
421 | + public function is_partial_capture($notification) { |
|
422 | 422 | return 0 < $notification->data->object->amount_refunded; |
423 | 423 | } |
424 | 424 | |
@@ -429,11 +429,11 @@ discard block |
||
429 | 429 | * @version 4.0.0 |
430 | 430 | * @param object $notification |
431 | 431 | */ |
432 | - public function get_refund_amount( $notification ) { |
|
433 | - if ( $this->is_partial_capture( $notification ) ) { |
|
432 | + public function get_refund_amount($notification) { |
|
433 | + if ($this->is_partial_capture($notification)) { |
|
434 | 434 | $amount = $notification->data->object->amount_refunded / 100; |
435 | 435 | |
436 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
436 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
437 | 437 | $amount = $notification->data->object->amount_refunded; |
438 | 438 | } |
439 | 439 | |
@@ -450,12 +450,12 @@ discard block |
||
450 | 450 | * @version 4.0.0 |
451 | 451 | * @param object $notification |
452 | 452 | */ |
453 | - public function get_partial_amount_to_charge( $notification ) { |
|
454 | - if ( $this->is_partial_capture( $notification ) ) { |
|
455 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
453 | + public function get_partial_amount_to_charge($notification) { |
|
454 | + if ($this->is_partial_capture($notification)) { |
|
455 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
456 | 456 | |
457 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
458 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
457 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
458 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | return $amount; |
@@ -471,36 +471,36 @@ discard block |
||
471 | 471 | * @version 4.0.0 |
472 | 472 | * @param string $request_body |
473 | 473 | */ |
474 | - public function process_webhook( $request_body ) { |
|
475 | - $notification = json_decode( $request_body ); |
|
474 | + public function process_webhook($request_body) { |
|
475 | + $notification = json_decode($request_body); |
|
476 | 476 | |
477 | - switch ( $notification->type ) { |
|
477 | + switch ($notification->type) { |
|
478 | 478 | case 'source.chargeable': |
479 | - $this->process_webhook_payment( $notification ); |
|
479 | + $this->process_webhook_payment($notification); |
|
480 | 480 | break; |
481 | 481 | |
482 | 482 | case 'source.canceled': |
483 | - $this->process_webhook_source_canceled( $notification ); |
|
483 | + $this->process_webhook_source_canceled($notification); |
|
484 | 484 | break; |
485 | 485 | |
486 | 486 | case 'charge.succeeded': |
487 | - $this->process_webhook_charge_succeeded( $notification ); |
|
487 | + $this->process_webhook_charge_succeeded($notification); |
|
488 | 488 | break; |
489 | 489 | |
490 | 490 | case 'charge.failed': |
491 | - $this->process_webhook_charge_failed( $notification ); |
|
491 | + $this->process_webhook_charge_failed($notification); |
|
492 | 492 | break; |
493 | 493 | |
494 | 494 | case 'charge.captured': |
495 | - $this->process_webhook_capture( $notification ); |
|
495 | + $this->process_webhook_capture($notification); |
|
496 | 496 | break; |
497 | 497 | |
498 | 498 | case 'charge.dispute.created': |
499 | - $this->process_webhook_dispute( $notification ); |
|
499 | + $this->process_webhook_dispute($notification); |
|
500 | 500 | break; |
501 | 501 | |
502 | 502 | case 'charge.refunded': |
503 | - $this->process_webhook_refund( $notification ); |
|
503 | + $this->process_webhook_refund($notification); |
|
504 | 504 | break; |
505 | 505 | |
506 | 506 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | * Check if this gateway is enabled |
19 | 19 | */ |
20 | 20 | public function is_available() { |
21 | - if ( 'yes' === $this->enabled ) { |
|
22 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
21 | + if ('yes' === $this->enabled) { |
|
22 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
25 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | return true; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @since 4.0.0 |
38 | 38 | * @version 4.0.0 |
39 | 39 | */ |
40 | - public function add_admin_notice( $slug, $class, $message ) { |
|
41 | - $this->notices[ $slug ] = array( |
|
40 | + public function add_admin_notice($slug, $class, $message) { |
|
41 | + $this->notices[$slug] = array( |
|
42 | 42 | 'class' => $class, |
43 | 43 | 'message' => $message, |
44 | 44 | ); |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @version 4.0.0 |
52 | 52 | */ |
53 | 53 | public function remove_admin_notice() { |
54 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
55 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
54 | + if (did_action('woocommerce_update_options')) { |
|
55 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | * @version 4.0.0 |
65 | 65 | * @param object $order |
66 | 66 | */ |
67 | - public function validate_minimum_order_amount( $order ) { |
|
68 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
67 | + public function validate_minimum_order_amount($order) { |
|
68 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
69 | 69 | /* translators: 1) dollar amount */ |
70 | - 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 ) ) ); |
|
70 | + 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))); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
@@ -77,14 +77,14 @@ discard block |
||
77 | 77 | * @since 4.0.0 |
78 | 78 | * @version 4.0.0 |
79 | 79 | */ |
80 | - public function get_transaction_url( $order ) { |
|
81 | - if ( $this->testmode ) { |
|
80 | + public function get_transaction_url($order) { |
|
81 | + if ($this->testmode) { |
|
82 | 82 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
83 | 83 | } else { |
84 | 84 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
85 | 85 | } |
86 | 86 | |
87 | - return parent::get_transaction_url( $order ); |
|
87 | + return parent::get_transaction_url($order); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | * @since 4.0.0 |
94 | 94 | * @version 4.0.0 |
95 | 95 | */ |
96 | - public function get_stripe_customer_id( $order ) { |
|
97 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
96 | + public function get_stripe_customer_id($order) { |
|
97 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
98 | 98 | |
99 | - if ( empty( $customer ) ) { |
|
99 | + if (empty($customer)) { |
|
100 | 100 | // Try to get it via the order. |
101 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
102 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
101 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
102 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
103 | 103 | } else { |
104 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
104 | + return $order->get_meta('_stripe_customer_id', true); |
|
105 | 105 | } |
106 | 106 | } else { |
107 | 107 | return $customer; |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | * @param object $order |
119 | 119 | * @param int $id Stripe session id. |
120 | 120 | */ |
121 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
122 | - if ( is_object( $order ) ) { |
|
123 | - if ( empty( $id ) ) { |
|
121 | + public function get_stripe_return_url($order = null, $id = null) { |
|
122 | + if (is_object($order)) { |
|
123 | + if (empty($id)) { |
|
124 | 124 | $id = uniqid(); |
125 | 125 | } |
126 | 126 | |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | 'order_id' => $order_id, |
132 | 132 | ); |
133 | 133 | |
134 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
134 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
135 | 135 | } |
136 | 136 | |
137 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
137 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -146,48 +146,47 @@ discard block |
||
146 | 146 | * @param object $source |
147 | 147 | * @return array() |
148 | 148 | */ |
149 | - public function generate_payment_request( $order, $source ) { |
|
150 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
151 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
152 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
149 | + public function generate_payment_request($order, $source) { |
|
150 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
151 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
152 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
153 | 153 | $post_data = array(); |
154 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
155 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
154 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
155 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
156 | 156 | /* translators: 1) blog name 2) order number */ |
157 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
157 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
158 | 158 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
159 | 159 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
160 | 160 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
161 | 161 | |
162 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
162 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
163 | 163 | $post_data['receipt_email'] = $billing_email; |
164 | 164 | } |
165 | 165 | |
166 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
167 | - case 'stripe': |
|
168 | - if ( ! empty( $statement_descriptor ) ) { |
|
169 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
166 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
167 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
168 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
170 | 169 | } |
171 | 170 | |
172 | - $post_data['capture'] = $capture ? 'true' : 'false'; |
|
171 | + $post_data['capture'] = $capture ? 'true' : 'false'; |
|
173 | 172 | break; |
174 | 173 | } |
175 | 174 | |
176 | 175 | $post_data['expand[]'] = 'balance_transaction'; |
177 | 176 | |
178 | 177 | $metadata = array( |
179 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
180 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
178 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
179 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
181 | 180 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
182 | 181 | ); |
183 | 182 | |
184 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
183 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
185 | 184 | |
186 | - if ( $source->customer ) { |
|
185 | + if ($source->customer) { |
|
187 | 186 | $post_data['customer'] = $source->customer; |
188 | 187 | } |
189 | 188 | |
190 | - if ( $source->source ) { |
|
189 | + if ($source->source) { |
|
191 | 190 | $post_data['source'] = $source->source; |
192 | 191 | } |
193 | 192 | |
@@ -199,77 +198,77 @@ discard block |
||
199 | 198 | * @param WC_Order $order |
200 | 199 | * @param object $source |
201 | 200 | */ |
202 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
201 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
203 | 202 | } |
204 | 203 | |
205 | 204 | /** |
206 | 205 | * Store extra meta data for an order from a Stripe Response. |
207 | 206 | */ |
208 | - public function process_response( $response, $order ) { |
|
209 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
207 | + public function process_response($response, $order) { |
|
208 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
210 | 209 | |
211 | 210 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
212 | 211 | |
213 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
212 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
214 | 213 | |
215 | 214 | // Store charge data |
216 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
215 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
217 | 216 | |
218 | 217 | // Store other data such as fees |
219 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
218 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
220 | 219 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
221 | 220 | // values are in the local currency of the Stripe account, not from WC. |
222 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
223 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
224 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
225 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
221 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
222 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
223 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
224 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
226 | 225 | } |
227 | 226 | |
228 | - if ( 'yes' === $captured ) { |
|
227 | + if ('yes' === $captured) { |
|
229 | 228 | /** |
230 | 229 | * Charge can be captured but in a pending state. Payment methods |
231 | 230 | * that are asynchronous may take couple days to clear. Webhook will |
232 | 231 | * take care of the status changes. |
233 | 232 | */ |
234 | - if ( 'pending' === $response->status ) { |
|
235 | - if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) { |
|
236 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
233 | + if ('pending' === $response->status) { |
|
234 | + if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) { |
|
235 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
237 | 236 | } |
238 | 237 | |
239 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
238 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
240 | 239 | /* translators: transaction id */ |
241 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
240 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
242 | 241 | } |
243 | 242 | |
244 | - if ( 'succeeded' === $response->status ) { |
|
245 | - $order->payment_complete( $response->id ); |
|
243 | + if ('succeeded' === $response->status) { |
|
244 | + $order->payment_complete($response->id); |
|
246 | 245 | |
247 | 246 | /* translators: transaction id */ |
248 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
249 | - $order->add_order_note( $message ); |
|
247 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
248 | + $order->add_order_note($message); |
|
250 | 249 | } |
251 | 250 | |
252 | - if ( 'failed' === $response->status ) { |
|
253 | - $error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
254 | - $order->add_order_note( $error_msg ); |
|
255 | - throw new Exception( $error_msg ); |
|
251 | + if ('failed' === $response->status) { |
|
252 | + $error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
253 | + $order->add_order_note($error_msg); |
|
254 | + throw new Exception($error_msg); |
|
256 | 255 | } |
257 | 256 | } else { |
258 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
257 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
259 | 258 | |
260 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
261 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
259 | + if ($order->has_status(array('pending', 'failed'))) { |
|
260 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
262 | 261 | } |
263 | 262 | |
264 | 263 | /* translators: transaction id */ |
265 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
264 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
266 | 265 | } |
267 | 266 | |
268 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
267 | + if (is_callable(array($order, 'save'))) { |
|
269 | 268 | $order->save(); |
270 | 269 | } |
271 | 270 | |
272 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
271 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
273 | 272 | |
274 | 273 | return $response; |
275 | 274 | } |
@@ -282,10 +281,10 @@ discard block |
||
282 | 281 | * @param int $order_id |
283 | 282 | * @return null |
284 | 283 | */ |
285 | - public function send_failed_order_email( $order_id ) { |
|
284 | + public function send_failed_order_email($order_id) { |
|
286 | 285 | $emails = WC()->mailer()->get_emails(); |
287 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
288 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
286 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
287 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
289 | 288 | } |
290 | 289 | } |
291 | 290 | |
@@ -297,7 +296,7 @@ discard block |
||
297 | 296 | * @param object $order |
298 | 297 | * @return object $details |
299 | 298 | */ |
300 | - public function get_owner_details( $order ) { |
|
299 | + public function get_owner_details($order) { |
|
301 | 300 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
302 | 301 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
303 | 302 | |
@@ -308,8 +307,8 @@ discard block |
||
308 | 307 | |
309 | 308 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
310 | 309 | |
311 | - if ( ! empty( $phone ) ) { |
|
312 | - $details['phone'] = $phone; |
|
310 | + if ( ! empty($phone)) { |
|
311 | + $details['phone'] = $phone; |
|
313 | 312 | } |
314 | 313 | |
315 | 314 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -319,7 +318,7 @@ discard block |
||
319 | 318 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
320 | 319 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
321 | 320 | |
322 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
321 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
323 | 322 | } |
324 | 323 | |
325 | 324 | /** |
@@ -335,58 +334,58 @@ discard block |
||
335 | 334 | * @throws Exception When card was not added or for and invalid card. |
336 | 335 | * @return object |
337 | 336 | */ |
338 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
339 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
337 | + public function prepare_source($user_id, $force_save_source = false) { |
|
338 | + $customer = new WC_Stripe_Customer($user_id); |
|
340 | 339 | $set_customer = true; |
341 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
340 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
342 | 341 | $source = ''; |
343 | 342 | $wc_token_id = false; |
344 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
343 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
345 | 344 | |
346 | 345 | // New CC info was entered and we have a new source to process. |
347 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
346 | + if ( ! empty($_POST['stripe_source'])) { |
|
348 | 347 | // This gets the source object from Stripe. |
349 | - $source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ); |
|
348 | + $source = json_decode(wc_clean(stripslashes($_POST['stripe_source']))); |
|
350 | 349 | |
351 | 350 | // This checks to see if customer opted to save the payment method to file. |
352 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
351 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
353 | 352 | |
354 | 353 | /** |
355 | 354 | * This is true if the user wants to store the card to their account. |
356 | 355 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
357 | 356 | * actually reusable. Either that or force_save_source is true. |
358 | 357 | */ |
359 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage ) || $force_save_source ) { |
|
360 | - $source = $customer->add_source( $source->id ); |
|
358 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage) || $force_save_source) { |
|
359 | + $source = $customer->add_source($source->id); |
|
361 | 360 | |
362 | - if ( ! empty( $source->error ) ) { |
|
363 | - throw new Exception( $source->error->message ); |
|
361 | + if ( ! empty($source->error)) { |
|
362 | + throw new Exception($source->error->message); |
|
364 | 363 | } |
365 | 364 | } else { |
366 | 365 | $source = $source->id; |
367 | 366 | } |
368 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
367 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
369 | 368 | // Use an existing token, and then process the payment |
370 | 369 | |
371 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
372 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
370 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
371 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
373 | 372 | |
374 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
375 | - WC()->session->set( 'refresh_totals', true ); |
|
376 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
373 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
374 | + WC()->session->set('refresh_totals', true); |
|
375 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
377 | 376 | } |
378 | 377 | |
379 | 378 | $source = $wc_token->get_token(); |
380 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
381 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
382 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
379 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
380 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
381 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
383 | 382 | |
384 | 383 | // This is true if the user wants to store the card to their account. |
385 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
386 | - $source = $customer->add_source( $stripe_token ); |
|
384 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
385 | + $source = $customer->add_source($stripe_token); |
|
387 | 386 | |
388 | - if ( ! empty( $source->error ) ) { |
|
389 | - throw new Exception( $source->error->message ); |
|
387 | + if ( ! empty($source->error)) { |
|
388 | + throw new Exception($source->error->message); |
|
390 | 389 | } |
391 | 390 | } else { |
392 | 391 | $set_customer = false; |
@@ -394,7 +393,7 @@ discard block |
||
394 | 393 | } |
395 | 394 | } |
396 | 395 | |
397 | - if ( ! $set_customer ) { |
|
396 | + if ( ! $set_customer) { |
|
398 | 397 | $customer_id = false; |
399 | 398 | } else { |
400 | 399 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -415,27 +414,27 @@ discard block |
||
415 | 414 | * @param WC_Order $order For to which the source applies. |
416 | 415 | * @param stdClass $source Source information. |
417 | 416 | */ |
418 | - public function save_source( $order, $source ) { |
|
417 | + public function save_source($order, $source) { |
|
419 | 418 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
420 | 419 | |
421 | 420 | // Store source in the order. |
422 | - if ( $source->customer ) { |
|
423 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
424 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
421 | + if ($source->customer) { |
|
422 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
423 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
425 | 424 | } else { |
426 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
425 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
427 | 426 | } |
428 | 427 | } |
429 | 428 | |
430 | - if ( $source->source ) { |
|
431 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
432 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
429 | + if ($source->source) { |
|
430 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
431 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
433 | 432 | } else { |
434 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
433 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
435 | 434 | } |
436 | 435 | } |
437 | 436 | |
438 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
437 | + if (is_callable(array($order, 'save'))) { |
|
439 | 438 | $order->save(); |
440 | 439 | } |
441 | 440 | } |
@@ -453,35 +452,35 @@ discard block |
||
453 | 452 | * @param object $order |
454 | 453 | * @return object |
455 | 454 | */ |
456 | - public function prepare_order_source( $order = null ) { |
|
455 | + public function prepare_order_source($order = null) { |
|
457 | 456 | $stripe_customer = new WC_Stripe_Customer(); |
458 | 457 | $stripe_source = false; |
459 | 458 | $token_id = false; |
460 | 459 | |
461 | - if ( $order ) { |
|
460 | + if ($order) { |
|
462 | 461 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
463 | 462 | |
464 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
463 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
465 | 464 | |
466 | - if ( $stripe_customer_id ) { |
|
467 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
465 | + if ($stripe_customer_id) { |
|
466 | + $stripe_customer->set_id($stripe_customer_id); |
|
468 | 467 | } |
469 | 468 | |
470 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
469 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
471 | 470 | |
472 | 471 | // Since 4.0.0, we changed card to source so we need to account for that. |
473 | - if ( empty( $source_id ) ) { |
|
474 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
472 | + if (empty($source_id)) { |
|
473 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
475 | 474 | |
476 | 475 | // Take this opportunity to update the key name. |
477 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
476 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
478 | 477 | |
479 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
478 | + if (is_callable(array($order, 'save'))) { |
|
480 | 479 | $order->save(); |
481 | 480 | } |
482 | 481 | } |
483 | 482 | |
484 | - if ( $source_id ) { |
|
483 | + if ($source_id) { |
|
485 | 484 | $stripe_source = $source_id; |
486 | 485 | } |
487 | 486 | } |
@@ -502,27 +501,27 @@ discard block |
||
502 | 501 | * @param object $order The order object |
503 | 502 | * @param int $balance_transaction_id |
504 | 503 | */ |
505 | - public function update_fees( $order, $balance_transaction_id ) { |
|
504 | + public function update_fees($order, $balance_transaction_id) { |
|
506 | 505 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
507 | 506 | |
508 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
507 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
509 | 508 | |
510 | - if ( empty( $balance_transaction->error ) ) { |
|
511 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
509 | + if (empty($balance_transaction->error)) { |
|
510 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
512 | 511 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
513 | 512 | // values are in the local currency of the Stripe account, not from WC. |
514 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
515 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
513 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
514 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
516 | 515 | |
517 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
518 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
516 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
517 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
519 | 518 | |
520 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
519 | + if (is_callable(array($order, 'save'))) { |
|
521 | 520 | $order->save(); |
522 | 521 | } |
523 | 522 | } |
524 | 523 | } else { |
525 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
524 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
526 | 525 | } |
527 | 526 | } |
528 | 527 | |
@@ -535,53 +534,53 @@ discard block |
||
535 | 534 | * @param float $amount |
536 | 535 | * @return bool |
537 | 536 | */ |
538 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
539 | - $order = wc_get_order( $order_id ); |
|
537 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
538 | + $order = wc_get_order($order_id); |
|
540 | 539 | |
541 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
540 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
542 | 541 | return false; |
543 | 542 | } |
544 | 543 | |
545 | 544 | $body = array(); |
546 | 545 | |
547 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
548 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
546 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
547 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
549 | 548 | } else { |
550 | 549 | $order_currency = $order->get_currency(); |
551 | 550 | } |
552 | 551 | |
553 | - if ( ! is_null( $amount ) ) { |
|
554 | - $body['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
552 | + if ( ! is_null($amount)) { |
|
553 | + $body['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
555 | 554 | } |
556 | 555 | |
557 | - if ( $reason ) { |
|
556 | + if ($reason) { |
|
558 | 557 | $body['metadata'] = array( |
559 | 558 | 'reason' => $reason, |
560 | 559 | ); |
561 | 560 | } |
562 | 561 | |
563 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
562 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
564 | 563 | |
565 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
564 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
566 | 565 | |
567 | - if ( ! empty( $response->error ) ) { |
|
568 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
566 | + if ( ! empty($response->error)) { |
|
567 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
569 | 568 | return $response; |
570 | - } elseif ( ! empty( $response->id ) ) { |
|
571 | - $amount = wc_price( $response->amount / 100 ); |
|
569 | + } elseif ( ! empty($response->id)) { |
|
570 | + $amount = wc_price($response->amount / 100); |
|
572 | 571 | |
573 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
574 | - $amount = wc_price( $response->amount ); |
|
572 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
573 | + $amount = wc_price($response->amount); |
|
575 | 574 | } |
576 | 575 | |
577 | - if ( isset( $response->balance_transaction ) ) { |
|
578 | - $this->update_fees( $order, $response->balance_transaction ); |
|
576 | + if (isset($response->balance_transaction)) { |
|
577 | + $this->update_fees($order, $response->balance_transaction); |
|
579 | 578 | } |
580 | 579 | |
581 | 580 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
582 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ); |
|
583 | - $order->add_order_note( $refund_message ); |
|
584 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
581 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason); |
|
582 | + $order->add_order_note($refund_message); |
|
583 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
585 | 584 | |
586 | 585 | return true; |
587 | 586 | } |
@@ -596,41 +595,41 @@ discard block |
||
596 | 595 | */ |
597 | 596 | public function add_payment_method() { |
598 | 597 | $error = false; |
599 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
598 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
600 | 599 | $source_id = ''; |
601 | 600 | |
602 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
601 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
603 | 602 | $error = true; |
604 | 603 | } |
605 | 604 | |
606 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
605 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
607 | 606 | |
608 | - if ( isset( $_POST['stripe_source'] ) ) { |
|
609 | - $source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ); |
|
607 | + if (isset($_POST['stripe_source'])) { |
|
608 | + $source = json_decode(wc_clean(stripslashes($_POST['stripe_source']))); |
|
610 | 609 | |
611 | - if ( ! empty( $source->error ) ) { |
|
610 | + if ( ! empty($source->error)) { |
|
612 | 611 | $error = true; |
613 | 612 | } |
614 | 613 | |
615 | 614 | $source_id = $source->id; |
616 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
617 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
615 | + } elseif (isset($_POST['stripe_token'])) { |
|
616 | + $source_id = wc_clean($_POST['stripe_token']); |
|
618 | 617 | } |
619 | 618 | |
620 | - $response = $stripe_customer->add_source( $source_id ); |
|
619 | + $response = $stripe_customer->add_source($source_id); |
|
621 | 620 | |
622 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
621 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
623 | 622 | $error = true; |
624 | 623 | } |
625 | 624 | |
626 | - if ( $error ) { |
|
627 | - wc_add_notice( $error_msg, 'error' ); |
|
625 | + if ($error) { |
|
626 | + wc_add_notice($error_msg, 'error'); |
|
628 | 627 | return; |
629 | 628 | } |
630 | 629 | |
631 | 630 | return array( |
632 | 631 | 'result' => 'success', |
633 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
632 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
634 | 633 | ); |
635 | 634 | } |
636 | 635 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | * @param int $user_id The WP user ID |
34 | 34 | */ |
35 | - public function __construct( $user_id = 0 ) { |
|
36 | - if ( $user_id ) { |
|
37 | - $this->set_user_id( $user_id ); |
|
38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
35 | + public function __construct($user_id = 0) { |
|
36 | + if ($user_id) { |
|
37 | + $this->set_user_id($user_id); |
|
38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
55 | - $this->id = wc_clean( $id ); |
|
54 | + public function set_id($id) { |
|
55 | + $this->id = wc_clean($id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | */ |
62 | 62 | public function get_user_id() { |
63 | - return absint( $this->user_id ); |
|
63 | + return absint($this->user_id); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Set User ID used by WordPress. |
68 | 68 | * @param int $user_id |
69 | 69 | */ |
70 | - public function set_user_id( $user_id ) { |
|
71 | - $this->user_id = absint( $user_id ); |
|
70 | + public function set_user_id($user_id) { |
|
71 | + $this->user_id = absint($user_id); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | * @return WP_User |
77 | 77 | */ |
78 | 78 | protected function get_user() { |
79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Store data from the Stripe API about this customer |
84 | 84 | */ |
85 | - public function set_customer_data( $data ) { |
|
85 | + public function set_customer_data($data) { |
|
86 | 86 | $this->customer_data = $data; |
87 | 87 | } |
88 | 88 | |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | * Get data from the Stripe API about this customer |
91 | 91 | */ |
92 | 92 | public function get_customer_data() { |
93 | - $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ); |
|
93 | + $this->customer_data = get_transient('stripe_customer_' . $this->get_id()); |
|
94 | 94 | |
95 | - if ( empty( $this->customer_data ) && $this->get_id() && false === $this->customer_data ) { |
|
96 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() ); |
|
95 | + if (empty($this->customer_data) && $this->get_id() && false === $this->customer_data) { |
|
96 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id()); |
|
97 | 97 | |
98 | - if ( empty( $response->error ) ) { |
|
99 | - $this->set_customer_data( $response ); |
|
100 | - set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 ); |
|
98 | + if (empty($response->error)) { |
|
99 | + $this->set_customer_data($response); |
|
100 | + set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $data = $this->get_customer_data(); |
113 | 113 | $source = ''; |
114 | 114 | |
115 | - if ( $data ) { |
|
115 | + if ($data) { |
|
116 | 116 | $source = $data->default_source; |
117 | 117 | } |
118 | 118 | |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | * @param array $args |
125 | 125 | * @return WP_Error|int |
126 | 126 | */ |
127 | - public function create_customer( $args = array() ) { |
|
128 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
127 | + public function create_customer($args = array()) { |
|
128 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
129 | 129 | $user = $this->get_user(); |
130 | 130 | |
131 | - if ( $user ) { |
|
132 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
133 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
131 | + if ($user) { |
|
132 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
133 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
134 | 134 | |
135 | 135 | $defaults = array( |
136 | 136 | 'email' => $user->user_email, |
@@ -145,24 +145,24 @@ discard block |
||
145 | 145 | |
146 | 146 | $metadata = array(); |
147 | 147 | |
148 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
148 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
149 | 149 | |
150 | - $args = wp_parse_args( $args, $defaults ); |
|
151 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
150 | + $args = wp_parse_args($args, $defaults); |
|
151 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
152 | 152 | |
153 | - if ( ! empty( $response->error ) ) { |
|
154 | - throw new Exception( $response->error->message ); |
|
153 | + if ( ! empty($response->error)) { |
|
154 | + throw new Exception($response->error->message); |
|
155 | 155 | } |
156 | 156 | |
157 | - $this->set_id( $response->id ); |
|
157 | + $this->set_id($response->id); |
|
158 | 158 | $this->clear_cache(); |
159 | - $this->set_customer_data( $response ); |
|
159 | + $this->set_customer_data($response); |
|
160 | 160 | |
161 | - if ( $this->get_user_id() ) { |
|
162 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
161 | + if ($this->get_user_id()) { |
|
162 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
163 | 163 | } |
164 | 164 | |
165 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
165 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
166 | 166 | |
167 | 167 | return $response->id; |
168 | 168 | } |
@@ -173,72 +173,72 @@ discard block |
||
173 | 173 | * @param bool $retry |
174 | 174 | * @return WP_Error|int |
175 | 175 | */ |
176 | - public function add_source( $source_id, $retry = true ) { |
|
177 | - if ( ! $this->get_id() ) { |
|
176 | + public function add_source($source_id, $retry = true) { |
|
177 | + if ( ! $this->get_id()) { |
|
178 | 178 | $this->create_customer(); |
179 | 179 | } |
180 | 180 | |
181 | - $response = WC_Stripe_API::request( array( |
|
181 | + $response = WC_Stripe_API::request(array( |
|
182 | 182 | 'source' => $source_id, |
183 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
183 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
184 | 184 | |
185 | - if ( ! empty( $response->error ) ) { |
|
185 | + if ( ! empty($response->error)) { |
|
186 | 186 | // It is possible the WC user once was linked to a customer on Stripe |
187 | 187 | // but no longer exists. Instead of failing, lets try to create a |
188 | 188 | // new customer. |
189 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
190 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
189 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
190 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
191 | 191 | $this->create_customer(); |
192 | - return $this->add_source( $source_id, false ); |
|
192 | + return $this->add_source($source_id, false); |
|
193 | 193 | } else { |
194 | 194 | return $response; |
195 | 195 | } |
196 | - } elseif ( empty( $response->id ) ) { |
|
197 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
196 | + } elseif (empty($response->id)) { |
|
197 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | // Add token to WooCommerce. |
201 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
202 | - if ( ! empty( $response->type ) ) { |
|
203 | - switch ( $response->type ) { |
|
201 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
202 | + if ( ! empty($response->type)) { |
|
203 | + switch ($response->type) { |
|
204 | 204 | case 'alipay': |
205 | 205 | break; |
206 | 206 | case 'sepa_debit': |
207 | 207 | $wc_token = new WC_Payment_Token_SEPA(); |
208 | - $wc_token->set_token( $response->id ); |
|
209 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
210 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
208 | + $wc_token->set_token($response->id); |
|
209 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
210 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
211 | 211 | break; |
212 | 212 | default: |
213 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
213 | + if ('source' === $response->object && 'card' === $response->type) { |
|
214 | 214 | $wc_token = new WC_Payment_Token_CC(); |
215 | - $wc_token->set_token( $response->id ); |
|
216 | - $wc_token->set_gateway_id( 'stripe' ); |
|
217 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
218 | - $wc_token->set_last4( $response->card->last4 ); |
|
219 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
220 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
215 | + $wc_token->set_token($response->id); |
|
216 | + $wc_token->set_gateway_id('stripe'); |
|
217 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
218 | + $wc_token->set_last4($response->card->last4); |
|
219 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
220 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
221 | 221 | } |
222 | 222 | break; |
223 | 223 | } |
224 | 224 | } else { |
225 | 225 | // Legacy. |
226 | 226 | $wc_token = new WC_Payment_Token_CC(); |
227 | - $wc_token->set_token( $response->id ); |
|
228 | - $wc_token->set_gateway_id( 'stripe' ); |
|
229 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
230 | - $wc_token->set_last4( $response->last4 ); |
|
231 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
232 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
227 | + $wc_token->set_token($response->id); |
|
228 | + $wc_token->set_gateway_id('stripe'); |
|
229 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
230 | + $wc_token->set_last4($response->last4); |
|
231 | + $wc_token->set_expiry_month($response->exp_month); |
|
232 | + $wc_token->set_expiry_year($response->exp_year); |
|
233 | 233 | } |
234 | 234 | |
235 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
235 | + $wc_token->set_user_id($this->get_user_id()); |
|
236 | 236 | $wc_token->save(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $this->clear_cache(); |
240 | 240 | |
241 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
241 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
242 | 242 | |
243 | 243 | return $response->id; |
244 | 244 | } |
@@ -250,38 +250,38 @@ discard block |
||
250 | 250 | * @return array |
251 | 251 | */ |
252 | 252 | public function get_sources() { |
253 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
253 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
254 | 254 | |
255 | - if ( false === $sources ) { |
|
256 | - $response = WC_Stripe_API::request( array( |
|
255 | + if (false === $sources) { |
|
256 | + $response = WC_Stripe_API::request(array( |
|
257 | 257 | 'limit' => 100, |
258 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
258 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
259 | 259 | |
260 | - if ( ! empty( $response->error ) ) { |
|
260 | + if ( ! empty($response->error)) { |
|
261 | 261 | return array(); |
262 | 262 | } |
263 | 263 | |
264 | - if ( is_array( $response->data ) ) { |
|
264 | + if (is_array($response->data)) { |
|
265 | 265 | $sources = $response->data; |
266 | 266 | } |
267 | 267 | |
268 | - set_transient( 'stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24 ); |
|
268 | + set_transient('stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24); |
|
269 | 269 | } |
270 | 270 | |
271 | - return empty( $sources ) ? array() : $sources; |
|
271 | + return empty($sources) ? array() : $sources; |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | 275 | * Delete a source from stripe. |
276 | 276 | * @param string $source_id |
277 | 277 | */ |
278 | - public function delete_source( $source_id ) { |
|
279 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
278 | + public function delete_source($source_id) { |
|
279 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
280 | 280 | |
281 | 281 | $this->clear_cache(); |
282 | 282 | |
283 | - if ( empty( $response->error ) ) { |
|
284 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
283 | + if (empty($response->error)) { |
|
284 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
285 | 285 | |
286 | 286 | return true; |
287 | 287 | } |
@@ -293,15 +293,15 @@ discard block |
||
293 | 293 | * Set default source in Stripe |
294 | 294 | * @param string $source_id |
295 | 295 | */ |
296 | - public function set_default_source( $source_id ) { |
|
297 | - $response = WC_Stripe_API::request( array( |
|
298 | - 'default_source' => sanitize_text_field( $source_id ), |
|
299 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
296 | + public function set_default_source($source_id) { |
|
297 | + $response = WC_Stripe_API::request(array( |
|
298 | + 'default_source' => sanitize_text_field($source_id), |
|
299 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
300 | 300 | |
301 | 301 | $this->clear_cache(); |
302 | 302 | |
303 | - if ( empty( $response->error ) ) { |
|
304 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
303 | + if (empty($response->error)) { |
|
304 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
305 | 305 | |
306 | 306 | return true; |
307 | 307 | } |
@@ -313,8 +313,8 @@ discard block |
||
313 | 313 | * Deletes caches for this users cards. |
314 | 314 | */ |
315 | 315 | public function clear_cache() { |
316 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
317 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
316 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
317 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
318 | 318 | $this->customer_data = array(); |
319 | 319 | } |
320 | 320 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * Set secret API Key. |
27 | 27 | * @param string $key |
28 | 28 | */ |
29 | - public static function set_secret_key( $secret_key ) { |
|
29 | + public static function set_secret_key($secret_key) { |
|
30 | 30 | self::$secret_key = $secret_key; |
31 | 31 | } |
32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * @return string |
36 | 36 | */ |
37 | 37 | public static function get_secret_key() { |
38 | - if ( ! self::$secret_key ) { |
|
39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
38 | + if ( ! self::$secret_key) { |
|
39 | + $options = get_option('woocommerce_stripe_settings'); |
|
40 | 40 | |
41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | return self::$secret_key; |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $user_agent = self::get_user_agent(); |
79 | 79 | $app_info = $user_agent['application']; |
80 | 80 | |
81 | - return apply_filters( 'woocommerce_stripe_request_headers', array( |
|
82 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
81 | + return apply_filters('woocommerce_stripe_request_headers', array( |
|
82 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
83 | 83 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
84 | 84 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
85 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
86 | - ) ); |
|
85 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
86 | + )); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | * @param string $api |
96 | 96 | * @return array|WP_Error |
97 | 97 | */ |
98 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
99 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
98 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
99 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
100 | 100 | |
101 | 101 | $headers = self::get_headers(); |
102 | 102 | |
103 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
104 | - $headers['Idempotency-Key'] = uniqid( 'stripe_' ); |
|
103 | + if ('charges' === $api && 'POST' === $method) { |
|
104 | + $headers['Idempotency-Key'] = uniqid('stripe_'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | $response = wp_safe_remote_post( |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | array( |
110 | 110 | 'method' => $method, |
111 | 111 | 'headers' => $headers, |
112 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
112 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
113 | 113 | 'timeout' => 70, |
114 | 114 | ) |
115 | 115 | ); |
116 | 116 | |
117 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
118 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
119 | - throw new Exception( __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
117 | + if (is_wp_error($response) || empty($response['body'])) { |
|
118 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
119 | + throw new Exception(__('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
120 | 120 | } |
121 | 121 | |
122 | - return json_decode( $response['body'] ); |
|
122 | + return json_decode($response['body']); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @version 4.0.0 |
130 | 130 | * @param string $api |
131 | 131 | */ |
132 | - public static function retrieve( $api ) { |
|
133 | - WC_Stripe_Logger::log( "{$api}" ); |
|
132 | + public static function retrieve($api) { |
|
133 | + WC_Stripe_Logger::log("{$api}"); |
|
134 | 134 | |
135 | 135 | $ua = self::get_user_agent(); |
136 | 136 | |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | |
146 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
147 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
148 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
146 | + if (is_wp_error($response) || empty($response['body'])) { |
|
147 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
148 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
149 | 149 | } |
150 | 150 | |
151 | - return json_decode( $response['body'] ); |
|
151 | + return json_decode($response['body']); |
|
152 | 152 | } |
153 | 153 | } |