@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | public function __construct() { |
86 | 86 | $this->retry_interval = 1; |
87 | 87 | $this->id = 'stripe'; |
88 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
88 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
89 | 89 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
90 | - $this->method_description = __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
90 | + $this->method_description = __('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
91 | 91 | $this->has_fields = true; |
92 | 92 | $this->supports = array( |
93 | 93 | 'products', |
@@ -114,41 +114,41 @@ discard block |
||
114 | 114 | $this->init_settings(); |
115 | 115 | |
116 | 116 | // Get setting values. |
117 | - $this->title = $this->get_option( 'title' ); |
|
118 | - $this->description = $this->get_option( 'description' ); |
|
119 | - $this->enabled = $this->get_option( 'enabled' ); |
|
120 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
121 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
122 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
123 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
124 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
125 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
126 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
127 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
128 | - |
|
129 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
117 | + $this->title = $this->get_option('title'); |
|
118 | + $this->description = $this->get_option('description'); |
|
119 | + $this->enabled = $this->get_option('enabled'); |
|
120 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
121 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
122 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
123 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
124 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
125 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
126 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
127 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
128 | + |
|
129 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
130 | 130 | |
131 | 131 | // Hooks. |
132 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
133 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
134 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
135 | - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ) ); |
|
136 | - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_payout' ), 20 ); |
|
137 | - add_action( 'woocommerce_customer_save_address', array( $this, 'show_update_card_notice' ), 10, 2 ); |
|
138 | - add_filter( 'woocommerce_available_payment_gateways', array( $this, 'prepare_order_pay_page' ) ); |
|
139 | - add_action( 'woocommerce_account_view-order_endpoint', array( $this, 'check_intent_status_on_order_page' ), 1 ); |
|
140 | - add_filter( 'woocommerce_payment_successful_result', array( $this, 'modify_successful_payment_result' ), 99999, 2 ); |
|
141 | - add_action( 'set_logged_in_cookie', array( $this, 'set_cookie_on_current_request' ) ); |
|
142 | - add_filter( 'woocommerce_get_checkout_payment_url', array( $this, 'get_checkout_payment_url' ), 10, 2 ); |
|
143 | - add_filter( 'woocommerce_settings_api_sanitized_fields_' . $this->id, array( $this, 'settings_api_sanitized_fields' ) ); |
|
132 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
133 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
134 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
135 | + add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_fee')); |
|
136 | + add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_payout'), 20); |
|
137 | + add_action('woocommerce_customer_save_address', array($this, 'show_update_card_notice'), 10, 2); |
|
138 | + add_filter('woocommerce_available_payment_gateways', array($this, 'prepare_order_pay_page')); |
|
139 | + add_action('woocommerce_account_view-order_endpoint', array($this, 'check_intent_status_on_order_page'), 1); |
|
140 | + add_filter('woocommerce_payment_successful_result', array($this, 'modify_successful_payment_result'), 99999, 2); |
|
141 | + add_action('set_logged_in_cookie', array($this, 'set_cookie_on_current_request')); |
|
142 | + add_filter('woocommerce_get_checkout_payment_url', array($this, 'get_checkout_payment_url'), 10, 2); |
|
143 | + add_filter('woocommerce_settings_api_sanitized_fields_' . $this->id, array($this, 'settings_api_sanitized_fields')); |
|
144 | 144 | |
145 | 145 | // Note: display error is in the parent class. |
146 | - add_action( 'admin_notices', array( $this, 'display_errors' ), 9999 ); |
|
146 | + add_action('admin_notices', array($this, 'display_errors'), 9999); |
|
147 | 147 | |
148 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
148 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
149 | 149 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
150 | 150 | |
151 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
151 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @since 4.0.2 |
159 | 159 | */ |
160 | 160 | public function is_available() { |
161 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
161 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
162 | 162 | return false; |
163 | 163 | } |
164 | 164 | |
@@ -172,13 +172,13 @@ discard block |
||
172 | 172 | * @param int $user_id The ID of the current user. |
173 | 173 | * @param string $load_address The address to load. |
174 | 174 | */ |
175 | - public function show_update_card_notice( $user_id, $load_address ) { |
|
176 | - if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) { |
|
175 | + public function show_update_card_notice($user_id, $load_address) { |
|
176 | + if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | 180 | /* translators: 1) Opening anchor tag 2) closing anchor tag */ |
181 | - wc_add_notice( sprintf( __( 'If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe' ), '<a href="' . esc_url( wc_get_endpoint_url( 'payment-methods' ) ) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>' ), 'notice' ); |
|
181 | + wc_add_notice(sprintf(__('If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe'), '<a href="' . esc_url(wc_get_endpoint_url('payment-methods')) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>'), 'notice'); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -193,24 +193,24 @@ discard block |
||
193 | 193 | |
194 | 194 | $icons_str = ''; |
195 | 195 | |
196 | - $icons_str .= isset( $icons['visa'] ) ? $icons['visa'] : ''; |
|
197 | - $icons_str .= isset( $icons['amex'] ) ? $icons['amex'] : ''; |
|
198 | - $icons_str .= isset( $icons['mastercard'] ) ? $icons['mastercard'] : ''; |
|
196 | + $icons_str .= isset($icons['visa']) ? $icons['visa'] : ''; |
|
197 | + $icons_str .= isset($icons['amex']) ? $icons['amex'] : ''; |
|
198 | + $icons_str .= isset($icons['mastercard']) ? $icons['mastercard'] : ''; |
|
199 | 199 | |
200 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
201 | - $icons_str .= isset( $icons['discover'] ) ? $icons['discover'] : ''; |
|
202 | - $icons_str .= isset( $icons['jcb'] ) ? $icons['jcb'] : ''; |
|
203 | - $icons_str .= isset( $icons['diners'] ) ? $icons['diners'] : ''; |
|
200 | + if ('USD' === get_woocommerce_currency()) { |
|
201 | + $icons_str .= isset($icons['discover']) ? $icons['discover'] : ''; |
|
202 | + $icons_str .= isset($icons['jcb']) ? $icons['jcb'] : ''; |
|
203 | + $icons_str .= isset($icons['diners']) ? $icons['diners'] : ''; |
|
204 | 204 | } |
205 | 205 | |
206 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
206 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | 210 | * Initialise Gateway Settings Form Fields |
211 | 211 | */ |
212 | 212 | public function init_form_fields() { |
213 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
213 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -219,27 +219,27 @@ discard block |
||
219 | 219 | public function payment_fields() { |
220 | 220 | global $wp; |
221 | 221 | $user = wp_get_current_user(); |
222 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
222 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
223 | 223 | $total = WC()->cart->total; |
224 | 224 | $user_email = ''; |
225 | 225 | $description = $this->get_description(); |
226 | - $description = ! empty( $description ) ? $description : ''; |
|
226 | + $description = ! empty($description) ? $description : ''; |
|
227 | 227 | $firstname = ''; |
228 | 228 | $lastname = ''; |
229 | 229 | |
230 | 230 | // If paying from order, we need to get total from order not cart. |
231 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { // wpcs: csrf ok. |
|
232 | - $order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) ); // wpcs: csrf ok, sanitization ok. |
|
231 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { // wpcs: csrf ok. |
|
232 | + $order = wc_get_order(wc_clean($wp->query_vars['order-pay'])); // wpcs: csrf ok, sanitization ok. |
|
233 | 233 | $total = $order->get_total(); |
234 | 234 | $user_email = $order->get_billing_email(); |
235 | 235 | } else { |
236 | - if ( $user->ID ) { |
|
237 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
236 | + if ($user->ID) { |
|
237 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
238 | 238 | $user_email = $user_email ? $user_email : $user->user_email; |
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
242 | - if ( is_add_payment_method_page() ) { |
|
242 | + if (is_add_payment_method_page()) { |
|
243 | 243 | $firstname = $user->user_firstname; |
244 | 244 | $lastname = $user->user_lastname; |
245 | 245 | } |
@@ -248,33 +248,33 @@ discard block |
||
248 | 248 | |
249 | 249 | echo '<div |
250 | 250 | id="stripe-payment-data" |
251 | - data-email="' . esc_attr( $user_email ) . '" |
|
252 | - data-full-name="' . esc_attr( $firstname . ' ' . $lastname ) . '" |
|
253 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
251 | + data-email="' . esc_attr($user_email) . '" |
|
252 | + data-full-name="' . esc_attr($firstname . ' ' . $lastname) . '" |
|
253 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
254 | 254 | >'; |
255 | 255 | |
256 | - if ( $this->testmode ) { |
|
256 | + if ($this->testmode) { |
|
257 | 257 | /* translators: link to Stripe testing page */ |
258 | - $description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
258 | + $description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
259 | 259 | } |
260 | 260 | |
261 | - $description = trim( $description ); |
|
261 | + $description = trim($description); |
|
262 | 262 | |
263 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); // wpcs: xss ok. |
|
263 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); // wpcs: xss ok. |
|
264 | 264 | |
265 | - if ( $display_tokenization ) { |
|
265 | + if ($display_tokenization) { |
|
266 | 266 | $this->tokenization_script(); |
267 | 267 | $this->saved_payment_methods(); |
268 | 268 | } |
269 | 269 | |
270 | 270 | $this->elements_form(); |
271 | 271 | |
272 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { // wpcs: csrf ok. |
|
272 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { // wpcs: csrf ok. |
|
273 | 273 | |
274 | 274 | $this->save_payment_method_checkbox(); |
275 | 275 | } |
276 | 276 | |
277 | - do_action( 'wc_stripe_cards_payment_fields', $this->id ); |
|
277 | + do_action('wc_stripe_cards_payment_fields', $this->id); |
|
278 | 278 | |
279 | 279 | echo '</div>'; |
280 | 280 | |
@@ -289,12 +289,12 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function elements_form() { |
291 | 291 | ?> |
292 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
293 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
292 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
293 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
294 | 294 | |
295 | - <?php if ( $this->inline_cc_form ) { ?> |
|
295 | + <?php if ($this->inline_cc_form) { ?> |
|
296 | 296 | <label for="card-element"> |
297 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
297 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
298 | 298 | </label> |
299 | 299 | |
300 | 300 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | </div> |
303 | 303 | <?php } else { ?> |
304 | 304 | <div class="form-row form-row-wide"> |
305 | - <label for="stripe-card-element"><?php esc_html_e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
305 | + <label for="stripe-card-element"><?php esc_html_e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
306 | 306 | <div class="stripe-card-group"> |
307 | 307 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
308 | 308 | <!-- a Stripe Element will be inserted here. --> |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | </div> |
314 | 314 | |
315 | 315 | <div class="form-row form-row-first"> |
316 | - <label for="stripe-exp-element"><?php esc_html_e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
316 | + <label for="stripe-exp-element"><?php esc_html_e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
317 | 317 | |
318 | 318 | <div id="stripe-exp-element" class="wc-stripe-elements-field"> |
319 | 319 | <!-- a Stripe Element will be inserted here. --> |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | </div> |
322 | 322 | |
323 | 323 | <div class="form-row form-row-last"> |
324 | - <label for="stripe-cvc-element"><?php esc_html_e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
324 | + <label for="stripe-cvc-element"><?php esc_html_e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
325 | 325 | <div id="stripe-cvc-element" class="wc-stripe-elements-field"> |
326 | 326 | <!-- a Stripe Element will be inserted here. --> |
327 | 327 | </div> |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | <!-- Used to display form errors --> |
333 | 333 | <div class="stripe-source-errors" role="alert"></div> |
334 | 334 | <br /> |
335 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
335 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
336 | 336 | <div class="clear"></div> |
337 | 337 | </fieldset> |
338 | 338 | <?php |
@@ -345,24 +345,24 @@ discard block |
||
345 | 345 | * @version 3.1.0 |
346 | 346 | */ |
347 | 347 | public function admin_scripts() { |
348 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
348 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
349 | 349 | return; |
350 | 350 | } |
351 | 351 | |
352 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
352 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
353 | 353 | |
354 | - wp_register_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
354 | + wp_register_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
355 | 355 | |
356 | 356 | $params = array( |
357 | 357 | 'time' => time(), |
358 | 358 | 'i18n_out_of_sync' => wp_kses( |
359 | - __( '<strong>Warning:</strong> your site\'s time does not match the time on your browser and may be incorrect. Some payment methods depend on webhook verification and verifying webhooks with a signing secret depends on your site\'s time being correct, so please check your site\'s time before setting a webhook secret. You may need to contact your site\'s hosting provider to correct the site\'s time.', 'woocommerce-gateway-stripe' ), |
|
360 | - array( 'strong' => array() ) |
|
359 | + __('<strong>Warning:</strong> your site\'s time does not match the time on your browser and may be incorrect. Some payment methods depend on webhook verification and verifying webhooks with a signing secret depends on your site\'s time being correct, so please check your site\'s time before setting a webhook secret. You may need to contact your site\'s hosting provider to correct the site\'s time.', 'woocommerce-gateway-stripe'), |
|
360 | + array('strong' => array()) |
|
361 | 361 | ), |
362 | 362 | ); |
363 | - wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_settings_params', $params ); |
|
363 | + wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_settings_params', $params); |
|
364 | 364 | |
365 | - wp_enqueue_script( 'woocommerce_stripe_admin' ); |
|
365 | + wp_enqueue_script('woocommerce_stripe_admin'); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -379,54 +379,54 @@ discard block |
||
379 | 379 | ! is_product() |
380 | 380 | && ! is_cart() |
381 | 381 | && ! is_checkout() |
382 | - && ! isset( $_GET['pay_for_order'] ) // wpcs: csrf ok. |
|
382 | + && ! isset($_GET['pay_for_order']) // wpcs: csrf ok. |
|
383 | 383 | && ! is_add_payment_method_page() |
384 | - && ! isset( $_GET['change_payment_method'] ) // wpcs: csrf ok. |
|
385 | - && ! ( ! empty( get_query_var( 'view-subscription' ) ) && is_callable( 'WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled' ) && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled() ) |
|
386 | - || ( is_order_received_page() ) |
|
384 | + && ! isset($_GET['change_payment_method']) // wpcs: csrf ok. |
|
385 | + && ! ( ! empty(get_query_var('view-subscription')) && is_callable('WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled') && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled()) |
|
386 | + || (is_order_received_page()) |
|
387 | 387 | ) { |
388 | 388 | return; |
389 | 389 | } |
390 | 390 | |
391 | 391 | // If Stripe is not enabled bail. |
392 | - if ( 'no' === $this->enabled ) { |
|
392 | + if ('no' === $this->enabled) { |
|
393 | 393 | return; |
394 | 394 | } |
395 | 395 | |
396 | 396 | // If keys are not set bail. |
397 | - if ( ! $this->are_keys_set() ) { |
|
398 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
397 | + if ( ! $this->are_keys_set()) { |
|
398 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
399 | 399 | return; |
400 | 400 | } |
401 | 401 | |
402 | 402 | // If no SSL bail. |
403 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
404 | - WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' ); |
|
403 | + if ( ! $this->testmode && ! is_ssl()) { |
|
404 | + WC_Stripe_Logger::log('Stripe live mode requires SSL.'); |
|
405 | 405 | return; |
406 | 406 | } |
407 | 407 | |
408 | 408 | $current_theme = wp_get_theme(); |
409 | 409 | |
410 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
410 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
411 | 411 | |
412 | - wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
413 | - wp_enqueue_style( 'stripe_styles' ); |
|
412 | + wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
413 | + wp_enqueue_style('stripe_styles'); |
|
414 | 414 | |
415 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
416 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
415 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
416 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
417 | 417 | |
418 | 418 | $stripe_params = array( |
419 | 419 | 'key' => $this->publishable_key, |
420 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
421 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
420 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
421 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
422 | 422 | ); |
423 | 423 | |
424 | 424 | // If we're on the pay page we need to pass stripe.js the address of the order. |
425 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { // wpcs: csrf ok. |
|
426 | - $order_id = wc_clean( $wp->query_vars['order-pay'] ); // wpcs: csrf ok, sanitization ok, xss ok. |
|
427 | - $order = wc_get_order( $order_id ); |
|
425 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { // wpcs: csrf ok. |
|
426 | + $order_id = wc_clean($wp->query_vars['order-pay']); // wpcs: csrf ok, sanitization ok, xss ok. |
|
427 | + $order = wc_get_order($order_id); |
|
428 | 428 | |
429 | - if ( is_a( $order, 'WC_Order' ) ) { |
|
429 | + if (is_a($order, 'WC_Order')) { |
|
430 | 430 | $stripe_params['billing_first_name'] = $order->get_billing_first_name(); |
431 | 431 | $stripe_params['billing_last_name'] = $order->get_billing_last_name(); |
432 | 432 | $stripe_params['billing_address_1'] = $order->get_billing_address_1(); |
@@ -441,41 +441,41 @@ discard block |
||
441 | 441 | $sepa_elements_options = apply_filters( |
442 | 442 | 'wc_stripe_sepa_elements_options', |
443 | 443 | array( |
444 | - 'supportedCountries' => array( 'SEPA' ), |
|
444 | + 'supportedCountries' => array('SEPA'), |
|
445 | 445 | 'placeholderCountry' => WC()->countries->get_base_country(), |
446 | - 'style' => array( 'base' => array( 'fontSize' => '15px' ) ), |
|
446 | + 'style' => array('base' => array('fontSize' => '15px')), |
|
447 | 447 | ) |
448 | 448 | ); |
449 | 449 | |
450 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
451 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
452 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
453 | - $stripe_params['payment_intent_error'] = __( 'We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe' ); |
|
454 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
455 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
450 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
451 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
452 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
453 | + $stripe_params['payment_intent_error'] = __('We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe'); |
|
454 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
455 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
456 | 456 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
457 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
457 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
458 | 458 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
459 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
460 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
459 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
460 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
461 | 461 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
462 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
462 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
463 | 463 | $stripe_params['sepa_elements_options'] = $sepa_elements_options; |
464 | - $stripe_params['invalid_owner_name'] = __( 'Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe' ); |
|
465 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
466 | - $stripe_params['is_add_payment_page'] = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no'; |
|
467 | - $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no'; |
|
468 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
469 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
470 | - $stripe_params['add_card_nonce'] = wp_create_nonce( 'wc_stripe_create_si' ); |
|
464 | + $stripe_params['invalid_owner_name'] = __('Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe'); |
|
465 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
466 | + $stripe_params['is_add_payment_page'] = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no'; |
|
467 | + $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url('order-pay') ? 'yes' : 'no'; |
|
468 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
469 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
470 | + $stripe_params['add_card_nonce'] = wp_create_nonce('wc_stripe_create_si'); |
|
471 | 471 | |
472 | 472 | // Merge localized messages to be use in JS. |
473 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
473 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
474 | 474 | |
475 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
475 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
476 | 476 | |
477 | 477 | $this->tokenization_script(); |
478 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
478 | + wp_enqueue_script('woocommerce_stripe'); |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | /** |
@@ -486,14 +486,14 @@ discard block |
||
486 | 486 | * @param object $prepared_source The object with source details. |
487 | 487 | * @throws WC_Stripe_Exception An exception if the card is prepaid, but prepaid cards are not allowed. |
488 | 488 | */ |
489 | - public function maybe_disallow_prepaid_card( $prepared_source ) { |
|
489 | + public function maybe_disallow_prepaid_card($prepared_source) { |
|
490 | 490 | // Check if we don't allow prepaid credit cards. |
491 | - if ( apply_filters( 'wc_stripe_allow_prepaid_card', true ) || ! $this->is_prepaid_card( $prepared_source->source_object ) ) { |
|
491 | + if (apply_filters('wc_stripe_allow_prepaid_card', true) || ! $this->is_prepaid_card($prepared_source->source_object)) { |
|
492 | 492 | return; |
493 | 493 | } |
494 | 494 | |
495 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
496 | - throw new WC_Stripe_Exception( print_r( $prepared_source->source_object, true ), $localized_message ); |
|
495 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
496 | + throw new WC_Stripe_Exception(print_r($prepared_source->source_object, true), $localized_message); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -503,10 +503,10 @@ discard block |
||
503 | 503 | * @param object $prepared_source The source that should be verified. |
504 | 504 | * @throws WC_Stripe_Exception An exception if the source ID is missing. |
505 | 505 | */ |
506 | - public function check_source( $prepared_source ) { |
|
507 | - if ( empty( $prepared_source->source ) ) { |
|
508 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
509 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
506 | + public function check_source($prepared_source) { |
|
507 | + if (empty($prepared_source->source)) { |
|
508 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
509 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
@@ -518,13 +518,13 @@ discard block |
||
518 | 518 | * @param WC_Order $order The order those payment is being processed. |
519 | 519 | * @return bool A flag that indicates that the customer does not exist and should be removed. |
520 | 520 | */ |
521 | - public function maybe_remove_non_existent_customer( $error, $order ) { |
|
522 | - if ( ! $this->is_no_such_customer_error( $error ) ) { |
|
521 | + public function maybe_remove_non_existent_customer($error, $order) { |
|
522 | + if ( ! $this->is_no_such_customer_error($error)) { |
|
523 | 523 | return false; |
524 | 524 | } |
525 | 525 | |
526 | - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); |
|
527 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
526 | + delete_user_option($order->get_customer_id(), '_stripe_customer_id'); |
|
527 | + $order->delete_meta_data('_stripe_customer_id'); |
|
528 | 528 | $order->save(); |
529 | 529 | |
530 | 530 | return true; |
@@ -539,15 +539,15 @@ discard block |
||
539 | 539 | * @param boolean $force_save_source Whether the payment source must be saved, like when dealing with a Subscription setup. |
540 | 540 | * @return array Redirection data for `process_payment`. |
541 | 541 | */ |
542 | - public function complete_free_order( $order, $prepared_source, $force_save_source ) { |
|
543 | - if ( $force_save_source ) { |
|
544 | - $intent_secret = $this->setup_intent( $order, $prepared_source ); |
|
542 | + public function complete_free_order($order, $prepared_source, $force_save_source) { |
|
543 | + if ($force_save_source) { |
|
544 | + $intent_secret = $this->setup_intent($order, $prepared_source); |
|
545 | 545 | |
546 | - if ( ! empty( $intent_secret ) ) { |
|
546 | + if ( ! empty($intent_secret)) { |
|
547 | 547 | // `get_return_url()` must be called immediately before returning a value. |
548 | 548 | return array( |
549 | 549 | 'result' => 'success', |
550 | - 'redirect' => $this->get_return_url( $order ), |
|
550 | + 'redirect' => $this->get_return_url($order), |
|
551 | 551 | 'setup_intent_secret' => $intent_secret, |
552 | 552 | ); |
553 | 553 | } |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | // Return thank you page redirect. |
562 | 562 | return array( |
563 | 563 | 'result' => 'success', |
564 | - 'redirect' => $this->get_return_url( $order ), |
|
564 | + 'redirect' => $this->get_return_url($order), |
|
565 | 565 | ); |
566 | 566 | } |
567 | 567 | |
@@ -579,81 +579,81 @@ discard block |
||
579 | 579 | * @throws Exception If payment will not be accepted. |
580 | 580 | * @return array|void |
581 | 581 | */ |
582 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false ) { |
|
582 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false) { |
|
583 | 583 | try { |
584 | - $order = wc_get_order( $order_id ); |
|
584 | + $order = wc_get_order($order_id); |
|
585 | 585 | |
586 | 586 | // ToDo: `process_pre_order` saves the source to the order for a later payment. |
587 | 587 | // This might not work well with PaymentIntents. |
588 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
589 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
588 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
589 | + return $this->pre_orders->process_pre_order($order_id); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | // Check whether there is an existing intent. |
593 | - $intent = $this->get_intent_from_order( $order ); |
|
594 | - if ( isset( $intent->object ) && 'setup_intent' === $intent->object ) { |
|
593 | + $intent = $this->get_intent_from_order($order); |
|
594 | + if (isset($intent->object) && 'setup_intent' === $intent->object) { |
|
595 | 595 | $intent = false; // This function can only deal with *payment* intents |
596 | 596 | } |
597 | 597 | |
598 | 598 | $stripe_customer_id = null; |
599 | - if ( $intent && ! empty( $intent->customer ) ) { |
|
599 | + if ($intent && ! empty($intent->customer)) { |
|
600 | 600 | $stripe_customer_id = $intent->customer; |
601 | 601 | } |
602 | 602 | |
603 | 603 | // For some payments the source should already be present in the order. |
604 | - if ( $use_order_source ) { |
|
605 | - $prepared_source = $this->prepare_order_source( $order ); |
|
604 | + if ($use_order_source) { |
|
605 | + $prepared_source = $this->prepare_order_source($order); |
|
606 | 606 | } else { |
607 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source, $stripe_customer_id ); |
|
607 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source, $stripe_customer_id); |
|
608 | 608 | } |
609 | 609 | |
610 | - $this->maybe_disallow_prepaid_card( $prepared_source ); |
|
611 | - $this->check_source( $prepared_source ); |
|
612 | - $this->save_source_to_order( $order, $prepared_source ); |
|
610 | + $this->maybe_disallow_prepaid_card($prepared_source); |
|
611 | + $this->check_source($prepared_source); |
|
612 | + $this->save_source_to_order($order, $prepared_source); |
|
613 | 613 | |
614 | - if ( 0 >= $order->get_total() ) { |
|
615 | - return $this->complete_free_order( $order, $prepared_source, $force_save_source ); |
|
614 | + if (0 >= $order->get_total()) { |
|
615 | + return $this->complete_free_order($order, $prepared_source, $force_save_source); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | // This will throw exception if not valid. |
619 | - $this->validate_minimum_order_amount( $order ); |
|
619 | + $this->validate_minimum_order_amount($order); |
|
620 | 620 | |
621 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
621 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
622 | 622 | |
623 | - if ( $intent ) { |
|
624 | - $intent = $this->update_existing_intent( $intent, $order, $prepared_source ); |
|
623 | + if ($intent) { |
|
624 | + $intent = $this->update_existing_intent($intent, $order, $prepared_source); |
|
625 | 625 | } else { |
626 | - $intent = $this->create_intent( $order, $prepared_source ); |
|
626 | + $intent = $this->create_intent($order, $prepared_source); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | // Confirm the intent after locking the order to make sure webhooks will not interfere. |
630 | - if ( empty( $intent->error ) ) { |
|
631 | - $this->lock_order_payment( $order, $intent ); |
|
632 | - $intent = $this->confirm_intent( $intent, $order, $prepared_source ); |
|
630 | + if (empty($intent->error)) { |
|
631 | + $this->lock_order_payment($order, $intent); |
|
632 | + $intent = $this->confirm_intent($intent, $order, $prepared_source); |
|
633 | 633 | } |
634 | 634 | |
635 | - if ( ! empty( $intent->error ) ) { |
|
636 | - $this->maybe_remove_non_existent_customer( $intent->error, $order ); |
|
635 | + if ( ! empty($intent->error)) { |
|
636 | + $this->maybe_remove_non_existent_customer($intent->error, $order); |
|
637 | 637 | |
638 | 638 | // We want to retry. |
639 | - if ( $this->is_retryable_error( $intent->error ) ) { |
|
640 | - return $this->retry_after_error( $intent, $order, $retry, $force_save_source, $previous_error, $use_order_source ); |
|
639 | + if ($this->is_retryable_error($intent->error)) { |
|
640 | + return $this->retry_after_error($intent, $order, $retry, $force_save_source, $previous_error, $use_order_source); |
|
641 | 641 | } |
642 | 642 | |
643 | - $this->unlock_order_payment( $order ); |
|
644 | - $this->throw_localized_message( $intent, $order ); |
|
643 | + $this->unlock_order_payment($order); |
|
644 | + $this->throw_localized_message($intent, $order); |
|
645 | 645 | } |
646 | 646 | |
647 | - if ( ! empty( $intent ) ) { |
|
647 | + if ( ! empty($intent)) { |
|
648 | 648 | // Use the last charge within the intent to proceed. |
649 | - $response = end( $intent->charges->data ); |
|
649 | + $response = end($intent->charges->data); |
|
650 | 650 | |
651 | 651 | // If the intent requires a 3DS flow, redirect to it. |
652 | - if ( 'requires_action' === $intent->status ) { |
|
653 | - $this->unlock_order_payment( $order ); |
|
652 | + if ('requires_action' === $intent->status) { |
|
653 | + $this->unlock_order_payment($order); |
|
654 | 654 | |
655 | - if ( is_wc_endpoint_url( 'order-pay' ) ) { |
|
656 | - $redirect_url = add_query_arg( 'wc-stripe-confirmation', 1, $order->get_checkout_payment_url( false ) ); |
|
655 | + if (is_wc_endpoint_url('order-pay')) { |
|
656 | + $redirect_url = add_query_arg('wc-stripe-confirmation', 1, $order->get_checkout_payment_url(false)); |
|
657 | 657 | |
658 | 658 | return array( |
659 | 659 | 'result' => 'success', |
@@ -668,7 +668,7 @@ discard block |
||
668 | 668 | |
669 | 669 | return array( |
670 | 670 | 'result' => 'success', |
671 | - 'redirect' => $this->get_return_url( $order ), |
|
671 | + 'redirect' => $this->get_return_url($order), |
|
672 | 672 | 'payment_intent_secret' => $intent->client_secret, |
673 | 673 | ); |
674 | 674 | } |
@@ -676,30 +676,30 @@ discard block |
||
676 | 676 | } |
677 | 677 | |
678 | 678 | // Process valid response. |
679 | - $this->process_response( $response, $order ); |
|
679 | + $this->process_response($response, $order); |
|
680 | 680 | |
681 | 681 | // Remove cart. |
682 | - if ( isset( WC()->cart ) ) { |
|
682 | + if (isset(WC()->cart)) { |
|
683 | 683 | WC()->cart->empty_cart(); |
684 | 684 | } |
685 | 685 | |
686 | 686 | // Unlock the order. |
687 | - $this->unlock_order_payment( $order ); |
|
687 | + $this->unlock_order_payment($order); |
|
688 | 688 | |
689 | 689 | // Return thank you page redirect. |
690 | 690 | return array( |
691 | 691 | 'result' => 'success', |
692 | - 'redirect' => $this->get_return_url( $order ), |
|
692 | + 'redirect' => $this->get_return_url($order), |
|
693 | 693 | ); |
694 | 694 | |
695 | - } catch ( WC_Stripe_Exception $e ) { |
|
696 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
697 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
695 | + } catch (WC_Stripe_Exception $e) { |
|
696 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
697 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
698 | 698 | |
699 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
699 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
700 | 700 | |
701 | 701 | /* translators: error message */ |
702 | - $order->update_status( 'failed' ); |
|
702 | + $order->update_status('failed'); |
|
703 | 703 | |
704 | 704 | return array( |
705 | 705 | 'result' => 'fail', |
@@ -715,17 +715,17 @@ discard block |
||
715 | 715 | * |
716 | 716 | * @param int $order_id The ID of the order. |
717 | 717 | */ |
718 | - public function display_order_fee( $order_id ) { |
|
719 | - if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) { |
|
718 | + public function display_order_fee($order_id) { |
|
719 | + if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) { |
|
720 | 720 | return; |
721 | 721 | } |
722 | 722 | |
723 | - $order = wc_get_order( $order_id ); |
|
723 | + $order = wc_get_order($order_id); |
|
724 | 724 | |
725 | - $fee = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
726 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
725 | + $fee = WC_Stripe_Helper::get_stripe_fee($order); |
|
726 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
727 | 727 | |
728 | - if ( ! $fee || ! $currency ) { |
|
728 | + if ( ! $fee || ! $currency) { |
|
729 | 729 | return; |
730 | 730 | } |
731 | 731 | |
@@ -733,12 +733,12 @@ discard block |
||
733 | 733 | |
734 | 734 | <tr> |
735 | 735 | <td class="label stripe-fee"> |
736 | - <?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?> |
|
737 | - <?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?> |
|
736 | + <?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?> |
|
737 | + <?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?> |
|
738 | 738 | </td> |
739 | 739 | <td width="1%"></td> |
740 | 740 | <td class="total"> |
741 | - - <?php echo wc_price( $fee, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
741 | + - <?php echo wc_price($fee, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
742 | 742 | </td> |
743 | 743 | </tr> |
744 | 744 | |
@@ -752,17 +752,17 @@ discard block |
||
752 | 752 | * |
753 | 753 | * @param int $order_id The ID of the order. |
754 | 754 | */ |
755 | - public function display_order_payout( $order_id ) { |
|
756 | - if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) { |
|
755 | + public function display_order_payout($order_id) { |
|
756 | + if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) { |
|
757 | 757 | return; |
758 | 758 | } |
759 | 759 | |
760 | - $order = wc_get_order( $order_id ); |
|
760 | + $order = wc_get_order($order_id); |
|
761 | 761 | |
762 | - $net = WC_Stripe_Helper::get_stripe_net( $order ); |
|
763 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
762 | + $net = WC_Stripe_Helper::get_stripe_net($order); |
|
763 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
764 | 764 | |
765 | - if ( ! $net || ! $currency ) { |
|
765 | + if ( ! $net || ! $currency) { |
|
766 | 766 | return; |
767 | 767 | } |
768 | 768 | |
@@ -770,12 +770,12 @@ discard block |
||
770 | 770 | |
771 | 771 | <tr> |
772 | 772 | <td class="label stripe-payout"> |
773 | - <?php echo wc_help_tip( __( 'This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?> |
|
774 | - <?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?> |
|
773 | + <?php echo wc_help_tip(__('This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?> |
|
774 | + <?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?> |
|
775 | 775 | </td> |
776 | 776 | <td width="1%"></td> |
777 | 777 | <td class="total"> |
778 | - <?php echo wc_price( $net, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
778 | + <?php echo wc_price($net, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
779 | 779 | </td> |
780 | 780 | </tr> |
781 | 781 | |
@@ -791,13 +791,13 @@ discard block |
||
791 | 791 | * |
792 | 792 | * @return string The localized error message. |
793 | 793 | */ |
794 | - public function get_localized_error_message_from_response( $response ) { |
|
794 | + public function get_localized_error_message_from_response($response) { |
|
795 | 795 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
796 | 796 | |
797 | - if ( 'card_error' === $response->error->type ) { |
|
798 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
797 | + if ('card_error' === $response->error->type) { |
|
798 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
799 | 799 | } else { |
800 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
800 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | return $localized_message; |
@@ -811,12 +811,12 @@ discard block |
||
811 | 811 | * @param WC_Order $order The order to add a note to. |
812 | 812 | * @throws WC_Stripe_Exception An exception with the right message. |
813 | 813 | */ |
814 | - public function throw_localized_message( $response, $order ) { |
|
815 | - $localized_message = $this->get_localized_error_message_from_response( $response ); |
|
814 | + public function throw_localized_message($response, $order) { |
|
815 | + $localized_message = $this->get_localized_error_message_from_response($response); |
|
816 | 816 | |
817 | - $order->add_order_note( $localized_message ); |
|
817 | + $order->add_order_note($localized_message); |
|
818 | 818 | |
819 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
819 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
820 | 820 | } |
821 | 821 | |
822 | 822 | /** |
@@ -832,22 +832,22 @@ discard block |
||
832 | 832 | * @throws WC_Stripe_Exception If the payment is not accepted. |
833 | 833 | * @return array|void |
834 | 834 | */ |
835 | - public function retry_after_error( $response, $order, $retry, $force_save_source, $previous_error, $use_order_source ) { |
|
836 | - if ( ! $retry ) { |
|
837 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
838 | - $order->add_order_note( $localized_message ); |
|
839 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
835 | + public function retry_after_error($response, $order, $retry, $force_save_source, $previous_error, $use_order_source) { |
|
836 | + if ( ! $retry) { |
|
837 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
838 | + $order->add_order_note($localized_message); |
|
839 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | // Don't do anymore retries after this. |
843 | - if ( 5 <= $this->retry_interval ) { |
|
844 | - return $this->process_payment( $order->get_id(), false, $force_save_source, $response->error, $previous_error ); |
|
843 | + if (5 <= $this->retry_interval) { |
|
844 | + return $this->process_payment($order->get_id(), false, $force_save_source, $response->error, $previous_error); |
|
845 | 845 | } |
846 | 846 | |
847 | - sleep( $this->retry_interval ); |
|
847 | + sleep($this->retry_interval); |
|
848 | 848 | $this->retry_interval++; |
849 | 849 | |
850 | - return $this->process_payment( $order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source ); |
|
850 | + return $this->process_payment($order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source); |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | /** |
@@ -858,23 +858,23 @@ discard block |
||
858 | 858 | * @param WC_Payment_Gateway[] $gateways A list of all available gateways. |
859 | 859 | * @return WC_Payment_Gateway[] Either the same list or an empty one in the right conditions. |
860 | 860 | */ |
861 | - public function prepare_order_pay_page( $gateways ) { |
|
862 | - if ( ! is_wc_endpoint_url( 'order-pay' ) || ! isset( $_GET['wc-stripe-confirmation'] ) ) { // wpcs: csrf ok. |
|
861 | + public function prepare_order_pay_page($gateways) { |
|
862 | + if ( ! is_wc_endpoint_url('order-pay') || ! isset($_GET['wc-stripe-confirmation'])) { // wpcs: csrf ok. |
|
863 | 863 | return $gateways; |
864 | 864 | } |
865 | 865 | |
866 | 866 | try { |
867 | 867 | $this->prepare_intent_for_order_pay_page(); |
868 | - } catch ( WC_Stripe_Exception $e ) { |
|
868 | + } catch (WC_Stripe_Exception $e) { |
|
869 | 869 | // Just show the full order pay page if there was a problem preparing the Payment Intent |
870 | 870 | return $gateways; |
871 | 871 | } |
872 | 872 | |
873 | - add_filter( 'woocommerce_checkout_show_terms', '__return_false' ); |
|
874 | - add_filter( 'woocommerce_pay_order_button_html', '__return_false' ); |
|
875 | - add_filter( 'woocommerce_available_payment_gateways', '__return_empty_array' ); |
|
876 | - add_filter( 'woocommerce_no_available_payment_methods_message', array( $this, 'change_no_available_methods_message' ) ); |
|
877 | - add_action( 'woocommerce_pay_order_after_submit', array( $this, 'render_payment_intent_inputs' ) ); |
|
873 | + add_filter('woocommerce_checkout_show_terms', '__return_false'); |
|
874 | + add_filter('woocommerce_pay_order_button_html', '__return_false'); |
|
875 | + add_filter('woocommerce_available_payment_gateways', '__return_empty_array'); |
|
876 | + add_filter('woocommerce_no_available_payment_methods_message', array($this, 'change_no_available_methods_message')); |
|
877 | + add_action('woocommerce_pay_order_after_submit', array($this, 'render_payment_intent_inputs')); |
|
878 | 878 | |
879 | 879 | return array(); |
880 | 880 | } |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | * @return string the new message. |
888 | 888 | */ |
889 | 889 | public function change_no_available_methods_message() { |
890 | - return wpautop( __( "Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe' ) ); |
|
890 | + return wpautop(__("Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe')); |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | /** |
@@ -898,19 +898,19 @@ discard block |
||
898 | 898 | * @throws WC_Stripe_Exception |
899 | 899 | * @since 4.3 |
900 | 900 | */ |
901 | - public function prepare_intent_for_order_pay_page( $order = null ) { |
|
902 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
903 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
901 | + public function prepare_intent_for_order_pay_page($order = null) { |
|
902 | + if ( ! isset($order) || empty($order)) { |
|
903 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
904 | 904 | } |
905 | - $intent = $this->get_intent_from_order( $order ); |
|
905 | + $intent = $this->get_intent_from_order($order); |
|
906 | 906 | |
907 | - if ( ! $intent ) { |
|
908 | - throw new WC_Stripe_Exception( 'Payment Intent not found', __( 'Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe' ) ); |
|
907 | + if ( ! $intent) { |
|
908 | + throw new WC_Stripe_Exception('Payment Intent not found', __('Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe')); |
|
909 | 909 | } |
910 | 910 | |
911 | - if ( 'requires_payment_method' === $intent->status && isset( $intent->last_payment_error ) |
|
912 | - && 'authentication_required' === $intent->last_payment_error->code ) { |
|
913 | - $level3_data = $this->get_level3_data_from_order( $order ); |
|
911 | + if ('requires_payment_method' === $intent->status && isset($intent->last_payment_error) |
|
912 | + && 'authentication_required' === $intent->last_payment_error->code) { |
|
913 | + $level3_data = $this->get_level3_data_from_order($order); |
|
914 | 914 | $intent = WC_Stripe_API::request_with_level3_data( |
915 | 915 | array( |
916 | 916 | 'payment_method' => $intent->last_payment_error->source->id, |
@@ -920,8 +920,8 @@ discard block |
||
920 | 920 | $order |
921 | 921 | ); |
922 | 922 | |
923 | - if ( isset( $intent->error ) ) { |
|
924 | - throw new WC_Stripe_Exception( print_r( $intent, true ), $intent->error->message ); |
|
923 | + if (isset($intent->error)) { |
|
924 | + throw new WC_Stripe_Exception(print_r($intent, true), $intent->error->message); |
|
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
@@ -936,26 +936,26 @@ discard block |
||
936 | 936 | * @throws WC_Stripe_Exception |
937 | 937 | * @since 4.2 |
938 | 938 | */ |
939 | - public function render_payment_intent_inputs( $order = null ) { |
|
940 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
941 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
939 | + public function render_payment_intent_inputs($order = null) { |
|
940 | + if ( ! isset($order) || empty($order)) { |
|
941 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
942 | 942 | } |
943 | - if ( ! isset( $this->order_pay_intent ) ) { |
|
944 | - $this->prepare_intent_for_order_pay_page( $order ); |
|
943 | + if ( ! isset($this->order_pay_intent)) { |
|
944 | + $this->prepare_intent_for_order_pay_page($order); |
|
945 | 945 | } |
946 | 946 | |
947 | 947 | $verification_url = add_query_arg( |
948 | 948 | array( |
949 | 949 | 'order' => $order->get_id(), |
950 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
951 | - 'redirect_to' => rawurlencode( $this->get_return_url( $order ) ), |
|
950 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
951 | + 'redirect_to' => rawurlencode($this->get_return_url($order)), |
|
952 | 952 | 'is_pay_for_order' => true, |
953 | 953 | ), |
954 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
954 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
955 | 955 | ); |
956 | 956 | |
957 | - echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr( $this->order_pay_intent->client_secret ) . '" />'; |
|
958 | - echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr( $verification_url ) . '" />'; |
|
957 | + echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr($this->order_pay_intent->client_secret) . '" />'; |
|
958 | + echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr($verification_url) . '" />'; |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | /** |
@@ -965,11 +965,11 @@ discard block |
||
965 | 965 | * @param WC_Payment_Token $token Payment Token. |
966 | 966 | * @return string Generated payment method HTML |
967 | 967 | */ |
968 | - public function get_saved_payment_method_option_html( $token ) { |
|
969 | - $html = parent::get_saved_payment_method_option_html( $token ); |
|
968 | + public function get_saved_payment_method_option_html($token) { |
|
969 | + $html = parent::get_saved_payment_method_option_html($token); |
|
970 | 970 | $error_wrapper = '<div class="stripe-source-errors" role="alert"></div>'; |
971 | 971 | |
972 | - return preg_replace( '~</(\w+)>\s*$~', "$error_wrapper</$1>", $html ); |
|
972 | + return preg_replace('~</(\w+)>\s*$~', "$error_wrapper</$1>", $html); |
|
973 | 973 | } |
974 | 974 | |
975 | 975 | /** |
@@ -979,18 +979,18 @@ discard block |
||
979 | 979 | * @since 4.2.0 |
980 | 980 | * @param int $order_id The ID that will be used for the thank you page. |
981 | 981 | */ |
982 | - public function check_intent_status_on_order_page( $order_id ) { |
|
983 | - if ( empty( $order_id ) || absint( $order_id ) <= 0 ) { |
|
982 | + public function check_intent_status_on_order_page($order_id) { |
|
983 | + if (empty($order_id) || absint($order_id) <= 0) { |
|
984 | 984 | return; |
985 | 985 | } |
986 | 986 | |
987 | - $order = wc_get_order( absint( $order_id ) ); |
|
987 | + $order = wc_get_order(absint($order_id)); |
|
988 | 988 | |
989 | - if ( ! $order ) { |
|
989 | + if ( ! $order) { |
|
990 | 990 | return; |
991 | 991 | } |
992 | 992 | |
993 | - $this->verify_intent_after_checkout( $order ); |
|
993 | + $this->verify_intent_after_checkout($order); |
|
994 | 994 | } |
995 | 995 | |
996 | 996 | /** |
@@ -1004,8 +1004,8 @@ discard block |
||
1004 | 1004 | * @param int $order_id The ID of the order which is being paid for. |
1005 | 1005 | * @return array |
1006 | 1006 | */ |
1007 | - public function modify_successful_payment_result( $result, $order_id ) { |
|
1008 | - if ( ! isset( $result['payment_intent_secret'] ) && ! isset( $result['setup_intent_secret'] ) ) { |
|
1007 | + public function modify_successful_payment_result($result, $order_id) { |
|
1008 | + if ( ! isset($result['payment_intent_secret']) && ! isset($result['setup_intent_secret'])) { |
|
1009 | 1009 | // Only redirects with intents need to be modified. |
1010 | 1010 | return $result; |
1011 | 1011 | } |
@@ -1014,16 +1014,16 @@ discard block |
||
1014 | 1014 | $verification_url = add_query_arg( |
1015 | 1015 | array( |
1016 | 1016 | 'order' => $order_id, |
1017 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
1018 | - 'redirect_to' => rawurlencode( $result['redirect'] ), |
|
1017 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
1018 | + 'redirect_to' => rawurlencode($result['redirect']), |
|
1019 | 1019 | ), |
1020 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
1020 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
1021 | 1021 | ); |
1022 | 1022 | |
1023 | - if ( isset( $result['payment_intent_secret'] ) ) { |
|
1024 | - $redirect = sprintf( '#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode( $verification_url ) ); |
|
1025 | - } else if ( isset( $result['setup_intent_secret'] ) ) { |
|
1026 | - $redirect = sprintf( '#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode( $verification_url ) ); |
|
1023 | + if (isset($result['payment_intent_secret'])) { |
|
1024 | + $redirect = sprintf('#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode($verification_url)); |
|
1025 | + } else if (isset($result['setup_intent_secret'])) { |
|
1026 | + $redirect = sprintf('#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode($verification_url)); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | return array( |
@@ -1035,8 +1035,8 @@ discard block |
||
1035 | 1035 | /** |
1036 | 1036 | * Proceed with current request using new login session (to ensure consistent nonce). |
1037 | 1037 | */ |
1038 | - public function set_cookie_on_current_request( $cookie ) { |
|
1039 | - $_COOKIE[ LOGGED_IN_COOKIE ] = $cookie; |
|
1038 | + public function set_cookie_on_current_request($cookie) { |
|
1039 | + $_COOKIE[LOGGED_IN_COOKIE] = $cookie; |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | /** |
@@ -1046,48 +1046,48 @@ discard block |
||
1046 | 1046 | * @since 4.2.0 |
1047 | 1047 | * @param WC_Order $order The order which is in a transitional state. |
1048 | 1048 | */ |
1049 | - public function verify_intent_after_checkout( $order ) { |
|
1049 | + public function verify_intent_after_checkout($order) { |
|
1050 | 1050 | $payment_method = $order->get_payment_method(); |
1051 | - if ( $payment_method !== $this->id ) { |
|
1051 | + if ($payment_method !== $this->id) { |
|
1052 | 1052 | // If this is not the payment method, an intent would not be available. |
1053 | 1053 | return; |
1054 | 1054 | } |
1055 | 1055 | |
1056 | - $intent = $this->get_intent_from_order( $order ); |
|
1057 | - if ( ! $intent ) { |
|
1056 | + $intent = $this->get_intent_from_order($order); |
|
1057 | + if ( ! $intent) { |
|
1058 | 1058 | // No intent, redirect to the order received page for further actions. |
1059 | 1059 | return; |
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | // A webhook might have modified or locked the order while the intent was retreived. This ensures we are reading the right status. |
1063 | - clean_post_cache( $order->get_id() ); |
|
1064 | - $order = wc_get_order( $order->get_id() ); |
|
1063 | + clean_post_cache($order->get_id()); |
|
1064 | + $order = wc_get_order($order->get_id()); |
|
1065 | 1065 | |
1066 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
1066 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
1067 | 1067 | // If payment has already been completed, this function is redundant. |
1068 | 1068 | return; |
1069 | 1069 | } |
1070 | 1070 | |
1071 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
1071 | + if ($this->lock_order_payment($order, $intent)) { |
|
1072 | 1072 | return; |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - if ( 'setup_intent' === $intent->object && 'succeeded' === $intent->status ) { |
|
1075 | + if ('setup_intent' === $intent->object && 'succeeded' === $intent->status) { |
|
1076 | 1076 | WC()->cart->empty_cart(); |
1077 | - if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) { |
|
1078 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
1077 | + if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) { |
|
1078 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
1079 | 1079 | } else { |
1080 | 1080 | $order->payment_complete(); |
1081 | 1081 | } |
1082 | - } else if ( 'succeeded' === $intent->status || 'requires_capture' === $intent->status ) { |
|
1082 | + } else if ('succeeded' === $intent->status || 'requires_capture' === $intent->status) { |
|
1083 | 1083 | // Proceed with the payment completion. |
1084 | - $this->handle_intent_verification_success( $order, $intent ); |
|
1085 | - } else if ( 'requires_payment_method' === $intent->status ) { |
|
1084 | + $this->handle_intent_verification_success($order, $intent); |
|
1085 | + } else if ('requires_payment_method' === $intent->status) { |
|
1086 | 1086 | // `requires_payment_method` means that SCA got denied for the current payment method. |
1087 | - $this->handle_intent_verification_failure( $order, $intent ); |
|
1087 | + $this->handle_intent_verification_failure($order, $intent); |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | - $this->unlock_order_payment( $order ); |
|
1090 | + $this->unlock_order_payment($order); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | /** |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param WC_Order $order The order whose verification succeeded. |
1098 | 1098 | * @param stdClass $intent The Payment Intent object. |
1099 | 1099 | */ |
1100 | - protected function handle_intent_verification_success( $order, $intent ) { |
|
1101 | - $this->process_response( end( $intent->charges->data ), $order ); |
|
1100 | + protected function handle_intent_verification_success($order, $intent) { |
|
1101 | + $this->process_response(end($intent->charges->data), $order); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | /** |
@@ -1108,8 +1108,8 @@ discard block |
||
1108 | 1108 | * @param WC_Order $order The order whose verification failed. |
1109 | 1109 | * @param stdClass $intent The Payment Intent object. |
1110 | 1110 | */ |
1111 | - protected function handle_intent_verification_failure( $order, $intent ) { |
|
1112 | - $this->failed_sca_auth( $order, $intent ); |
|
1111 | + protected function handle_intent_verification_failure($order, $intent) { |
|
1112 | + $this->failed_sca_auth($order, $intent); |
|
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | /** |
@@ -1119,18 +1119,18 @@ discard block |
||
1119 | 1119 | * @param WC_Order $order The order which should be checked. |
1120 | 1120 | * @param object $intent The intent, associated with the order. |
1121 | 1121 | */ |
1122 | - public function failed_sca_auth( $order, $intent ) { |
|
1122 | + public function failed_sca_auth($order, $intent) { |
|
1123 | 1123 | // If the order has already failed, do not repeat the same message. |
1124 | - if ( $order->has_status( 'failed' ) ) { |
|
1124 | + if ($order->has_status('failed')) { |
|
1125 | 1125 | return; |
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | // Load the right message and update the status. |
1129 | - $status_message = isset( $intent->last_payment_error ) |
|
1129 | + $status_message = isset($intent->last_payment_error) |
|
1130 | 1130 | /* translators: 1) The error message that was received from Stripe. */ |
1131 | - ? sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $intent->last_payment_error->message ) |
|
1132 | - : __( 'Stripe SCA authentication failed.', 'woocommerce-gateway-stripe' ); |
|
1133 | - $order->update_status( 'failed', $status_message ); |
|
1131 | + ? sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $intent->last_payment_error->message) |
|
1132 | + : __('Stripe SCA authentication failed.', 'woocommerce-gateway-stripe'); |
|
1133 | + $order->update_status('failed', $status_message); |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | /** |
@@ -1141,10 +1141,10 @@ discard block |
||
1141 | 1141 | * |
1142 | 1142 | * @return string Checkout URL for the given order. |
1143 | 1143 | */ |
1144 | - public function get_checkout_payment_url( $pay_url, $order ) { |
|
1144 | + public function get_checkout_payment_url($pay_url, $order) { |
|
1145 | 1145 | global $wp; |
1146 | - if ( isset( $_GET['wc-stripe-confirmation'] ) && isset( $wp->query_vars['order-pay'] ) && $wp->query_vars['order-pay'] == $order->get_id() ) { |
|
1147 | - $pay_url = add_query_arg( 'wc-stripe-confirmation', 1, $pay_url ); |
|
1146 | + if (isset($_GET['wc-stripe-confirmation']) && isset($wp->query_vars['order-pay']) && $wp->query_vars['order-pay'] == $order->get_id()) { |
|
1147 | + $pay_url = add_query_arg('wc-stripe-confirmation', 1, $pay_url); |
|
1148 | 1148 | } |
1149 | 1149 | return $pay_url; |
1150 | 1150 | } |
@@ -1154,63 +1154,63 @@ discard block |
||
1154 | 1154 | */ |
1155 | 1155 | public function process_admin_options() { |
1156 | 1156 | // Load all old values before the new settings get saved. |
1157 | - $old_publishable_key = $this->get_option( 'publishable_key' ); |
|
1158 | - $old_secret_key = $this->get_option( 'secret_key' ); |
|
1159 | - $old_test_publishable_key = $this->get_option( 'test_publishable_key' ); |
|
1160 | - $old_test_secret_key = $this->get_option( 'test_secret_key' ); |
|
1157 | + $old_publishable_key = $this->get_option('publishable_key'); |
|
1158 | + $old_secret_key = $this->get_option('secret_key'); |
|
1159 | + $old_test_publishable_key = $this->get_option('test_publishable_key'); |
|
1160 | + $old_test_secret_key = $this->get_option('test_secret_key'); |
|
1161 | 1161 | |
1162 | 1162 | parent::process_admin_options(); |
1163 | 1163 | |
1164 | 1164 | // Load all old values after the new settings have been saved. |
1165 | - $new_publishable_key = $this->get_option( 'publishable_key' ); |
|
1166 | - $new_secret_key = $this->get_option( 'secret_key' ); |
|
1167 | - $new_test_publishable_key = $this->get_option( 'test_publishable_key' ); |
|
1168 | - $new_test_secret_key = $this->get_option( 'test_secret_key' ); |
|
1165 | + $new_publishable_key = $this->get_option('publishable_key'); |
|
1166 | + $new_secret_key = $this->get_option('secret_key'); |
|
1167 | + $new_test_publishable_key = $this->get_option('test_publishable_key'); |
|
1168 | + $new_test_secret_key = $this->get_option('test_secret_key'); |
|
1169 | 1169 | |
1170 | 1170 | // Checks whether a value has transitioned from a non-empty value to a new one. |
1171 | - $has_changed = function( $old_value, $new_value ) { |
|
1172 | - return ! empty( $old_value ) && ( $old_value !== $new_value ); |
|
1171 | + $has_changed = function($old_value, $new_value) { |
|
1172 | + return ! empty($old_value) && ($old_value !== $new_value); |
|
1173 | 1173 | }; |
1174 | 1174 | |
1175 | 1175 | // Look for updates. |
1176 | 1176 | if ( |
1177 | - $has_changed( $old_publishable_key, $new_publishable_key ) |
|
1178 | - || $has_changed( $old_secret_key, $new_secret_key ) |
|
1179 | - || $has_changed( $old_test_publishable_key, $new_test_publishable_key ) |
|
1180 | - || $has_changed( $old_test_secret_key, $new_test_secret_key ) |
|
1177 | + $has_changed($old_publishable_key, $new_publishable_key) |
|
1178 | + || $has_changed($old_secret_key, $new_secret_key) |
|
1179 | + || $has_changed($old_test_publishable_key, $new_test_publishable_key) |
|
1180 | + || $has_changed($old_test_secret_key, $new_test_secret_key) |
|
1181 | 1181 | ) { |
1182 | - update_option( 'wc_stripe_show_changed_keys_notice', 'yes' ); |
|
1182 | + update_option('wc_stripe_show_changed_keys_notice', 'yes'); |
|
1183 | 1183 | } |
1184 | 1184 | } |
1185 | 1185 | |
1186 | - public function validate_publishable_key_field( $key, $value ) { |
|
1187 | - $value = $this->validate_text_field( $key, $value ); |
|
1188 | - if ( ! empty( $value ) && ! preg_match( '/^pk_live_/', $value ) ) { |
|
1189 | - throw new Exception( __( 'The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
1186 | + public function validate_publishable_key_field($key, $value) { |
|
1187 | + $value = $this->validate_text_field($key, $value); |
|
1188 | + if ( ! empty($value) && ! preg_match('/^pk_live_/', $value)) { |
|
1189 | + throw new Exception(__('The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
1190 | 1190 | } |
1191 | 1191 | return $value; |
1192 | 1192 | } |
1193 | 1193 | |
1194 | - public function validate_secret_key_field( $key, $value ) { |
|
1195 | - $value = $this->validate_text_field( $key, $value ); |
|
1196 | - if ( ! empty( $value ) && ! preg_match( '/^[rs]k_live_/', $value ) ) { |
|
1197 | - throw new Exception( __( 'The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
1194 | + public function validate_secret_key_field($key, $value) { |
|
1195 | + $value = $this->validate_text_field($key, $value); |
|
1196 | + if ( ! empty($value) && ! preg_match('/^[rs]k_live_/', $value)) { |
|
1197 | + throw new Exception(__('The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
1198 | 1198 | } |
1199 | 1199 | return $value; |
1200 | 1200 | } |
1201 | 1201 | |
1202 | - public function validate_test_publishable_key_field( $key, $value ) { |
|
1203 | - $value = $this->validate_text_field( $key, $value ); |
|
1204 | - if ( ! empty( $value ) && ! preg_match( '/^pk_test_/', $value ) ) { |
|
1205 | - throw new Exception( __( 'The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
1202 | + public function validate_test_publishable_key_field($key, $value) { |
|
1203 | + $value = $this->validate_text_field($key, $value); |
|
1204 | + if ( ! empty($value) && ! preg_match('/^pk_test_/', $value)) { |
|
1205 | + throw new Exception(__('The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
1206 | 1206 | } |
1207 | 1207 | return $value; |
1208 | 1208 | } |
1209 | 1209 | |
1210 | - public function validate_test_secret_key_field( $key, $value ) { |
|
1211 | - $value = $this->validate_text_field( $key, $value ); |
|
1212 | - if ( ! empty( $value ) && ! preg_match( '/^[rs]k_test_/', $value ) ) { |
|
1213 | - throw new Exception( __( 'The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
1210 | + public function validate_test_secret_key_field($key, $value) { |
|
1211 | + $value = $this->validate_text_field($key, $value); |
|
1212 | + if ( ! empty($value) && ! preg_match('/^[rs]k_test_/', $value)) { |
|
1213 | + throw new Exception(__('The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
1214 | 1214 | } |
1215 | 1215 | return $value; |
1216 | 1216 | } |
@@ -1222,10 +1222,10 @@ discard block |
||
1222 | 1222 | * @param $settings WC_Settings_API settings to be filtered |
1223 | 1223 | * @return Filtered settings |
1224 | 1224 | */ |
1225 | - public function settings_api_sanitized_fields( $settings ) { |
|
1226 | - if ( is_array( $settings ) ) { |
|
1227 | - if ( array_key_exists( 'statement_descriptor', $settings ) ) { |
|
1228 | - $settings['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $settings['statement_descriptor']); |
|
1225 | + public function settings_api_sanitized_fields($settings) { |
|
1226 | + if (is_array($settings)) { |
|
1227 | + if (array_key_exists('statement_descriptor', $settings)) { |
|
1228 | + $settings['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($settings['statement_descriptor']); |
|
1229 | 1229 | } |
1230 | 1230 | } |
1231 | 1231 | return $settings; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct() { |
41 | 41 | $this->retry_interval = 2; |
42 | - $stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
43 | - $this->testmode = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false; |
|
44 | - $secret_key = ( $this->testmode ? 'test_' : '' ) . 'webhook_secret'; |
|
45 | - $this->secret = ! empty( $stripe_settings[ $secret_key ] ) ? $stripe_settings[ $secret_key ] : false; |
|
42 | + $stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
43 | + $this->testmode = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false; |
|
44 | + $secret_key = ($this->testmode ? 'test_' : '') . 'webhook_secret'; |
|
45 | + $this->secret = ! empty($stripe_settings[$secret_key]) ? $stripe_settings[$secret_key] : false; |
|
46 | 46 | |
47 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
47 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -54,26 +54,26 @@ discard block |
||
54 | 54 | * @version 4.0.0 |
55 | 55 | */ |
56 | 56 | public function check_for_webhook() { |
57 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
58 | - || ! isset( $_GET['wc-api'] ) |
|
59 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
57 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
58 | + || ! isset($_GET['wc-api']) |
|
59 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
60 | 60 | ) { |
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - $request_body = file_get_contents( 'php://input' ); |
|
65 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
64 | + $request_body = file_get_contents('php://input'); |
|
65 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
66 | 66 | |
67 | 67 | // Validate it to make sure it is legit. |
68 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
69 | - $this->process_webhook( $request_body ); |
|
70 | - status_header( 200 ); |
|
68 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
69 | + $this->process_webhook($request_body); |
|
70 | + status_header(200); |
|
71 | 71 | exit; |
72 | 72 | } else { |
73 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
73 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
74 | 74 | // A webhook endpoint must return a 2xx HTTP status code. |
75 | 75 | // @see https://stripe.com/docs/webhooks/build#return-a-2xx-status-code-quickly |
76 | - status_header( 204 ); |
|
76 | + status_header(204); |
|
77 | 77 | exit; |
78 | 78 | } |
79 | 79 | } |
@@ -87,34 +87,34 @@ discard block |
||
87 | 87 | * @param string $request_body The request body from Stripe. |
88 | 88 | * @return bool |
89 | 89 | */ |
90 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
91 | - if ( null === $request_headers || null === $request_body ) { |
|
90 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
91 | + if (null === $request_headers || null === $request_body) { |
|
92 | 92 | return false; |
93 | 93 | } |
94 | 94 | |
95 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
95 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | - if ( ! empty( $this->secret ) ) { |
|
99 | + if ( ! empty($this->secret)) { |
|
100 | 100 | // Check for a valid signature. |
101 | 101 | $signature_format = '/^t=(?P<timestamp>\d+)(?P<signatures>(,v\d+=[a-z0-9]+){1,2})$/'; |
102 | - if ( empty( $request_headers['STRIPE-SIGNATURE'] ) || ! preg_match( $signature_format, $request_headers['STRIPE-SIGNATURE'], $matches ) ) { |
|
102 | + if (empty($request_headers['STRIPE-SIGNATURE']) || ! preg_match($signature_format, $request_headers['STRIPE-SIGNATURE'], $matches)) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Verify the timestamp. |
107 | - $timestamp = intval( $matches['timestamp'] ); |
|
108 | - if ( abs( $timestamp - time() ) > 5 * MINUTE_IN_SECONDS ) { |
|
107 | + $timestamp = intval($matches['timestamp']); |
|
108 | + if (abs($timestamp - time()) > 5 * MINUTE_IN_SECONDS) { |
|
109 | 109 | return false; |
110 | 110 | } |
111 | 111 | |
112 | 112 | // Generate the expected signature. |
113 | 113 | $signed_payload = $timestamp . '.' . $request_body; |
114 | - $expected_signature = hash_hmac( 'sha256', $signed_payload, $this->secret ); |
|
114 | + $expected_signature = hash_hmac('sha256', $signed_payload, $this->secret); |
|
115 | 115 | |
116 | 116 | // Check if the expected signature is present. |
117 | - if ( ! preg_match( '/,v\d+=' . preg_quote( $expected_signature, '/' ) . '/', $matches['signatures'] ) ) { |
|
117 | + if ( ! preg_match('/,v\d+=' . preg_quote($expected_signature, '/') . '/', $matches['signatures'])) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | } |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | * @version 4.0.0 |
132 | 132 | */ |
133 | 133 | public function get_request_headers() { |
134 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
134 | + if ( ! function_exists('getallheaders')) { |
|
135 | 135 | $headers = array(); |
136 | 136 | |
137 | - foreach ( $_SERVER as $name => $value ) { |
|
138 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
139 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
137 | + foreach ($_SERVER as $name => $value) { |
|
138 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
139 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
@@ -155,30 +155,30 @@ discard block |
||
155 | 155 | * @param object $notification |
156 | 156 | * @param bool $retry |
157 | 157 | */ |
158 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
158 | + public function process_webhook_payment($notification, $retry = true) { |
|
159 | 159 | // The following 3 payment methods are synchronous so does not need to be handle via webhook. |
160 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) { |
|
160 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) { |
|
161 | 161 | return; |
162 | 162 | } |
163 | 163 | |
164 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
164 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
165 | 165 | |
166 | - if ( ! $order ) { |
|
167 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
166 | + if ( ! $order) { |
|
167 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | 171 | $order_id = $order->get_id(); |
172 | 172 | $source_id = $notification->data->object->id; |
173 | 173 | |
174 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
174 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
175 | 175 | |
176 | 176 | try { |
177 | - if ( $order->has_status( array( 'processing', 'completed' ) ) ) { |
|
177 | + if ($order->has_status(array('processing', 'completed'))) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | 180 | |
181 | - if ( $order->has_status( 'on-hold' ) && ! $is_pending_receiver ) { |
|
181 | + if ($order->has_status('on-hold') && ! $is_pending_receiver) { |
|
182 | 182 | return; |
183 | 183 | } |
184 | 184 | |
@@ -186,89 +186,89 @@ discard block |
||
186 | 186 | $response = null; |
187 | 187 | |
188 | 188 | // This will throw exception if not valid. |
189 | - $this->validate_minimum_order_amount( $order ); |
|
189 | + $this->validate_minimum_order_amount($order); |
|
190 | 190 | |
191 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
191 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
192 | 192 | |
193 | 193 | // Prep source object. |
194 | 194 | $source_object = new stdClass(); |
195 | 195 | $source_object->token_id = ''; |
196 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
196 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
197 | 197 | $source_object->source = $source_id; |
198 | 198 | |
199 | 199 | // Make the request. |
200 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true ); |
|
200 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true); |
|
201 | 201 | $headers = $response['headers']; |
202 | 202 | $response = $response['body']; |
203 | 203 | |
204 | - if ( ! empty( $response->error ) ) { |
|
204 | + if ( ! empty($response->error)) { |
|
205 | 205 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
206 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
207 | - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); |
|
208 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
206 | + if ($this->is_no_such_customer_error($response->error)) { |
|
207 | + delete_user_option($order->get_customer_id(), '_stripe_customer_id'); |
|
208 | + $order->delete_meta_data('_stripe_customer_id'); |
|
209 | 209 | $order->save(); |
210 | 210 | } |
211 | 211 | |
212 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
212 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
213 | 213 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
214 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
214 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
215 | 215 | $wc_token->delete(); |
216 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
217 | - $order->add_order_note( $localized_message ); |
|
218 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
216 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
217 | + $order->add_order_note($localized_message); |
|
218 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | // We want to retry. |
222 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
223 | - if ( $retry ) { |
|
222 | + if ($this->is_retryable_error($response->error)) { |
|
223 | + if ($retry) { |
|
224 | 224 | // Don't do anymore retries after this. |
225 | - if ( 5 <= $this->retry_interval ) { |
|
225 | + if (5 <= $this->retry_interval) { |
|
226 | 226 | |
227 | - return $this->process_webhook_payment( $notification, false ); |
|
227 | + return $this->process_webhook_payment($notification, false); |
|
228 | 228 | } |
229 | 229 | |
230 | - sleep( $this->retry_interval ); |
|
230 | + sleep($this->retry_interval); |
|
231 | 231 | |
232 | 232 | $this->retry_interval++; |
233 | - return $this->process_webhook_payment( $notification, true ); |
|
233 | + return $this->process_webhook_payment($notification, true); |
|
234 | 234 | } else { |
235 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
236 | - $order->add_order_note( $localized_message ); |
|
237 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
235 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
236 | + $order->add_order_note($localized_message); |
|
237 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | 241 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
242 | 242 | |
243 | - if ( 'card_error' === $response->error->type ) { |
|
244 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
243 | + if ('card_error' === $response->error->type) { |
|
244 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
245 | 245 | } else { |
246 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
246 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
247 | 247 | } |
248 | 248 | |
249 | - $order->add_order_note( $localized_message ); |
|
249 | + $order->add_order_note($localized_message); |
|
250 | 250 | |
251 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
251 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | // To prevent double processing the order on WC side. |
255 | - if ( ! $this->is_original_request( $headers ) ) { |
|
255 | + if ( ! $this->is_original_request($headers)) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | 258 | |
259 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
259 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
260 | 260 | |
261 | - $this->process_response( $response, $order ); |
|
261 | + $this->process_response($response, $order); |
|
262 | 262 | |
263 | - } catch ( WC_Stripe_Exception $e ) { |
|
264 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
263 | + } catch (WC_Stripe_Exception $e) { |
|
264 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
265 | 265 | |
266 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e ); |
|
266 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e); |
|
267 | 267 | |
268 | - $statuses = array( 'pending', 'failed' ); |
|
268 | + $statuses = array('pending', 'failed'); |
|
269 | 269 | |
270 | - if ( $order->has_status( $statuses ) ) { |
|
271 | - $this->send_failed_order_email( $order_id ); |
|
270 | + if ($order->has_status($statuses)) { |
|
271 | + $this->send_failed_order_email($order_id); |
|
272 | 272 | } |
273 | 273 | } |
274 | 274 | } |
@@ -281,28 +281,28 @@ discard block |
||
281 | 281 | * @since 4.0.0 |
282 | 282 | * @param object $notification |
283 | 283 | */ |
284 | - public function process_webhook_dispute( $notification ) { |
|
285 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
284 | + public function process_webhook_dispute($notification) { |
|
285 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
286 | 286 | |
287 | - if ( ! $order ) { |
|
288 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
287 | + if ( ! $order) { |
|
288 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
289 | 289 | return; |
290 | 290 | } |
291 | 291 | |
292 | - $order->update_meta_data( '_stripe_status_before_hold', $order->get_status() ); |
|
292 | + $order->update_meta_data('_stripe_status_before_hold', $order->get_status()); |
|
293 | 293 | |
294 | 294 | /* translators: 1) The URL to the order. */ |
295 | - $message = sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ); |
|
296 | - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
297 | - $order->update_status( 'on-hold', $message ); |
|
295 | + $message = sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order)); |
|
296 | + if ( ! $order->get_meta('_stripe_status_final', false)) { |
|
297 | + $order->update_status('on-hold', $message); |
|
298 | 298 | } else { |
299 | - $order->add_order_note( $message ); |
|
299 | + $order->add_order_note($message); |
|
300 | 300 | } |
301 | 301 | |
302 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
302 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
303 | 303 | |
304 | 304 | $order_id = $order->get_id(); |
305 | - $this->send_failed_order_email( $order_id ); |
|
305 | + $this->send_failed_order_email($order_id); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -311,34 +311,34 @@ discard block |
||
311 | 311 | * @since 4.4.1 |
312 | 312 | * @param object $notification |
313 | 313 | */ |
314 | - public function process_webhook_dispute_closed( $notification ) { |
|
315 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
314 | + public function process_webhook_dispute_closed($notification) { |
|
315 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
316 | 316 | $status = $notification->data->object->status; |
317 | 317 | |
318 | - if ( ! $order ) { |
|
319 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
318 | + if ( ! $order) { |
|
319 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
320 | 320 | return; |
321 | 321 | } |
322 | 322 | |
323 | - if ( 'lost' === $status ) { |
|
324 | - $message = __( 'The dispute was lost or accepted.', 'woocommerce-gateway-stripe' ); |
|
325 | - } elseif ( 'won' === $status ) { |
|
326 | - $message = __( 'The dispute was resolved in your favor.', 'woocommerce-gateway-stripe' ); |
|
327 | - } elseif ( 'warning_closed' === $status ) { |
|
328 | - $message = __( 'The inquiry or retrieval was closed.', 'woocommerce-gateway-stripe' ); |
|
323 | + if ('lost' === $status) { |
|
324 | + $message = __('The dispute was lost or accepted.', 'woocommerce-gateway-stripe'); |
|
325 | + } elseif ('won' === $status) { |
|
326 | + $message = __('The dispute was resolved in your favor.', 'woocommerce-gateway-stripe'); |
|
327 | + } elseif ('warning_closed' === $status) { |
|
328 | + $message = __('The inquiry or retrieval was closed.', 'woocommerce-gateway-stripe'); |
|
329 | 329 | } else { |
330 | 330 | return; |
331 | 331 | } |
332 | 332 | |
333 | - if ( apply_filters( 'wc_stripe_webhook_dispute_change_order_status', true, $order, $notification ) ) { |
|
333 | + if (apply_filters('wc_stripe_webhook_dispute_change_order_status', true, $order, $notification)) { |
|
334 | 334 | // Mark final so that order status is not overridden by out-of-sequence events. |
335 | - $order->update_meta_data( '_stripe_status_final', true ); |
|
335 | + $order->update_meta_data('_stripe_status_final', true); |
|
336 | 336 | |
337 | 337 | // Fail order if dispute is lost, or else revert to pre-dispute status. |
338 | - $order_status = 'lost' === $status ? 'failed' : $order->get_meta( '_stripe_status_before_hold', 'processing' ); |
|
339 | - $order->update_status( $order_status, $message ); |
|
338 | + $order_status = 'lost' === $status ? 'failed' : $order->get_meta('_stripe_status_before_hold', 'processing'); |
|
339 | + $order->update_status($order_status, $message); |
|
340 | 340 | } else { |
341 | - $order->add_order_note( $message ); |
|
341 | + $order->add_order_note($message); |
|
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
@@ -350,43 +350,43 @@ discard block |
||
350 | 350 | * @version 4.0.0 |
351 | 351 | * @param object $notification |
352 | 352 | */ |
353 | - public function process_webhook_capture( $notification ) { |
|
354 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
353 | + public function process_webhook_capture($notification) { |
|
354 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
355 | 355 | |
356 | - if ( ! $order ) { |
|
357 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
356 | + if ( ! $order) { |
|
357 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | - if ( 'stripe' === $order->get_payment_method() ) { |
|
361 | + if ('stripe' === $order->get_payment_method()) { |
|
362 | 362 | $charge = $order->get_transaction_id(); |
363 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
363 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
364 | 364 | |
365 | - if ( $charge && 'no' === $captured ) { |
|
366 | - $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
365 | + if ($charge && 'no' === $captured) { |
|
366 | + $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
367 | 367 | |
368 | 368 | // Store other data such as fees |
369 | - $order->set_transaction_id( $notification->data->object->id ); |
|
369 | + $order->set_transaction_id($notification->data->object->id); |
|
370 | 370 | |
371 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
372 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
371 | + if (isset($notification->data->object->balance_transaction)) { |
|
372 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | // Check and see if capture is partial. |
376 | - if ( $this->is_partial_capture( $notification ) ) { |
|
377 | - $partial_amount = $this->get_partial_amount_to_charge( $notification ); |
|
378 | - $order->set_total( $partial_amount ); |
|
379 | - $this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction ); |
|
376 | + if ($this->is_partial_capture($notification)) { |
|
377 | + $partial_amount = $this->get_partial_amount_to_charge($notification); |
|
378 | + $order->set_total($partial_amount); |
|
379 | + $this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction); |
|
380 | 380 | /* translators: partial captured amount */ |
381 | - $order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) ); |
|
381 | + $order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount)); |
|
382 | 382 | } else { |
383 | - $order->payment_complete( $notification->data->object->id ); |
|
383 | + $order->payment_complete($notification->data->object->id); |
|
384 | 384 | |
385 | 385 | /* translators: transaction id */ |
386 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
386 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
387 | 387 | } |
388 | 388 | |
389 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
389 | + if (is_callable(array($order, 'save'))) { |
|
390 | 390 | $order->save(); |
391 | 391 | } |
392 | 392 | } |
@@ -401,41 +401,41 @@ discard block |
||
401 | 401 | * @version 4.0.0 |
402 | 402 | * @param object $notification |
403 | 403 | */ |
404 | - public function process_webhook_charge_succeeded( $notification ) { |
|
404 | + public function process_webhook_charge_succeeded($notification) { |
|
405 | 405 | // Ignore the notification for charges, created through PaymentIntents. |
406 | - if ( isset( $notification->data->object->payment_intent ) && $notification->data->object->payment_intent ) { |
|
406 | + if (isset($notification->data->object->payment_intent) && $notification->data->object->payment_intent) { |
|
407 | 407 | return; |
408 | 408 | } |
409 | 409 | |
410 | 410 | // The following payment methods are synchronous so does not need to be handle via webhook. |
411 | - 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 ) ) { |
|
411 | + 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)) { |
|
412 | 412 | return; |
413 | 413 | } |
414 | 414 | |
415 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
415 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
416 | 416 | |
417 | - if ( ! $order ) { |
|
418 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
417 | + if ( ! $order) { |
|
418 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
419 | 419 | return; |
420 | 420 | } |
421 | 421 | |
422 | - if ( ! $order->has_status( 'on-hold' ) ) { |
|
422 | + if ( ! $order->has_status('on-hold')) { |
|
423 | 423 | return; |
424 | 424 | } |
425 | 425 | |
426 | 426 | // Store other data such as fees |
427 | - $order->set_transaction_id( $notification->data->object->id ); |
|
427 | + $order->set_transaction_id($notification->data->object->id); |
|
428 | 428 | |
429 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
430 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
429 | + if (isset($notification->data->object->balance_transaction)) { |
|
430 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
431 | 431 | } |
432 | 432 | |
433 | - $order->payment_complete( $notification->data->object->id ); |
|
433 | + $order->payment_complete($notification->data->object->id); |
|
434 | 434 | |
435 | 435 | /* translators: transaction id */ |
436 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
436 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
437 | 437 | |
438 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
438 | + if (is_callable(array($order, 'save'))) { |
|
439 | 439 | $order->save(); |
440 | 440 | } |
441 | 441 | } |
@@ -447,27 +447,27 @@ discard block |
||
447 | 447 | * @since 4.1.5 Can handle any fail payments from any methods. |
448 | 448 | * @param object $notification |
449 | 449 | */ |
450 | - public function process_webhook_charge_failed( $notification ) { |
|
451 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
450 | + public function process_webhook_charge_failed($notification) { |
|
451 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
452 | 452 | |
453 | - if ( ! $order ) { |
|
454 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
453 | + if ( ! $order) { |
|
454 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
455 | 455 | return; |
456 | 456 | } |
457 | 457 | |
458 | 458 | // If order status is already in failed status don't continue. |
459 | - if ( $order->has_status( 'failed' ) ) { |
|
459 | + if ($order->has_status('failed')) { |
|
460 | 460 | return; |
461 | 461 | } |
462 | 462 | |
463 | - $message = __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ); |
|
464 | - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
465 | - $order->update_status( 'failed', $message ); |
|
463 | + $message = __('This payment failed to clear.', 'woocommerce-gateway-stripe'); |
|
464 | + if ( ! $order->get_meta('_stripe_status_final', false)) { |
|
465 | + $order->update_status('failed', $message); |
|
466 | 466 | } else { |
467 | - $order->add_order_note( $message ); |
|
467 | + $order->add_order_note($message); |
|
468 | 468 | } |
469 | 469 | |
470 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
470 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | /** |
@@ -478,33 +478,33 @@ discard block |
||
478 | 478 | * @since 4.1.15 Add check to make sure order is processed by Stripe. |
479 | 479 | * @param object $notification |
480 | 480 | */ |
481 | - public function process_webhook_source_canceled( $notification ) { |
|
482 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
481 | + public function process_webhook_source_canceled($notification) { |
|
482 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
483 | 483 | |
484 | 484 | // If can't find order by charge ID, try source ID. |
485 | - if ( ! $order ) { |
|
486 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
485 | + if ( ! $order) { |
|
486 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
487 | 487 | |
488 | - if ( ! $order ) { |
|
489 | - WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id ); |
|
488 | + if ( ! $order) { |
|
489 | + WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id); |
|
490 | 490 | return; |
491 | 491 | } |
492 | 492 | } |
493 | 493 | |
494 | 494 | // Don't proceed if payment method isn't Stripe. |
495 | - if ( 'stripe' !== $order->get_payment_method() ) { |
|
496 | - WC_Stripe_Logger::log( 'Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id() ); |
|
495 | + if ('stripe' !== $order->get_payment_method()) { |
|
496 | + WC_Stripe_Logger::log('Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id()); |
|
497 | 497 | return; |
498 | 498 | } |
499 | 499 | |
500 | - $message = __( 'This payment was cancelled.', 'woocommerce-gateway-stripe' ); |
|
501 | - if ( ! $order->has_status( 'cancelled' ) && ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
502 | - $order->update_status( 'cancelled', $message ); |
|
500 | + $message = __('This payment was cancelled.', 'woocommerce-gateway-stripe'); |
|
501 | + if ( ! $order->has_status('cancelled') && ! $order->get_meta('_stripe_status_final', false)) { |
|
502 | + $order->update_status('cancelled', $message); |
|
503 | 503 | } else { |
504 | - $order->add_order_note( $message ); |
|
504 | + $order->add_order_note($message); |
|
505 | 505 | } |
506 | 506 | |
507 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
507 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
@@ -514,59 +514,59 @@ discard block |
||
514 | 514 | * @version 4.0.0 |
515 | 515 | * @param object $notification |
516 | 516 | */ |
517 | - public function process_webhook_refund( $notification ) { |
|
518 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
517 | + public function process_webhook_refund($notification) { |
|
518 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
519 | 519 | |
520 | - if ( ! $order ) { |
|
521 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
520 | + if ( ! $order) { |
|
521 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
522 | 522 | return; |
523 | 523 | } |
524 | 524 | |
525 | 525 | $order_id = $order->get_id(); |
526 | 526 | |
527 | - if ( 'stripe' === $order->get_payment_method() ) { |
|
527 | + if ('stripe' === $order->get_payment_method()) { |
|
528 | 528 | $charge = $order->get_transaction_id(); |
529 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
530 | - $refund_id = $order->get_meta( '_stripe_refund_id', true ); |
|
529 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
530 | + $refund_id = $order->get_meta('_stripe_refund_id', true); |
|
531 | 531 | |
532 | 532 | // If the refund ID matches, don't continue to prevent double refunding. |
533 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
533 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
534 | 534 | return; |
535 | 535 | } |
536 | 536 | |
537 | 537 | // Only refund captured charge. |
538 | - if ( $charge ) { |
|
539 | - $reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
538 | + if ($charge) { |
|
539 | + $reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
540 | 540 | |
541 | 541 | // Create the refund. |
542 | 542 | $refund = wc_create_refund( |
543 | 543 | array( |
544 | 544 | 'order_id' => $order_id, |
545 | - 'amount' => $this->get_refund_amount( $notification ), |
|
545 | + 'amount' => $this->get_refund_amount($notification), |
|
546 | 546 | 'reason' => $reason, |
547 | 547 | ) |
548 | 548 | ); |
549 | 549 | |
550 | - if ( is_wp_error( $refund ) ) { |
|
551 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
550 | + if (is_wp_error($refund)) { |
|
551 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
552 | 552 | } |
553 | 553 | |
554 | - $order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ); |
|
554 | + $order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id); |
|
555 | 555 | |
556 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 ); |
|
556 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount / 100); |
|
557 | 557 | |
558 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
559 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount ); |
|
558 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
559 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount); |
|
560 | 560 | } |
561 | 561 | |
562 | - if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) { |
|
563 | - $this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction ); |
|
562 | + if (isset($notification->data->object->refunds->data[0]->balance_transaction)) { |
|
563 | + $this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
567 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $notification->data->object->refunds->data[0]->id, $reason ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
567 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe'), $amount, $notification->data->object->refunds->data[0]->id, $reason) : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
568 | 568 | |
569 | - $order->add_order_note( $refund_message ); |
|
569 | + $order->add_order_note($refund_message); |
|
570 | 570 | } |
571 | 571 | } |
572 | 572 | } |
@@ -577,32 +577,32 @@ discard block |
||
577 | 577 | * @since 4.0.6 |
578 | 578 | * @param object $notification |
579 | 579 | */ |
580 | - public function process_review_opened( $notification ) { |
|
581 | - if ( isset( $notification->data->object->payment_intent ) ) { |
|
582 | - $order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent ); |
|
580 | + public function process_review_opened($notification) { |
|
581 | + if (isset($notification->data->object->payment_intent)) { |
|
582 | + $order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent); |
|
583 | 583 | |
584 | - if ( ! $order ) { |
|
585 | - WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent ); |
|
584 | + if ( ! $order) { |
|
585 | + WC_Stripe_Logger::log('[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent); |
|
586 | 586 | return; |
587 | 587 | } |
588 | 588 | } else { |
589 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
589 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
590 | 590 | |
591 | - if ( ! $order ) { |
|
592 | - WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
591 | + if ( ! $order) { |
|
592 | + WC_Stripe_Logger::log('[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge); |
|
593 | 593 | return; |
594 | 594 | } |
595 | 595 | } |
596 | 596 | |
597 | - $order->update_meta_data( '_stripe_status_before_hold', $order->get_status() ); |
|
597 | + $order->update_meta_data('_stripe_status_before_hold', $order->get_status()); |
|
598 | 598 | |
599 | 599 | /* translators: 1) The URL to the order. 2) The reason type. */ |
600 | - $message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason ); |
|
600 | + $message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason); |
|
601 | 601 | |
602 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) && ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
603 | - $order->update_status( 'on-hold', $message ); |
|
602 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification) && ! $order->get_meta('_stripe_status_final', false)) { |
|
603 | + $order->update_status('on-hold', $message); |
|
604 | 604 | } else { |
605 | - $order->add_order_note( $message ); |
|
605 | + $order->add_order_note($message); |
|
606 | 606 | } |
607 | 607 | } |
608 | 608 | |
@@ -612,34 +612,34 @@ discard block |
||
612 | 612 | * @since 4.0.6 |
613 | 613 | * @param object $notification |
614 | 614 | */ |
615 | - public function process_review_closed( $notification ) { |
|
616 | - if ( isset( $notification->data->object->payment_intent ) ) { |
|
617 | - $order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent ); |
|
615 | + public function process_review_closed($notification) { |
|
616 | + if (isset($notification->data->object->payment_intent)) { |
|
617 | + $order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent); |
|
618 | 618 | |
619 | - if ( ! $order ) { |
|
620 | - WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent ); |
|
619 | + if ( ! $order) { |
|
620 | + WC_Stripe_Logger::log('[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent); |
|
621 | 621 | return; |
622 | 622 | } |
623 | 623 | } else { |
624 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
624 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
625 | 625 | |
626 | - if ( ! $order ) { |
|
627 | - WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
626 | + if ( ! $order) { |
|
627 | + WC_Stripe_Logger::log('[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge); |
|
628 | 628 | return; |
629 | 629 | } |
630 | 630 | } |
631 | 631 | |
632 | 632 | /* translators: 1) The reason type. */ |
633 | - $message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ); |
|
633 | + $message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason); |
|
634 | 634 | |
635 | 635 | if ( |
636 | - $order->has_status( 'on-hold' ) && |
|
637 | - apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) && |
|
638 | - ! $order->get_meta( '_stripe_status_final', false ) |
|
636 | + $order->has_status('on-hold') && |
|
637 | + apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification) && |
|
638 | + ! $order->get_meta('_stripe_status_final', false) |
|
639 | 639 | ) { |
640 | - $order->update_status( $order->get_meta( '_stripe_status_before_hold', 'processing' ), $message ); |
|
640 | + $order->update_status($order->get_meta('_stripe_status_before_hold', 'processing'), $message); |
|
641 | 641 | } else { |
642 | - $order->add_order_note( $message ); |
|
642 | + $order->add_order_note($message); |
|
643 | 643 | } |
644 | 644 | } |
645 | 645 | |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | * @version 4.0.0 |
651 | 651 | * @param object $notification |
652 | 652 | */ |
653 | - public function is_partial_capture( $notification ) { |
|
653 | + public function is_partial_capture($notification) { |
|
654 | 654 | return 0 < $notification->data->object->amount_refunded; |
655 | 655 | } |
656 | 656 | |
@@ -661,11 +661,11 @@ discard block |
||
661 | 661 | * @version 4.0.0 |
662 | 662 | * @param object $notification |
663 | 663 | */ |
664 | - public function get_refund_amount( $notification ) { |
|
665 | - if ( $this->is_partial_capture( $notification ) ) { |
|
664 | + public function get_refund_amount($notification) { |
|
665 | + if ($this->is_partial_capture($notification)) { |
|
666 | 666 | $amount = $notification->data->object->refunds->data[0]->amount / 100; |
667 | 667 | |
668 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
668 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
669 | 669 | $amount = $notification->data->object->refunds->data[0]->amount; |
670 | 670 | } |
671 | 671 | |
@@ -682,12 +682,12 @@ discard block |
||
682 | 682 | * @version 4.0.0 |
683 | 683 | * @param object $notification |
684 | 684 | */ |
685 | - public function get_partial_amount_to_charge( $notification ) { |
|
686 | - if ( $this->is_partial_capture( $notification ) ) { |
|
687 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
685 | + public function get_partial_amount_to_charge($notification) { |
|
686 | + if ($this->is_partial_capture($notification)) { |
|
687 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
688 | 688 | |
689 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
690 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
689 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
690 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | return $amount; |
@@ -696,75 +696,75 @@ discard block |
||
696 | 696 | return false; |
697 | 697 | } |
698 | 698 | |
699 | - public function process_payment_intent_success( $notification ) { |
|
699 | + public function process_payment_intent_success($notification) { |
|
700 | 700 | $intent = $notification->data->object; |
701 | - $order = WC_Stripe_Helper::get_order_by_intent_id( $intent->id ); |
|
701 | + $order = WC_Stripe_Helper::get_order_by_intent_id($intent->id); |
|
702 | 702 | |
703 | - if ( ! $order ) { |
|
704 | - WC_Stripe_Logger::log( 'Could not find order via intent ID: ' . $intent->id ); |
|
703 | + if ( ! $order) { |
|
704 | + WC_Stripe_Logger::log('Could not find order via intent ID: ' . $intent->id); |
|
705 | 705 | return; |
706 | 706 | } |
707 | 707 | |
708 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
708 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
709 | 709 | return; |
710 | 710 | } |
711 | 711 | |
712 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
712 | + if ($this->lock_order_payment($order, $intent)) { |
|
713 | 713 | return; |
714 | 714 | } |
715 | 715 | |
716 | 716 | $order_id = $order->get_id(); |
717 | - if ( 'payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type ) { |
|
718 | - $charge = end( $intent->charges->data ); |
|
719 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" ); |
|
717 | + if ('payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type) { |
|
718 | + $charge = end($intent->charges->data); |
|
719 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id"); |
|
720 | 720 | |
721 | - do_action( 'wc_gateway_stripe_process_payment', $charge, $order ); |
|
721 | + do_action('wc_gateway_stripe_process_payment', $charge, $order); |
|
722 | 722 | |
723 | 723 | // Process valid response. |
724 | - $this->process_response( $charge, $order ); |
|
724 | + $this->process_response($charge, $order); |
|
725 | 725 | |
726 | 726 | } else { |
727 | 727 | $error_message = $intent->last_payment_error ? $intent->last_payment_error->message : ""; |
728 | 728 | |
729 | 729 | /* translators: 1) The error message that was received from Stripe. */ |
730 | - $message = sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ); |
|
730 | + $message = sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message); |
|
731 | 731 | |
732 | - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
733 | - $order->update_status( 'failed', $message ); |
|
732 | + if ( ! $order->get_meta('_stripe_status_final', false)) { |
|
733 | + $order->update_status('failed', $message); |
|
734 | 734 | } else { |
735 | - $order->add_order_note( $message ); |
|
735 | + $order->add_order_note($message); |
|
736 | 736 | } |
737 | 737 | |
738 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
738 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
739 | 739 | |
740 | - $this->send_failed_order_email( $order_id ); |
|
740 | + $this->send_failed_order_email($order_id); |
|
741 | 741 | } |
742 | 742 | |
743 | - $this->unlock_order_payment( $order ); |
|
743 | + $this->unlock_order_payment($order); |
|
744 | 744 | } |
745 | 745 | |
746 | - public function process_setup_intent( $notification ) { |
|
746 | + public function process_setup_intent($notification) { |
|
747 | 747 | $intent = $notification->data->object; |
748 | - $order = WC_Stripe_Helper::get_order_by_setup_intent_id( $intent->id ); |
|
748 | + $order = WC_Stripe_Helper::get_order_by_setup_intent_id($intent->id); |
|
749 | 749 | |
750 | - if ( ! $order ) { |
|
751 | - WC_Stripe_Logger::log( 'Could not find order via setup intent ID: ' . $intent->id ); |
|
750 | + if ( ! $order) { |
|
751 | + WC_Stripe_Logger::log('Could not find order via setup intent ID: ' . $intent->id); |
|
752 | 752 | return; |
753 | 753 | } |
754 | 754 | |
755 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
755 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
756 | 756 | return; |
757 | 757 | } |
758 | 758 | |
759 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
759 | + if ($this->lock_order_payment($order, $intent)) { |
|
760 | 760 | return; |
761 | 761 | } |
762 | 762 | |
763 | 763 | $order_id = $order->get_id(); |
764 | - if ( 'setup_intent.succeeded' === $notification->type ) { |
|
765 | - WC_Stripe_Logger::log( "Stripe SetupIntent $intent->id succeeded for order $order_id" ); |
|
766 | - if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) { |
|
767 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
764 | + if ('setup_intent.succeeded' === $notification->type) { |
|
765 | + WC_Stripe_Logger::log("Stripe SetupIntent $intent->id succeeded for order $order_id"); |
|
766 | + if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) { |
|
767 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
768 | 768 | } else { |
769 | 769 | $order->payment_complete(); |
770 | 770 | } |
@@ -772,18 +772,18 @@ discard block |
||
772 | 772 | $error_message = $intent->last_setup_error ? $intent->last_setup_error->message : ""; |
773 | 773 | |
774 | 774 | /* translators: 1) The error message that was received from Stripe. */ |
775 | - $message = sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ); |
|
775 | + $message = sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message); |
|
776 | 776 | |
777 | - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
778 | - $order->update_status( 'failed', $message ); |
|
777 | + if ( ! $order->get_meta('_stripe_status_final', false)) { |
|
778 | + $order->update_status('failed', $message); |
|
779 | 779 | } else { |
780 | - $order->add_order_note( $message ); |
|
780 | + $order->add_order_note($message); |
|
781 | 781 | } |
782 | 782 | |
783 | - $this->send_failed_order_email( $order_id ); |
|
783 | + $this->send_failed_order_email($order_id); |
|
784 | 784 | } |
785 | 785 | |
786 | - $this->unlock_order_payment( $order ); |
|
786 | + $this->unlock_order_payment($order); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -793,59 +793,59 @@ discard block |
||
793 | 793 | * @version 4.0.0 |
794 | 794 | * @param string $request_body |
795 | 795 | */ |
796 | - public function process_webhook( $request_body ) { |
|
797 | - $notification = json_decode( $request_body ); |
|
796 | + public function process_webhook($request_body) { |
|
797 | + $notification = json_decode($request_body); |
|
798 | 798 | |
799 | - switch ( $notification->type ) { |
|
799 | + switch ($notification->type) { |
|
800 | 800 | case 'source.chargeable': |
801 | - $this->process_webhook_payment( $notification ); |
|
801 | + $this->process_webhook_payment($notification); |
|
802 | 802 | break; |
803 | 803 | |
804 | 804 | case 'source.canceled': |
805 | - $this->process_webhook_source_canceled( $notification ); |
|
805 | + $this->process_webhook_source_canceled($notification); |
|
806 | 806 | break; |
807 | 807 | |
808 | 808 | case 'charge.succeeded': |
809 | - $this->process_webhook_charge_succeeded( $notification ); |
|
809 | + $this->process_webhook_charge_succeeded($notification); |
|
810 | 810 | break; |
811 | 811 | |
812 | 812 | case 'charge.failed': |
813 | - $this->process_webhook_charge_failed( $notification ); |
|
813 | + $this->process_webhook_charge_failed($notification); |
|
814 | 814 | break; |
815 | 815 | |
816 | 816 | case 'charge.captured': |
817 | - $this->process_webhook_capture( $notification ); |
|
817 | + $this->process_webhook_capture($notification); |
|
818 | 818 | break; |
819 | 819 | |
820 | 820 | case 'charge.dispute.created': |
821 | - $this->process_webhook_dispute( $notification ); |
|
821 | + $this->process_webhook_dispute($notification); |
|
822 | 822 | break; |
823 | 823 | |
824 | 824 | case 'charge.dispute.closed': |
825 | - $this->process_webhook_dispute_closed( $notification ); |
|
825 | + $this->process_webhook_dispute_closed($notification); |
|
826 | 826 | break; |
827 | 827 | |
828 | 828 | case 'charge.refunded': |
829 | - $this->process_webhook_refund( $notification ); |
|
829 | + $this->process_webhook_refund($notification); |
|
830 | 830 | break; |
831 | 831 | |
832 | 832 | case 'review.opened': |
833 | - $this->process_review_opened( $notification ); |
|
833 | + $this->process_review_opened($notification); |
|
834 | 834 | break; |
835 | 835 | |
836 | 836 | case 'review.closed': |
837 | - $this->process_review_closed( $notification ); |
|
837 | + $this->process_review_closed($notification); |
|
838 | 838 | break; |
839 | 839 | |
840 | 840 | case 'payment_intent.succeeded': |
841 | 841 | case 'payment_intent.payment_failed': |
842 | 842 | case 'payment_intent.amount_capturable_updated': |
843 | - $this->process_payment_intent_success( $notification ); |
|
843 | + $this->process_payment_intent_success($notification); |
|
844 | 844 | break; |
845 | 845 | |
846 | 846 | case 'setup_intent.succeeded': |
847 | 847 | case 'setup_intent.setup_failed': |
848 | - $this->process_setup_intent( $notification ); |
|
848 | + $this->process_setup_intent($notification); |
|
849 | 849 | |
850 | 850 | } |
851 | 851 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function display_admin_settings_webhook_description() { |
23 | 23 | /* translators: 1) webhook url */ |
24 | - return sprintf( __( 'You must add the following webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::get_webhook_url() ); |
|
24 | + return sprintf(__('You must add the following webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::get_webhook_url()); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | <input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
36 | 36 | <label for="wc-%1$s-new-payment-method" style="display:inline;">%2$s</label> |
37 | 37 | </p>', |
38 | - esc_attr( $this->id ), |
|
39 | - esc_html( apply_filters( 'wc_stripe_save_to_account_text', __( 'Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe' ) ) ) |
|
38 | + esc_attr($this->id), |
|
39 | + esc_html(apply_filters('wc_stripe_save_to_account_text', __('Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe'))) |
|
40 | 40 | ); |
41 | 41 | } |
42 | 42 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @since 4.0.5 |
48 | 48 | * @param array $error |
49 | 49 | */ |
50 | - public function is_retryable_error( $error ) { |
|
50 | + public function is_retryable_error($error) { |
|
51 | 51 | return ( |
52 | 52 | 'invalid_request_error' === $error->type || |
53 | 53 | 'idempotency_error' === $error->type || |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * @since 4.1.0 |
65 | 65 | * @param array $error |
66 | 66 | */ |
67 | - public function is_same_idempotency_error( $error ) { |
|
67 | + public function is_same_idempotency_error($error) { |
|
68 | 68 | return ( |
69 | 69 | $error && |
70 | 70 | 'idempotency_error' === $error->type && |
71 | - preg_match( '/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message ) |
|
71 | + preg_match('/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message) |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | * @since 4.1.0 |
80 | 80 | * @param array $error |
81 | 81 | */ |
82 | - public function is_no_such_customer_error( $error ) { |
|
82 | + public function is_no_such_customer_error($error) { |
|
83 | 83 | return ( |
84 | 84 | $error && |
85 | 85 | 'invalid_request_error' === $error->type && |
86 | - preg_match( '/No such customer/i', $error->message ) |
|
86 | + preg_match('/No such customer/i', $error->message) |
|
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | * @since 4.1.0 |
95 | 95 | * @param array $error |
96 | 96 | */ |
97 | - public function is_no_such_token_error( $error ) { |
|
97 | + public function is_no_such_token_error($error) { |
|
98 | 98 | return ( |
99 | 99 | $error && |
100 | 100 | 'invalid_request_error' === $error->type && |
101 | - preg_match( '/No such token/i', $error->message ) |
|
101 | + preg_match('/No such token/i', $error->message) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | * @since 4.1.0 |
110 | 110 | * @param array $error |
111 | 111 | */ |
112 | - public function is_no_such_source_error( $error ) { |
|
112 | + public function is_no_such_source_error($error) { |
|
113 | 113 | return ( |
114 | 114 | $error && |
115 | 115 | 'invalid_request_error' === $error->type && |
116 | - preg_match( '/No such source/i', $error->message ) |
|
116 | + preg_match('/No such source/i', $error->message) |
|
117 | 117 | ); |
118 | 118 | } |
119 | 119 | |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | * @since 4.1.0 |
125 | 125 | * @param array $error |
126 | 126 | */ |
127 | - public function is_no_linked_source_error( $error ) { |
|
127 | + public function is_no_linked_source_error($error) { |
|
128 | 128 | return ( |
129 | 129 | $error && |
130 | 130 | 'invalid_request_error' === $error->type && |
131 | - preg_match( '/does not have a linked source with ID/i', $error->message ) |
|
131 | + preg_match('/does not have a linked source with ID/i', $error->message) |
|
132 | 132 | ); |
133 | 133 | } |
134 | 134 | |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @param object $error |
142 | 142 | * @return bool |
143 | 143 | */ |
144 | - public function need_update_idempotency_key( $source_object, $error ) { |
|
144 | + public function need_update_idempotency_key($source_object, $error) { |
|
145 | 145 | return ( |
146 | 146 | $error && |
147 | 147 | 1 < $this->retry_interval && |
148 | - ! empty( $source_object ) && |
|
148 | + ! empty($source_object) && |
|
149 | 149 | 'chargeable' === $source_object->status && |
150 | - self::is_same_idempotency_error( $error ) |
|
150 | + self::is_same_idempotency_error($error) |
|
151 | 151 | ); |
152 | 152 | } |
153 | 153 | |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | // NOTE: updates to this function should be added to are_keys_set() |
162 | 162 | // in includes/payment-methods/class-wc-stripe-payment-request.php |
163 | 163 | |
164 | - if ( $this->testmode ) { |
|
165 | - return preg_match( '/^pk_test_/', $this->publishable_key ) |
|
166 | - && preg_match( '/^[rs]k_test_/', $this->secret_key ); |
|
164 | + if ($this->testmode) { |
|
165 | + return preg_match('/^pk_test_/', $this->publishable_key) |
|
166 | + && preg_match('/^[rs]k_test_/', $this->secret_key); |
|
167 | 167 | } else { |
168 | - return preg_match( '/^pk_live_/', $this->publishable_key ) |
|
169 | - && preg_match( '/^[rs]k_live_/', $this->secret_key ); |
|
168 | + return preg_match('/^pk_live_/', $this->publishable_key) |
|
169 | + && preg_match('/^[rs]k_live_/', $this->secret_key); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @since 4.1.3 |
177 | 177 | */ |
178 | 178 | public function is_available() { |
179 | - if ( 'yes' === $this->enabled ) { |
|
179 | + if ('yes' === $this->enabled) { |
|
180 | 180 | return $this->are_keys_set(); |
181 | 181 | } |
182 | 182 | |
@@ -191,12 +191,12 @@ discard block |
||
191 | 191 | * @param int $order_id |
192 | 192 | * @return bool |
193 | 193 | */ |
194 | - public function maybe_process_pre_orders( $order_id ) { |
|
194 | + public function maybe_process_pre_orders($order_id) { |
|
195 | 195 | return ( |
196 | 196 | WC_Stripe_Helper::is_pre_orders_exists() && |
197 | - $this->pre_orders->is_pre_order( $order_id ) && |
|
198 | - WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) && |
|
199 | - ! is_wc_endpoint_url( 'order-pay' ) |
|
197 | + $this->pre_orders->is_pre_order($order_id) && |
|
198 | + WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id) && |
|
199 | + ! is_wc_endpoint_url('order-pay') |
|
200 | 200 | ); |
201 | 201 | } |
202 | 202 | |
@@ -240,10 +240,10 @@ discard block |
||
240 | 240 | * @version 4.0.0 |
241 | 241 | * @param object $order |
242 | 242 | */ |
243 | - public function validate_minimum_order_amount( $order ) { |
|
244 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
243 | + public function validate_minimum_order_amount($order) { |
|
244 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
245 | 245 | /* translators: 1) dollar amount */ |
246 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
246 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
@@ -253,14 +253,14 @@ discard block |
||
253 | 253 | * @since 4.0.0 |
254 | 254 | * @version 4.0.0 |
255 | 255 | */ |
256 | - public function get_transaction_url( $order ) { |
|
257 | - if ( $this->testmode ) { |
|
256 | + public function get_transaction_url($order) { |
|
257 | + if ($this->testmode) { |
|
258 | 258 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
259 | 259 | } else { |
260 | 260 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
261 | 261 | } |
262 | 262 | |
263 | - return parent::get_transaction_url( $order ); |
|
263 | + return parent::get_transaction_url($order); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -269,12 +269,12 @@ discard block |
||
269 | 269 | * @since 4.0.0 |
270 | 270 | * @version 4.0.0 |
271 | 271 | */ |
272 | - public function get_stripe_customer_id( $order ) { |
|
273 | - $customer = get_user_option( '_stripe_customer_id', $order->get_customer_id() ); |
|
272 | + public function get_stripe_customer_id($order) { |
|
273 | + $customer = get_user_option('_stripe_customer_id', $order->get_customer_id()); |
|
274 | 274 | |
275 | - if ( empty( $customer ) ) { |
|
275 | + if (empty($customer)) { |
|
276 | 276 | // Try to get it via the order. |
277 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
277 | + return $order->get_meta('_stripe_customer_id', true); |
|
278 | 278 | } else { |
279 | 279 | return $customer; |
280 | 280 | } |
@@ -290,9 +290,9 @@ discard block |
||
290 | 290 | * @param object $order |
291 | 291 | * @param int $id Stripe session id. |
292 | 292 | */ |
293 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
294 | - if ( is_object( $order ) ) { |
|
295 | - if ( empty( $id ) ) { |
|
293 | + public function get_stripe_return_url($order = null, $id = null) { |
|
294 | + if (is_object($order)) { |
|
295 | + if (empty($id)) { |
|
296 | 296 | $id = uniqid(); |
297 | 297 | } |
298 | 298 | |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | 'order_id' => $order_id, |
304 | 304 | ); |
305 | 305 | |
306 | - return wp_sanitize_redirect( esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ) ); |
|
306 | + return wp_sanitize_redirect(esc_url_raw(add_query_arg($args, $this->get_return_url($order)))); |
|
307 | 307 | } |
308 | 308 | |
309 | - return wp_sanitize_redirect( esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ) ); |
|
309 | + return wp_sanitize_redirect(esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()))); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | * @param int $order_id |
315 | 315 | * @return boolean |
316 | 316 | */ |
317 | - public function has_subscription( $order_id ) { |
|
318 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
317 | + public function has_subscription($order_id) { |
|
318 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -327,41 +327,41 @@ discard block |
||
327 | 327 | * @param object $prepared_source |
328 | 328 | * @return array() |
329 | 329 | */ |
330 | - public function generate_payment_request( $order, $prepared_source ) { |
|
331 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
332 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
333 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
330 | + public function generate_payment_request($order, $prepared_source) { |
|
331 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
332 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
333 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
334 | 334 | $post_data = array(); |
335 | - $post_data['currency'] = strtolower( $order->get_currency() ); |
|
336 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
335 | + $post_data['currency'] = strtolower($order->get_currency()); |
|
336 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
337 | 337 | /* translators: 1) blog name 2) order number */ |
338 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
338 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
339 | 339 | $billing_email = $order->get_billing_email(); |
340 | 340 | $billing_first_name = $order->get_billing_first_name(); |
341 | 341 | $billing_last_name = $order->get_billing_last_name(); |
342 | 342 | |
343 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
343 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
344 | 344 | $post_data['receipt_email'] = $billing_email; |
345 | 345 | } |
346 | 346 | |
347 | - switch ( $order->get_payment_method() ) { |
|
347 | + switch ($order->get_payment_method()) { |
|
348 | 348 | case 'stripe': |
349 | - if ( ! empty( $statement_descriptor ) ) { |
|
350 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
349 | + if ( ! empty($statement_descriptor)) { |
|
350 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | $post_data['capture'] = $capture ? 'true' : 'false'; |
354 | 354 | break; |
355 | 355 | case 'stripe_sepa': |
356 | - if ( ! empty( $statement_descriptor ) ) { |
|
357 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
356 | + if ( ! empty($statement_descriptor)) { |
|
357 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
358 | 358 | } |
359 | 359 | break; |
360 | 360 | } |
361 | 361 | |
362 | - if ( method_exists( $order, 'get_shipping_postcode' ) && ! empty( $order->get_shipping_postcode() ) ) { |
|
362 | + if (method_exists($order, 'get_shipping_postcode') && ! empty($order->get_shipping_postcode())) { |
|
363 | 363 | $post_data['shipping'] = array( |
364 | - 'name' => trim( $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name() ), |
|
364 | + 'name' => trim($order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name()), |
|
365 | 365 | 'address' => array( |
366 | 366 | 'line1' => $order->get_shipping_address_1(), |
367 | 367 | 'line2' => $order->get_shipping_address_2(), |
@@ -376,25 +376,25 @@ discard block |
||
376 | 376 | $post_data['expand[]'] = 'balance_transaction'; |
377 | 377 | |
378 | 378 | $metadata = array( |
379 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
380 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
379 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
380 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
381 | 381 | 'order_id' => $order->get_order_number(), |
382 | - 'site_url' => esc_url( get_site_url() ), |
|
382 | + 'site_url' => esc_url(get_site_url()), |
|
383 | 383 | ); |
384 | 384 | |
385 | - if ( $this->has_subscription( $order->get_id() ) ) { |
|
385 | + if ($this->has_subscription($order->get_id())) { |
|
386 | 386 | $metadata += array( |
387 | 387 | 'payment_type' => 'recurring', |
388 | 388 | ); |
389 | 389 | } |
390 | 390 | |
391 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source ); |
|
391 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source); |
|
392 | 392 | |
393 | - if ( $prepared_source->customer ) { |
|
393 | + if ($prepared_source->customer) { |
|
394 | 394 | $post_data['customer'] = $prepared_source->customer; |
395 | 395 | } |
396 | 396 | |
397 | - if ( $prepared_source->source ) { |
|
397 | + if ($prepared_source->source) { |
|
398 | 398 | $post_data['source'] = $prepared_source->source; |
399 | 399 | } |
400 | 400 | |
@@ -406,72 +406,72 @@ discard block |
||
406 | 406 | * @param WC_Order $order |
407 | 407 | * @param object $source |
408 | 408 | */ |
409 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source ); |
|
409 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
413 | 413 | * Store extra meta data for an order from a Stripe Response. |
414 | 414 | */ |
415 | - public function process_response( $response, $order ) { |
|
416 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
415 | + public function process_response($response, $order) { |
|
416 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
417 | 417 | |
418 | 418 | $order_id = $order->get_id(); |
419 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
419 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
420 | 420 | |
421 | 421 | // Store charge data. |
422 | - $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
422 | + $order->update_meta_data('_stripe_charge_captured', $captured); |
|
423 | 423 | |
424 | - if ( isset( $response->balance_transaction ) ) { |
|
425 | - $this->update_fees( $order, is_string( $response->balance_transaction ) ? $response->balance_transaction : $response->balance_transaction->id ); |
|
424 | + if (isset($response->balance_transaction)) { |
|
425 | + $this->update_fees($order, is_string($response->balance_transaction) ? $response->balance_transaction : $response->balance_transaction->id); |
|
426 | 426 | } |
427 | 427 | |
428 | - if ( 'yes' === $captured ) { |
|
428 | + if ('yes' === $captured) { |
|
429 | 429 | /** |
430 | 430 | * Charge can be captured but in a pending state. Payment methods |
431 | 431 | * that are asynchronous may take couple days to clear. Webhook will |
432 | 432 | * take care of the status changes. |
433 | 433 | */ |
434 | - if ( 'pending' === $response->status ) { |
|
435 | - $order_stock_reduced = $order->get_meta( '_order_stock_reduced', true ); |
|
434 | + if ('pending' === $response->status) { |
|
435 | + $order_stock_reduced = $order->get_meta('_order_stock_reduced', true); |
|
436 | 436 | |
437 | - if ( ! $order_stock_reduced ) { |
|
438 | - wc_reduce_stock_levels( $order_id ); |
|
437 | + if ( ! $order_stock_reduced) { |
|
438 | + wc_reduce_stock_levels($order_id); |
|
439 | 439 | } |
440 | 440 | |
441 | - $order->set_transaction_id( $response->id ); |
|
441 | + $order->set_transaction_id($response->id); |
|
442 | 442 | /* translators: transaction id */ |
443 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
443 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( 'succeeded' === $response->status ) { |
|
447 | - $order->payment_complete( $response->id ); |
|
446 | + if ('succeeded' === $response->status) { |
|
447 | + $order->payment_complete($response->id); |
|
448 | 448 | |
449 | 449 | /* translators: transaction id */ |
450 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
451 | - $order->add_order_note( $message ); |
|
450 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
451 | + $order->add_order_note($message); |
|
452 | 452 | } |
453 | 453 | |
454 | - if ( 'failed' === $response->status ) { |
|
455 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
456 | - $order->add_order_note( $localized_message ); |
|
457 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
454 | + if ('failed' === $response->status) { |
|
455 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
456 | + $order->add_order_note($localized_message); |
|
457 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
458 | 458 | } |
459 | 459 | } else { |
460 | - $order->set_transaction_id( $response->id ); |
|
460 | + $order->set_transaction_id($response->id); |
|
461 | 461 | |
462 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
463 | - wc_reduce_stock_levels( $order_id ); |
|
462 | + if ($order->has_status(array('pending', 'failed'))) { |
|
463 | + wc_reduce_stock_levels($order_id); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /* translators: transaction id */ |
467 | - $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 ) ); |
|
467 | + $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)); |
|
468 | 468 | } |
469 | 469 | |
470 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
470 | + if (is_callable(array($order, 'save'))) { |
|
471 | 471 | $order->save(); |
472 | 472 | } |
473 | 473 | |
474 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
474 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
475 | 475 | |
476 | 476 | return $response; |
477 | 477 | } |
@@ -484,10 +484,10 @@ discard block |
||
484 | 484 | * @param int $order_id |
485 | 485 | * @return null |
486 | 486 | */ |
487 | - public function send_failed_order_email( $order_id ) { |
|
487 | + public function send_failed_order_email($order_id) { |
|
488 | 488 | $emails = WC()->mailer()->get_emails(); |
489 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
490 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
489 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
490 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
491 | 491 | } |
492 | 492 | } |
493 | 493 | |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | * @param object $order |
500 | 500 | * @return object $details |
501 | 501 | */ |
502 | - public function get_owner_details( $order ) { |
|
502 | + public function get_owner_details($order) { |
|
503 | 503 | $billing_first_name = $order->get_billing_first_name(); |
504 | 504 | $billing_last_name = $order->get_billing_last_name(); |
505 | 505 | |
@@ -509,15 +509,15 @@ discard block |
||
509 | 509 | $email = $order->get_billing_email(); |
510 | 510 | $phone = $order->get_billing_phone(); |
511 | 511 | |
512 | - if ( ! empty( $phone ) ) { |
|
512 | + if ( ! empty($phone)) { |
|
513 | 513 | $details['phone'] = $phone; |
514 | 514 | } |
515 | 515 | |
516 | - if ( ! empty( $name ) ) { |
|
516 | + if ( ! empty($name)) { |
|
517 | 517 | $details['name'] = $name; |
518 | 518 | } |
519 | 519 | |
520 | - if ( ! empty( $email ) ) { |
|
520 | + if ( ! empty($email)) { |
|
521 | 521 | $details['email'] = $email; |
522 | 522 | } |
523 | 523 | |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | $details['address']['postal_code'] = $order->get_billing_postcode(); |
529 | 529 | $details['address']['country'] = $order->get_billing_country(); |
530 | 530 | |
531 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
531 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | /** |
@@ -537,15 +537,15 @@ discard block |
||
537 | 537 | * @since 4.0.3 |
538 | 538 | * @param string $source_id The source ID to get source object for. |
539 | 539 | */ |
540 | - public function get_source_object( $source_id = '' ) { |
|
541 | - if ( empty( $source_id ) ) { |
|
540 | + public function get_source_object($source_id = '') { |
|
541 | + if (empty($source_id)) { |
|
542 | 542 | return ''; |
543 | 543 | } |
544 | 544 | |
545 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
545 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
546 | 546 | |
547 | - if ( ! empty( $source_object->error ) ) { |
|
548 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
547 | + if ( ! empty($source_object->error)) { |
|
548 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | return $source_object; |
@@ -558,10 +558,10 @@ discard block |
||
558 | 558 | * @param object $source_object |
559 | 559 | * @return bool |
560 | 560 | */ |
561 | - public function is_prepaid_card( $source_object ) { |
|
561 | + public function is_prepaid_card($source_object) { |
|
562 | 562 | return ( |
563 | 563 | $source_object |
564 | - && ( 'token' === $source_object->object || 'source' === $source_object->object ) |
|
564 | + && ('token' === $source_object->object || 'source' === $source_object->object) |
|
565 | 565 | && 'prepaid' === $source_object->card->funding |
566 | 566 | ); |
567 | 567 | } |
@@ -573,8 +573,8 @@ discard block |
||
573 | 573 | * @param string $source_id |
574 | 574 | * @return bool |
575 | 575 | */ |
576 | - public function is_type_legacy_card( $source_id ) { |
|
577 | - return ( preg_match( '/^card_/', $source_id ) ); |
|
576 | + public function is_type_legacy_card($source_id) { |
|
577 | + return (preg_match('/^card_/', $source_id)); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | /** |
@@ -584,9 +584,9 @@ discard block |
||
584 | 584 | * @return bool |
585 | 585 | */ |
586 | 586 | public function is_using_saved_payment_method() { |
587 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
587 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
588 | 588 | |
589 | - return ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
589 | + return (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
@@ -602,64 +602,64 @@ discard block |
||
602 | 602 | * @throws Exception When card was not added or for and invalid card. |
603 | 603 | * @return object |
604 | 604 | */ |
605 | - public function prepare_source( $user_id, $force_save_source = false, $existing_customer_id = null ) { |
|
606 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
607 | - if ( ! empty( $existing_customer_id ) ) { |
|
608 | - $customer->set_id( $existing_customer_id ); |
|
605 | + public function prepare_source($user_id, $force_save_source = false, $existing_customer_id = null) { |
|
606 | + $customer = new WC_Stripe_Customer($user_id); |
|
607 | + if ( ! empty($existing_customer_id)) { |
|
608 | + $customer->set_id($existing_customer_id); |
|
609 | 609 | } |
610 | 610 | |
611 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
611 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
612 | 612 | $source_object = ''; |
613 | 613 | $source_id = ''; |
614 | 614 | $wc_token_id = false; |
615 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
615 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
616 | 616 | $is_token = false; |
617 | 617 | |
618 | 618 | // New CC info was entered and we have a new source to process. |
619 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
620 | - $source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) ); |
|
619 | + if ( ! empty($_POST['stripe_source'])) { |
|
620 | + $source_object = self::get_source_object(wc_clean($_POST['stripe_source'])); |
|
621 | 621 | $source_id = $source_object->id; |
622 | 622 | |
623 | 623 | // This checks to see if customer opted to save the payment method to file. |
624 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
624 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
625 | 625 | |
626 | 626 | /** |
627 | 627 | * This is true if the user wants to store the card to their account. |
628 | 628 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
629 | 629 | * actually reusable. Either that or force_save_source is true. |
630 | 630 | */ |
631 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
632 | - $response = $customer->add_source( $source_object->id ); |
|
631 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
632 | + $response = $customer->add_source($source_object->id); |
|
633 | 633 | |
634 | - if ( ! empty( $response->error ) ) { |
|
635 | - throw new WC_Stripe_Exception( print_r( $response, true ), $this->get_localized_error_message_from_response( $response ) ); |
|
634 | + if ( ! empty($response->error)) { |
|
635 | + throw new WC_Stripe_Exception(print_r($response, true), $this->get_localized_error_message_from_response($response)); |
|
636 | 636 | } |
637 | 637 | } |
638 | - } elseif ( $this->is_using_saved_payment_method() ) { |
|
638 | + } elseif ($this->is_using_saved_payment_method()) { |
|
639 | 639 | // Use an existing token, and then process the payment. |
640 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
641 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
640 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
641 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
642 | 642 | |
643 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
644 | - WC()->session->set( 'refresh_totals', true ); |
|
645 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
643 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
644 | + WC()->session->set('refresh_totals', true); |
|
645 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | $source_id = $wc_token->get_token(); |
649 | 649 | |
650 | - if ( $this->is_type_legacy_card( $source_id ) ) { |
|
650 | + if ($this->is_type_legacy_card($source_id)) { |
|
651 | 651 | $is_token = true; |
652 | 652 | } |
653 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
654 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
655 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
653 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
654 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
655 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
656 | 656 | |
657 | 657 | // This is true if the user wants to store the card to their account. |
658 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
659 | - $response = $customer->add_source( $stripe_token ); |
|
658 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
659 | + $response = $customer->add_source($stripe_token); |
|
660 | 660 | |
661 | - if ( ! empty( $response->error ) ) { |
|
662 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
661 | + if ( ! empty($response->error)) { |
|
662 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
663 | 663 | } |
664 | 664 | $source_id = $response; |
665 | 665 | } else { |
@@ -669,15 +669,15 @@ discard block |
||
669 | 669 | } |
670 | 670 | |
671 | 671 | $customer_id = $customer->get_id(); |
672 | - if ( ! $customer_id ) { |
|
673 | - $customer->set_id( $customer->create_customer() ); |
|
672 | + if ( ! $customer_id) { |
|
673 | + $customer->set_id($customer->create_customer()); |
|
674 | 674 | $customer_id = $customer->get_id(); |
675 | 675 | } else { |
676 | 676 | $customer_id = $customer->update_customer(); |
677 | 677 | } |
678 | 678 | |
679 | - if ( empty( $source_object ) && ! $is_token ) { |
|
680 | - $source_object = self::get_source_object( $source_id ); |
|
679 | + if (empty($source_object) && ! $is_token) { |
|
680 | + $source_object = self::get_source_object($source_id); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | return (object) array( |
@@ -701,39 +701,39 @@ discard block |
||
701 | 701 | * @param object $order |
702 | 702 | * @return object |
703 | 703 | */ |
704 | - public function prepare_order_source( $order = null ) { |
|
704 | + public function prepare_order_source($order = null) { |
|
705 | 705 | $stripe_customer = new WC_Stripe_Customer(); |
706 | 706 | $stripe_source = false; |
707 | 707 | $token_id = false; |
708 | 708 | $source_object = false; |
709 | 709 | |
710 | - if ( $order ) { |
|
710 | + if ($order) { |
|
711 | 711 | $order_id = $order->get_id(); |
712 | 712 | |
713 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
713 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
714 | 714 | |
715 | - if ( $stripe_customer_id ) { |
|
716 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
715 | + if ($stripe_customer_id) { |
|
716 | + $stripe_customer->set_id($stripe_customer_id); |
|
717 | 717 | } |
718 | 718 | |
719 | - $source_id = $order->get_meta( '_stripe_source_id', true ); |
|
719 | + $source_id = $order->get_meta('_stripe_source_id', true); |
|
720 | 720 | |
721 | 721 | // Since 4.0.0, we changed card to source so we need to account for that. |
722 | - if ( empty( $source_id ) ) { |
|
723 | - $source_id = $order->get_meta( '_stripe_card_id', true ); |
|
722 | + if (empty($source_id)) { |
|
723 | + $source_id = $order->get_meta('_stripe_card_id', true); |
|
724 | 724 | |
725 | 725 | // Take this opportunity to update the key name. |
726 | - $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
726 | + $order->update_meta_data('_stripe_source_id', $source_id); |
|
727 | 727 | |
728 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
728 | + if (is_callable(array($order, 'save'))) { |
|
729 | 729 | $order->save(); |
730 | 730 | } |
731 | 731 | } |
732 | 732 | |
733 | - if ( $source_id ) { |
|
733 | + if ($source_id) { |
|
734 | 734 | $stripe_source = $source_id; |
735 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
736 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
735 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
736 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
737 | 737 | /* |
738 | 738 | * We can attempt to charge the customer's default source |
739 | 739 | * by sending empty source id. |
@@ -758,17 +758,17 @@ discard block |
||
758 | 758 | * @param WC_Order $order For to which the source applies. |
759 | 759 | * @param stdClass $source Source information. |
760 | 760 | */ |
761 | - public function save_source_to_order( $order, $source ) { |
|
761 | + public function save_source_to_order($order, $source) { |
|
762 | 762 | // Store source in the order. |
763 | - if ( $source->customer ) { |
|
764 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
763 | + if ($source->customer) { |
|
764 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
765 | 765 | } |
766 | 766 | |
767 | - if ( $source->source ) { |
|
768 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
767 | + if ($source->source) { |
|
768 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
769 | 769 | } |
770 | 770 | |
771 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
771 | + if (is_callable(array($order, 'save'))) { |
|
772 | 772 | $order->save(); |
773 | 773 | } |
774 | 774 | } |
@@ -782,36 +782,36 @@ discard block |
||
782 | 782 | * @param object $order The order object |
783 | 783 | * @param int $balance_transaction_id |
784 | 784 | */ |
785 | - public function update_fees( $order, $balance_transaction_id ) { |
|
786 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
785 | + public function update_fees($order, $balance_transaction_id) { |
|
786 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
787 | 787 | |
788 | - if ( empty( $balance_transaction->error ) ) { |
|
789 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
788 | + if (empty($balance_transaction->error)) { |
|
789 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
790 | 790 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
791 | 791 | // values are in the local currency of the Stripe account, not from WC. |
792 | - $fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
793 | - $net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
792 | + $fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
793 | + $net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
794 | 794 | |
795 | 795 | // Current data fee & net. |
796 | - $fee_current = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
797 | - $net_current = WC_Stripe_Helper::get_stripe_net( $order ); |
|
796 | + $fee_current = WC_Stripe_Helper::get_stripe_fee($order); |
|
797 | + $net_current = WC_Stripe_Helper::get_stripe_net($order); |
|
798 | 798 | |
799 | 799 | // Calculation. |
800 | 800 | $fee = (float) $fee_current + (float) $fee_refund; |
801 | 801 | $net = (float) $net_current + (float) $net_refund; |
802 | 802 | |
803 | - WC_Stripe_Helper::update_stripe_fee( $order, $fee ); |
|
804 | - WC_Stripe_Helper::update_stripe_net( $order, $net ); |
|
803 | + WC_Stripe_Helper::update_stripe_fee($order, $fee); |
|
804 | + WC_Stripe_Helper::update_stripe_net($order, $net); |
|
805 | 805 | |
806 | - $currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null; |
|
807 | - WC_Stripe_Helper::update_stripe_currency( $order, $currency ); |
|
806 | + $currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null; |
|
807 | + WC_Stripe_Helper::update_stripe_currency($order, $currency); |
|
808 | 808 | |
809 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
809 | + if (is_callable(array($order, 'save'))) { |
|
810 | 810 | $order->save(); |
811 | 811 | } |
812 | 812 | } |
813 | 813 | } else { |
814 | - WC_Stripe_Logger::log( 'Unable to update fees/net meta for order: ' . $order->get_id() ); |
|
814 | + WC_Stripe_Logger::log('Unable to update fees/net meta for order: ' . $order->get_id()); |
|
815 | 815 | } |
816 | 816 | } |
817 | 817 | |
@@ -824,36 +824,36 @@ discard block |
||
824 | 824 | * @param float $amount |
825 | 825 | * @return bool |
826 | 826 | */ |
827 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
828 | - $order = wc_get_order( $order_id ); |
|
827 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
828 | + $order = wc_get_order($order_id); |
|
829 | 829 | |
830 | - if ( ! $order ) { |
|
830 | + if ( ! $order) { |
|
831 | 831 | return false; |
832 | 832 | } |
833 | 833 | |
834 | 834 | $request = array(); |
835 | 835 | |
836 | 836 | $order_currency = $order->get_currency(); |
837 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
837 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
838 | 838 | $charge_id = $order->get_transaction_id(); |
839 | 839 | |
840 | - if ( ! $charge_id ) { |
|
840 | + if ( ! $charge_id) { |
|
841 | 841 | return false; |
842 | 842 | } |
843 | 843 | |
844 | - if ( ! is_null( $amount ) ) { |
|
845 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
844 | + if ( ! is_null($amount)) { |
|
845 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | // If order is only authorized, don't pass amount. |
849 | - if ( 'yes' !== $captured ) { |
|
850 | - unset( $request['amount'] ); |
|
849 | + if ('yes' !== $captured) { |
|
850 | + unset($request['amount']); |
|
851 | 851 | } |
852 | 852 | |
853 | - if ( $reason ) { |
|
853 | + if ($reason) { |
|
854 | 854 | // Trim the refund reason to a max of 500 characters due to Stripe limits: https://stripe.com/docs/api/metadata. |
855 | - if ( strlen( $reason ) > 500 ) { |
|
856 | - $reason = function_exists( 'mb_substr' ) ? mb_substr( $reason, 0, 450 ) : substr( $reason, 0, 450 ); |
|
855 | + if (strlen($reason) > 500) { |
|
856 | + $reason = function_exists('mb_substr') ? mb_substr($reason, 0, 450) : substr($reason, 0, 450); |
|
857 | 857 | // Add some explainer text indicating where to find the full refund reason. |
858 | 858 | $reason = $reason . '... [See WooCommerce order page for full text.]'; |
859 | 859 | } |
@@ -864,60 +864,60 @@ discard block |
||
864 | 864 | } |
865 | 865 | |
866 | 866 | $request['charge'] = $charge_id; |
867 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$charge_id} for the amount of {$amount}" ); |
|
867 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$charge_id} for the amount of {$amount}"); |
|
868 | 868 | |
869 | - $request = apply_filters( 'wc_stripe_refund_request', $request, $order ); |
|
869 | + $request = apply_filters('wc_stripe_refund_request', $request, $order); |
|
870 | 870 | |
871 | - $intent = $this->get_intent_from_order( $order ); |
|
871 | + $intent = $this->get_intent_from_order($order); |
|
872 | 872 | $intent_cancelled = false; |
873 | - if ( $intent ) { |
|
873 | + if ($intent) { |
|
874 | 874 | // If the order has a Payment Intent pending capture, then the Intent itself must be refunded (cancelled), not the Charge |
875 | - if ( ! empty( $intent->error ) ) { |
|
875 | + if ( ! empty($intent->error)) { |
|
876 | 876 | $response = $intent; |
877 | 877 | $intent_cancelled = true; |
878 | - } elseif ( 'requires_capture' === $intent->status ) { |
|
878 | + } elseif ('requires_capture' === $intent->status) { |
|
879 | 879 | $result = WC_Stripe_API::request( |
880 | 880 | array(), |
881 | 881 | 'payment_intents/' . $intent->id . '/cancel' |
882 | 882 | ); |
883 | 883 | $intent_cancelled = true; |
884 | 884 | |
885 | - if ( ! empty( $result->error ) ) { |
|
885 | + if ( ! empty($result->error)) { |
|
886 | 886 | $response = $result; |
887 | 887 | } else { |
888 | - $charge = end( $result->charges->data ); |
|
889 | - $response = end( $charge->refunds->data ); |
|
888 | + $charge = end($result->charges->data); |
|
889 | + $response = end($charge->refunds->data); |
|
890 | 890 | } |
891 | 891 | } |
892 | 892 | } |
893 | 893 | |
894 | - if ( ! $intent_cancelled ) { |
|
895 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
894 | + if ( ! $intent_cancelled) { |
|
895 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
896 | 896 | } |
897 | 897 | |
898 | - if ( ! empty( $response->error ) ) { |
|
899 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
898 | + if ( ! empty($response->error)) { |
|
899 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
900 | 900 | |
901 | 901 | return $response; |
902 | 902 | |
903 | - } elseif ( ! empty( $response->id ) ) { |
|
904 | - $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
903 | + } elseif ( ! empty($response->id)) { |
|
904 | + $order->update_meta_data('_stripe_refund_id', $response->id); |
|
905 | 905 | |
906 | - $amount = wc_price( $response->amount / 100 ); |
|
906 | + $amount = wc_price($response->amount / 100); |
|
907 | 907 | |
908 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
909 | - $amount = wc_price( $response->amount ); |
|
908 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
909 | + $amount = wc_price($response->amount); |
|
910 | 910 | } |
911 | 911 | |
912 | - if ( isset( $response->balance_transaction ) ) { |
|
913 | - $this->update_fees( $order, $response->balance_transaction ); |
|
912 | + if (isset($response->balance_transaction)) { |
|
913 | + $this->update_fees($order, $response->balance_transaction); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
917 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
917 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
918 | 918 | |
919 | - $order->add_order_note( $refund_message ); |
|
920 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) ); |
|
919 | + $order->add_order_note($refund_message); |
|
920 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message))); |
|
921 | 921 | |
922 | 922 | return true; |
923 | 923 | } |
@@ -932,46 +932,46 @@ discard block |
||
932 | 932 | */ |
933 | 933 | public function add_payment_method() { |
934 | 934 | $error = false; |
935 | - $error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' ); |
|
935 | + $error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe'); |
|
936 | 936 | $source_id = ''; |
937 | 937 | |
938 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
938 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
939 | 939 | $error = true; |
940 | 940 | } |
941 | 941 | |
942 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
942 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
943 | 943 | |
944 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
944 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
945 | 945 | |
946 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
946 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
947 | 947 | |
948 | - if ( isset( $source_object ) ) { |
|
949 | - if ( ! empty( $source_object->error ) ) { |
|
948 | + if (isset($source_object)) { |
|
949 | + if ( ! empty($source_object->error)) { |
|
950 | 950 | $error = true; |
951 | 951 | } |
952 | 952 | |
953 | 953 | $source_id = $source_object->id; |
954 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
955 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
954 | + } elseif (isset($_POST['stripe_token'])) { |
|
955 | + $source_id = wc_clean($_POST['stripe_token']); |
|
956 | 956 | } |
957 | 957 | |
958 | - $response = $stripe_customer->add_source( $source_id ); |
|
958 | + $response = $stripe_customer->add_source($source_id); |
|
959 | 959 | |
960 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
960 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
961 | 961 | $error = true; |
962 | 962 | } |
963 | 963 | |
964 | - if ( $error ) { |
|
965 | - wc_add_notice( $error_msg, 'error' ); |
|
966 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
964 | + if ($error) { |
|
965 | + wc_add_notice($error_msg, 'error'); |
|
966 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
967 | 967 | return; |
968 | 968 | } |
969 | 969 | |
970 | - do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object ); |
|
970 | + do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object); |
|
971 | 971 | |
972 | 972 | return array( |
973 | 973 | 'result' => 'success', |
974 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
974 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
975 | 975 | ); |
976 | 976 | } |
977 | 977 | |
@@ -988,10 +988,10 @@ discard block |
||
988 | 988 | * Stripe expects Norwegian to only be passed NO. |
989 | 989 | * But WP has different dialects. |
990 | 990 | */ |
991 | - if ( 'NO' === substr( $locale, 3, 2 ) ) { |
|
991 | + if ('NO' === substr($locale, 3, 2)) { |
|
992 | 992 | $locale = 'no'; |
993 | 993 | } else { |
994 | - $locale = substr( get_locale(), 0, 2 ); |
|
994 | + $locale = substr(get_locale(), 0, 2); |
|
995 | 995 | } |
996 | 996 | |
997 | 997 | return $locale; |
@@ -1005,9 +1005,9 @@ discard block |
||
1005 | 1005 | * @param string $idempotency_key |
1006 | 1006 | * @param array $request |
1007 | 1007 | */ |
1008 | - public function change_idempotency_key( $idempotency_key, $request ) { |
|
1009 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
1010 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
1008 | + public function change_idempotency_key($idempotency_key, $request) { |
|
1009 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
1010 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
1011 | 1011 | $count = $this->retry_interval; |
1012 | 1012 | |
1013 | 1013 | return $request['metadata']['order_id'] . '-' . $count . '-' . $source; |
@@ -1021,8 +1021,8 @@ discard block |
||
1021 | 1021 | * @since 4.0.6 |
1022 | 1022 | * @param array $headers |
1023 | 1023 | */ |
1024 | - public function is_original_request( $headers ) { |
|
1025 | - if ( $headers['original-request'] === $headers['request-id'] ) { |
|
1024 | + public function is_original_request($headers) { |
|
1025 | + if ($headers['original-request'] === $headers['request-id']) { |
|
1026 | 1026 | return true; |
1027 | 1027 | } |
1028 | 1028 | |
@@ -1036,31 +1036,31 @@ discard block |
||
1036 | 1036 | * @param object $prepared_source The source that is used for the payment. |
1037 | 1037 | * @return array The arguments for the request. |
1038 | 1038 | */ |
1039 | - public function generate_create_intent_request( $order, $prepared_source ) { |
|
1039 | + public function generate_create_intent_request($order, $prepared_source) { |
|
1040 | 1040 | // The request for a charge contains metadata for the intent. |
1041 | - $full_request = $this->generate_payment_request( $order, $prepared_source ); |
|
1041 | + $full_request = $this->generate_payment_request($order, $prepared_source); |
|
1042 | 1042 | |
1043 | 1043 | $request = array( |
1044 | 1044 | 'source' => $prepared_source->source, |
1045 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ), |
|
1046 | - 'currency' => strtolower( $order->get_currency() ), |
|
1045 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()), |
|
1046 | + 'currency' => strtolower($order->get_currency()), |
|
1047 | 1047 | 'description' => $full_request['description'], |
1048 | 1048 | 'metadata' => $full_request['metadata'], |
1049 | - 'capture_method' => ( 'true' === $full_request['capture'] ) ? 'automatic' : 'manual', |
|
1049 | + 'capture_method' => ('true' === $full_request['capture']) ? 'automatic' : 'manual', |
|
1050 | 1050 | 'payment_method_types' => array( |
1051 | 1051 | 'card', |
1052 | 1052 | ), |
1053 | 1053 | ); |
1054 | 1054 | |
1055 | - if ( $prepared_source->customer ) { |
|
1055 | + if ($prepared_source->customer) { |
|
1056 | 1056 | $request['customer'] = $prepared_source->customer; |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - if ( isset( $full_request['statement_descriptor'] ) ) { |
|
1059 | + if (isset($full_request['statement_descriptor'])) { |
|
1060 | 1060 | $request['statement_descriptor'] = $full_request['statement_descriptor']; |
1061 | 1061 | } |
1062 | 1062 | |
1063 | - if ( isset( $full_request['shipping'] ) ) { |
|
1063 | + if (isset($full_request['shipping'])) { |
|
1064 | 1064 | $request['shipping'] = $full_request['shipping']; |
1065 | 1065 | } |
1066 | 1066 | |
@@ -1072,7 +1072,7 @@ discard block |
||
1072 | 1072 | * @param WC_Order $order |
1073 | 1073 | * @param object $source |
1074 | 1074 | */ |
1075 | - return apply_filters( 'wc_stripe_generate_create_intent_request', $request, $order, $prepared_source ); |
|
1075 | + return apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | 1078 | /** |
@@ -1081,27 +1081,27 @@ discard block |
||
1081 | 1081 | * @param WC_Order $order The order that is being paid for. |
1082 | 1082 | * @return array The level 3 data to send to Stripe. |
1083 | 1083 | */ |
1084 | - public function get_level3_data_from_order( $order ) { |
|
1084 | + public function get_level3_data_from_order($order) { |
|
1085 | 1085 | // Get the order items. Don't need their keys, only their values. |
1086 | 1086 | // Order item IDs are used as keys in the original order items array. |
1087 | - $order_items = array_values( $order->get_items( [ 'line_item', 'fee' ] ) ); |
|
1087 | + $order_items = array_values($order->get_items(['line_item', 'fee'])); |
|
1088 | 1088 | $currency = $order->get_currency(); |
1089 | 1089 | |
1090 | - $stripe_line_items = array_map( function( $item ) use ( $currency ) { |
|
1091 | - if ( is_a( $item, 'WC_Order_Item_Product' ) ) { |
|
1090 | + $stripe_line_items = array_map(function($item) use ($currency) { |
|
1091 | + if (is_a($item, 'WC_Order_Item_Product')) { |
|
1092 | 1092 | $product_id = $item->get_variation_id() |
1093 | 1093 | ? $item->get_variation_id() |
1094 | 1094 | : $item->get_product_id(); |
1095 | 1095 | $subtotal = $item->get_subtotal(); |
1096 | 1096 | } else { |
1097 | - $product_id = substr( sanitize_title( $item->get_name() ), 0, 12 ); |
|
1097 | + $product_id = substr(sanitize_title($item->get_name()), 0, 12); |
|
1098 | 1098 | $subtotal = $item->get_total(); |
1099 | 1099 | } |
1100 | - $product_description = substr( $item->get_name(), 0, 26 ); |
|
1100 | + $product_description = substr($item->get_name(), 0, 26); |
|
1101 | 1101 | $quantity = $item->get_quantity(); |
1102 | - $unit_cost = WC_Stripe_Helper::get_stripe_amount( ( $subtotal / $quantity ), $currency ); |
|
1103 | - $tax_amount = WC_Stripe_Helper::get_stripe_amount( $item->get_total_tax(), $currency ); |
|
1104 | - $discount_amount = WC_Stripe_Helper::get_stripe_amount( $subtotal - $item->get_total(), $currency ); |
|
1102 | + $unit_cost = WC_Stripe_Helper::get_stripe_amount(($subtotal / $quantity), $currency); |
|
1103 | + $tax_amount = WC_Stripe_Helper::get_stripe_amount($item->get_total_tax(), $currency); |
|
1104 | + $discount_amount = WC_Stripe_Helper::get_stripe_amount($subtotal - $item->get_total(), $currency); |
|
1105 | 1105 | |
1106 | 1106 | return (object) array( |
1107 | 1107 | 'product_code' => (string) $product_id, // Up to 12 characters that uniquely identify the product. |
@@ -1115,19 +1115,19 @@ discard block |
||
1115 | 1115 | |
1116 | 1116 | $level3_data = array( |
1117 | 1117 | 'merchant_reference' => $order->get_id(), // An alphanumeric string of up to characters in length. This unique value is assigned by the merchant to identify the order. Also known as an “Order ID”. |
1118 | - 'shipping_amount' => WC_Stripe_Helper::get_stripe_amount( (float) $order->get_shipping_total() + (float) $order->get_shipping_tax(), $currency), // The shipping cost, in cents, as a non-negative integer. |
|
1118 | + 'shipping_amount' => WC_Stripe_Helper::get_stripe_amount((float) $order->get_shipping_total() + (float) $order->get_shipping_tax(), $currency), // The shipping cost, in cents, as a non-negative integer. |
|
1119 | 1119 | 'line_items' => $stripe_line_items, |
1120 | 1120 | ); |
1121 | 1121 | |
1122 | 1122 | // The customer’s U.S. shipping ZIP code. |
1123 | 1123 | $shipping_address_zip = $order->get_shipping_postcode(); |
1124 | - if ( $this->is_valid_us_zip_code( $shipping_address_zip ) ) { |
|
1124 | + if ($this->is_valid_us_zip_code($shipping_address_zip)) { |
|
1125 | 1125 | $level3_data['shipping_address_zip'] = $shipping_address_zip; |
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | // The merchant’s U.S. shipping ZIP code. |
1129 | - $store_postcode = get_option( 'woocommerce_store_postcode' ); |
|
1130 | - if ( $this->is_valid_us_zip_code( $store_postcode ) ) { |
|
1129 | + $store_postcode = get_option('woocommerce_store_postcode'); |
|
1130 | + if ($this->is_valid_us_zip_code($store_postcode)) { |
|
1131 | 1131 | $level3_data['shipping_from_zip'] = $store_postcode; |
1132 | 1132 | } |
1133 | 1133 | |
@@ -1141,20 +1141,20 @@ discard block |
||
1141 | 1141 | * @param object $prepared_source The source that is used for the payment. |
1142 | 1142 | * @return object An intent or an error. |
1143 | 1143 | */ |
1144 | - public function create_intent( $order, $prepared_source ) { |
|
1145 | - $request = $this->generate_create_intent_request( $order, $prepared_source ); |
|
1144 | + public function create_intent($order, $prepared_source) { |
|
1145 | + $request = $this->generate_create_intent_request($order, $prepared_source); |
|
1146 | 1146 | |
1147 | 1147 | // Create an intent that awaits an action. |
1148 | - $intent = WC_Stripe_API::request( $request, 'payment_intents' ); |
|
1149 | - if ( ! empty( $intent->error ) ) { |
|
1148 | + $intent = WC_Stripe_API::request($request, 'payment_intents'); |
|
1149 | + if ( ! empty($intent->error)) { |
|
1150 | 1150 | return $intent; |
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | $order_id = $order->get_id(); |
1154 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id initiated for order $order_id" ); |
|
1154 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id initiated for order $order_id"); |
|
1155 | 1155 | |
1156 | 1156 | // Save the intent ID to the order. |
1157 | - $this->save_intent_to_order( $order, $intent ); |
|
1157 | + $this->save_intent_to_order($order, $intent); |
|
1158 | 1158 | |
1159 | 1159 | return $intent; |
1160 | 1160 | } |
@@ -1167,33 +1167,33 @@ discard block |
||
1167 | 1167 | * @param object $prepared_source Currently selected source. |
1168 | 1168 | * @return object An updated intent. |
1169 | 1169 | */ |
1170 | - public function update_existing_intent( $intent, $order, $prepared_source ) { |
|
1170 | + public function update_existing_intent($intent, $order, $prepared_source) { |
|
1171 | 1171 | $request = array(); |
1172 | 1172 | |
1173 | - if ( $prepared_source->source !== $intent->source ) { |
|
1173 | + if ($prepared_source->source !== $intent->source) { |
|
1174 | 1174 | $request['source'] = $prepared_source->source; |
1175 | 1175 | } |
1176 | 1176 | |
1177 | - $new_amount = WC_Stripe_Helper::get_stripe_amount( $order->get_total() ); |
|
1178 | - if ( $intent->amount !== $new_amount ) { |
|
1177 | + $new_amount = WC_Stripe_Helper::get_stripe_amount($order->get_total()); |
|
1178 | + if ($intent->amount !== $new_amount) { |
|
1179 | 1179 | $request['amount'] = $new_amount; |
1180 | 1180 | } |
1181 | 1181 | |
1182 | - if ( $prepared_source->customer && $intent->customer !== $prepared_source->customer ) { |
|
1182 | + if ($prepared_source->customer && $intent->customer !== $prepared_source->customer) { |
|
1183 | 1183 | $request['customer'] = $prepared_source->customer; |
1184 | 1184 | } |
1185 | 1185 | |
1186 | - if ( $this->has_subscription( $order ) ) { |
|
1186 | + if ($this->has_subscription($order)) { |
|
1187 | 1187 | // If this is a failed subscription order payment, the intent should be |
1188 | 1188 | // prepared for future usage. |
1189 | 1189 | $request['setup_future_usage'] = 'off_session'; |
1190 | 1190 | } |
1191 | 1191 | |
1192 | - if ( empty( $request ) ) { |
|
1192 | + if (empty($request)) { |
|
1193 | 1193 | return $intent; |
1194 | 1194 | } |
1195 | 1195 | |
1196 | - $level3_data = $this->get_level3_data_from_order( $order ); |
|
1196 | + $level3_data = $this->get_level3_data_from_order($order); |
|
1197 | 1197 | return WC_Stripe_API::request_with_level3_data( |
1198 | 1198 | $request, |
1199 | 1199 | "payment_intents/$intent->id", |
@@ -1211,8 +1211,8 @@ discard block |
||
1211 | 1211 | * @param object $prepared_source The source that is being charged. |
1212 | 1212 | * @return object Either an error or the updated intent. |
1213 | 1213 | */ |
1214 | - public function confirm_intent( $intent, $order, $prepared_source ) { |
|
1215 | - if ( 'requires_confirmation' !== $intent->status ) { |
|
1214 | + public function confirm_intent($intent, $order, $prepared_source) { |
|
1215 | + if ('requires_confirmation' !== $intent->status) { |
|
1216 | 1216 | return $intent; |
1217 | 1217 | } |
1218 | 1218 | |
@@ -1221,7 +1221,7 @@ discard block |
||
1221 | 1221 | 'source' => $prepared_source->source, |
1222 | 1222 | ); |
1223 | 1223 | |
1224 | - $level3_data = $this->get_level3_data_from_order( $order ); |
|
1224 | + $level3_data = $this->get_level3_data_from_order($order); |
|
1225 | 1225 | $confirmed_intent = WC_Stripe_API::request_with_level3_data( |
1226 | 1226 | $confirm_request, |
1227 | 1227 | "payment_intents/$intent->id/confirm", |
@@ -1229,16 +1229,16 @@ discard block |
||
1229 | 1229 | $order |
1230 | 1230 | ); |
1231 | 1231 | |
1232 | - if ( ! empty( $confirmed_intent->error ) ) { |
|
1232 | + if ( ! empty($confirmed_intent->error)) { |
|
1233 | 1233 | return $confirmed_intent; |
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | // Save a note about the status of the intent. |
1237 | 1237 | $order_id = $order->get_id(); |
1238 | - if ( 'succeeded' === $confirmed_intent->status ) { |
|
1239 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" ); |
|
1240 | - } elseif ( 'requires_action' === $confirmed_intent->status ) { |
|
1241 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id requires authentication for order $order_id" ); |
|
1238 | + if ('succeeded' === $confirmed_intent->status) { |
|
1239 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id"); |
|
1240 | + } elseif ('requires_action' === $confirmed_intent->status) { |
|
1241 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id requires authentication for order $order_id"); |
|
1242 | 1242 | } |
1243 | 1243 | |
1244 | 1244 | return $confirmed_intent; |
@@ -1251,10 +1251,10 @@ discard block |
||
1251 | 1251 | * @param WC_Order $order For to which the source applies. |
1252 | 1252 | * @param stdClass $intent Payment intent information. |
1253 | 1253 | */ |
1254 | - public function save_intent_to_order( $order, $intent ) { |
|
1255 | - $order->update_meta_data( '_stripe_intent_id', $intent->id ); |
|
1254 | + public function save_intent_to_order($order, $intent) { |
|
1255 | + $order->update_meta_data('_stripe_intent_id', $intent->id); |
|
1256 | 1256 | |
1257 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
1257 | + if (is_callable(array($order, 'save'))) { |
|
1258 | 1258 | $order->save(); |
1259 | 1259 | } |
1260 | 1260 | } |
@@ -1266,18 +1266,18 @@ discard block |
||
1266 | 1266 | * @param WC_Order $order The order to retrieve an intent for. |
1267 | 1267 | * @return obect|bool Either the intent object or `false`. |
1268 | 1268 | */ |
1269 | - public function get_intent_from_order( $order ) { |
|
1270 | - $intent_id = $order->get_meta( '_stripe_intent_id' ); |
|
1269 | + public function get_intent_from_order($order) { |
|
1270 | + $intent_id = $order->get_meta('_stripe_intent_id'); |
|
1271 | 1271 | |
1272 | - if ( $intent_id ) { |
|
1273 | - return $this->get_intent( 'payment_intents', $intent_id ); |
|
1272 | + if ($intent_id) { |
|
1273 | + return $this->get_intent('payment_intents', $intent_id); |
|
1274 | 1274 | } |
1275 | 1275 | |
1276 | 1276 | // The order doesn't have a payment intent, but it may have a setup intent. |
1277 | - $intent_id = $order->get_meta( '_stripe_setup_intent' ); |
|
1277 | + $intent_id = $order->get_meta('_stripe_setup_intent'); |
|
1278 | 1278 | |
1279 | - if ( $intent_id ) { |
|
1280 | - return $this->get_intent( 'setup_intents', $intent_id ); |
|
1279 | + if ($intent_id) { |
|
1280 | + return $this->get_intent('setup_intents', $intent_id); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | 1283 | return false; |
@@ -1291,15 +1291,15 @@ discard block |
||
1291 | 1291 | * @return object|bool Either the intent object or `false`. |
1292 | 1292 | * @throws Exception Throws exception for unknown $intent_type. |
1293 | 1293 | */ |
1294 | - private function get_intent( $intent_type, $intent_id ) { |
|
1295 | - if ( ! in_array( $intent_type, [ 'payment_intents', 'setup_intents' ] ) ) { |
|
1296 | - throw new Exception( "Failed to get intent of type $intent_type. Type is not allowed" ); |
|
1294 | + private function get_intent($intent_type, $intent_id) { |
|
1295 | + if ( ! in_array($intent_type, ['payment_intents', 'setup_intents'])) { |
|
1296 | + throw new Exception("Failed to get intent of type $intent_type. Type is not allowed"); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | - $response = WC_Stripe_API::request( array(), "$intent_type/$intent_id", 'GET' ); |
|
1299 | + $response = WC_Stripe_API::request(array(), "$intent_type/$intent_id", 'GET'); |
|
1300 | 1300 | |
1301 | - if ( $response && isset( $response->{ 'error' } ) ) { |
|
1302 | - $error_response_message = print_r( $response, true ); |
|
1301 | + if ($response && isset($response->{ 'error' } )) { |
|
1302 | + $error_response_message = print_r($response, true); |
|
1303 | 1303 | WC_Stripe_Logger::log("Failed to get Stripe intent $intent_type/$intent_id."); |
1304 | 1304 | WC_Stripe_Logger::log("Response: $error_response_message"); |
1305 | 1305 | return false; |
@@ -1316,18 +1316,18 @@ discard block |
||
1316 | 1316 | * @param stdClass $intent The intent that is being processed. |
1317 | 1317 | * @return bool A flag that indicates whether the order is already locked. |
1318 | 1318 | */ |
1319 | - public function lock_order_payment( $order, $intent = null ) { |
|
1319 | + public function lock_order_payment($order, $intent = null) { |
|
1320 | 1320 | $order_id = $order->get_id(); |
1321 | 1321 | $transient_name = 'wc_stripe_processing_intent_' . $order_id; |
1322 | - $processing = get_transient( $transient_name ); |
|
1322 | + $processing = get_transient($transient_name); |
|
1323 | 1323 | |
1324 | 1324 | // Block the process if the same intent is already being handled. |
1325 | - if ( "-1" === $processing || ( isset( $intent->id ) && $processing === $intent->id ) ) { |
|
1325 | + if ("-1" === $processing || (isset($intent->id) && $processing === $intent->id)) { |
|
1326 | 1326 | return true; |
1327 | 1327 | } |
1328 | 1328 | |
1329 | 1329 | // Save the new intent as a transient, eventually overwriting another one. |
1330 | - set_transient( $transient_name, empty( $intent ) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS ); |
|
1330 | + set_transient($transient_name, empty($intent) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS); |
|
1331 | 1331 | |
1332 | 1332 | return false; |
1333 | 1333 | } |
@@ -1338,9 +1338,9 @@ discard block |
||
1338 | 1338 | * @since 4.2 |
1339 | 1339 | * @param WC_Order $order The order that is being unlocked. |
1340 | 1340 | */ |
1341 | - public function unlock_order_payment( $order ) { |
|
1341 | + public function unlock_order_payment($order) { |
|
1342 | 1342 | $order_id = $order->get_id(); |
1343 | - delete_transient( 'wc_stripe_processing_intent_' . $order_id ); |
|
1343 | + delete_transient('wc_stripe_processing_intent_' . $order_id); |
|
1344 | 1344 | } |
1345 | 1345 | |
1346 | 1346 | /** |
@@ -1350,9 +1350,9 @@ discard block |
||
1350 | 1350 | * @param object $response The response from Stripe. |
1351 | 1351 | * @return boolean Whether or not it's a 'authentication_required' error |
1352 | 1352 | */ |
1353 | - public function is_authentication_required_for_payment( $response ) { |
|
1354 | - return ( ! empty( $response->error ) && 'authentication_required' === $response->error->code ) |
|
1355 | - || ( ! empty( $response->last_payment_error ) && 'authentication_required' === $response->last_payment_error->code ); |
|
1353 | + public function is_authentication_required_for_payment($response) { |
|
1354 | + return ( ! empty($response->error) && 'authentication_required' === $response->error->code) |
|
1355 | + || ( ! empty($response->last_payment_error) && 'authentication_required' === $response->last_payment_error->code); |
|
1356 | 1356 | } |
1357 | 1357 | |
1358 | 1358 | /** |
@@ -1362,18 +1362,18 @@ discard block |
||
1362 | 1362 | * @param object $prepared_source The source, entered/chosen by the customer. |
1363 | 1363 | * @return string The client secret of the intent, used for confirmation in JS. |
1364 | 1364 | */ |
1365 | - public function setup_intent( $order, $prepared_source ) { |
|
1365 | + public function setup_intent($order, $prepared_source) { |
|
1366 | 1366 | $order_id = $order->get_id(); |
1367 | - $setup_intent = WC_Stripe_API::request( array( |
|
1367 | + $setup_intent = WC_Stripe_API::request(array( |
|
1368 | 1368 | 'payment_method' => $prepared_source->source, |
1369 | 1369 | 'customer' => $prepared_source->customer, |
1370 | 1370 | 'confirm' => 'true', |
1371 | - ), 'setup_intents' ); |
|
1371 | + ), 'setup_intents'); |
|
1372 | 1372 | |
1373 | - if ( is_wp_error( $setup_intent ) ) { |
|
1374 | - WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) ); |
|
1375 | - } elseif ( 'requires_action' === $setup_intent->status ) { |
|
1376 | - $order->update_meta_data( '_stripe_setup_intent', $setup_intent->id ); |
|
1373 | + if (is_wp_error($setup_intent)) { |
|
1374 | + WC_Stripe_Logger::log("Unable to create SetupIntent for Order #$order_id: " . print_r($setup_intent, true)); |
|
1375 | + } elseif ('requires_action' === $setup_intent->status) { |
|
1376 | + $order->update_meta_data('_stripe_setup_intent', $setup_intent->id); |
|
1377 | 1377 | $order->save(); |
1378 | 1378 | |
1379 | 1379 | return $setup_intent->client_secret; |
@@ -1388,12 +1388,12 @@ discard block |
||
1388 | 1388 | * @param float $amount The amount to charge. If not specified, it will be read from the order. |
1389 | 1389 | * @return object An intent or an error. |
1390 | 1390 | */ |
1391 | - public function create_and_confirm_intent_for_off_session( $order, $prepared_source, $amount = NULL ) { |
|
1391 | + public function create_and_confirm_intent_for_off_session($order, $prepared_source, $amount = NULL) { |
|
1392 | 1392 | // The request for a charge contains metadata for the intent. |
1393 | - $full_request = $this->generate_payment_request( $order, $prepared_source ); |
|
1393 | + $full_request = $this->generate_payment_request($order, $prepared_source); |
|
1394 | 1394 | |
1395 | 1395 | $request = array( |
1396 | - 'amount' => $amount ? WC_Stripe_Helper::get_stripe_amount( $amount, $full_request['currency'] ) : $full_request['amount'], |
|
1396 | + 'amount' => $amount ? WC_Stripe_Helper::get_stripe_amount($amount, $full_request['currency']) : $full_request['amount'], |
|
1397 | 1397 | 'currency' => $full_request['currency'], |
1398 | 1398 | 'description' => $full_request['description'], |
1399 | 1399 | 'metadata' => $full_request['metadata'], |
@@ -1405,17 +1405,17 @@ discard block |
||
1405 | 1405 | 'confirmation_method' => 'automatic', |
1406 | 1406 | ); |
1407 | 1407 | |
1408 | - if ( isset( $full_request['statement_descriptor'] ) ) { |
|
1408 | + if (isset($full_request['statement_descriptor'])) { |
|
1409 | 1409 | $request['statement_descriptor'] = $full_request['statement_descriptor']; |
1410 | 1410 | } |
1411 | 1411 | |
1412 | - if ( isset( $full_request['customer'] ) ) { |
|
1412 | + if (isset($full_request['customer'])) { |
|
1413 | 1413 | $request['customer'] = $full_request['customer']; |
1414 | 1414 | } |
1415 | 1415 | |
1416 | - if ( isset( $full_request['source'] ) ) { |
|
1417 | - $is_source = 'src_' === substr( $full_request['source'], 0, 4 ); |
|
1418 | - $request[ $is_source ? 'source' : 'payment_method' ] = $full_request['source']; |
|
1416 | + if (isset($full_request['source'])) { |
|
1417 | + $is_source = 'src_' === substr($full_request['source'], 0, 4); |
|
1418 | + $request[$is_source ? 'source' : 'payment_method'] = $full_request['source']; |
|
1419 | 1419 | } |
1420 | 1420 | |
1421 | 1421 | /** |
@@ -1426,38 +1426,38 @@ discard block |
||
1426 | 1426 | * @param WC_Order $order |
1427 | 1427 | * @param object $source |
1428 | 1428 | */ |
1429 | - $request = apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source ); |
|
1429 | + $request = apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source); |
|
1430 | 1430 | |
1431 | - if ( isset( $full_request['shipping'] ) ) { |
|
1431 | + if (isset($full_request['shipping'])) { |
|
1432 | 1432 | $request['shipping'] = $full_request['shipping']; |
1433 | 1433 | } |
1434 | 1434 | |
1435 | - $level3_data = $this->get_level3_data_from_order( $order ); |
|
1435 | + $level3_data = $this->get_level3_data_from_order($order); |
|
1436 | 1436 | $intent = WC_Stripe_API::request_with_level3_data( |
1437 | 1437 | $request, |
1438 | 1438 | 'payment_intents', |
1439 | 1439 | $level3_data, |
1440 | 1440 | $order |
1441 | 1441 | ); |
1442 | - $is_authentication_required = $this->is_authentication_required_for_payment( $intent ); |
|
1442 | + $is_authentication_required = $this->is_authentication_required_for_payment($intent); |
|
1443 | 1443 | |
1444 | - if ( ! empty( $intent->error ) && ! $is_authentication_required ) { |
|
1444 | + if ( ! empty($intent->error) && ! $is_authentication_required) { |
|
1445 | 1445 | return $intent; |
1446 | 1446 | } |
1447 | 1447 | |
1448 | - $intent_id = ( ! empty( $intent->error ) |
|
1448 | + $intent_id = ( ! empty($intent->error) |
|
1449 | 1449 | ? $intent->error->payment_intent->id |
1450 | 1450 | : $intent->id |
1451 | 1451 | ); |
1452 | - $payment_intent = ( ! empty( $intent->error ) |
|
1452 | + $payment_intent = ( ! empty($intent->error) |
|
1453 | 1453 | ? $intent->error->payment_intent |
1454 | 1454 | : $intent |
1455 | 1455 | ); |
1456 | - $order_id = $order->get_id(); |
|
1457 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent_id initiated for order $order_id" ); |
|
1456 | + $order_id = $order->get_id(); |
|
1457 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent_id initiated for order $order_id"); |
|
1458 | 1458 | |
1459 | 1459 | // Save the intent ID to the order. |
1460 | - $this->save_intent_to_order( $order, $payment_intent ); |
|
1460 | + $this->save_intent_to_order($order, $payment_intent); |
|
1461 | 1461 | |
1462 | 1462 | return $intent; |
1463 | 1463 | } |
@@ -1468,13 +1468,13 @@ discard block |
||
1468 | 1468 | * Fix renewal for existing subscriptions affected by https://github.com/woocommerce/woocommerce-gateway-stripe/issues/1072. |
1469 | 1469 | * @param int $order_id subscription renewal order id. |
1470 | 1470 | */ |
1471 | - public function ensure_subscription_has_customer_id( $order_id ) { |
|
1472 | - $subscriptions_ids = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => 'any' ) ); |
|
1473 | - foreach( $subscriptions_ids as $subscription_id => $subscription ) { |
|
1474 | - if ( ! metadata_exists( 'post', $subscription_id, '_stripe_customer_id' ) ) { |
|
1475 | - $stripe_customer = new WC_Stripe_Customer( $subscription->get_user_id() ); |
|
1476 | - update_post_meta( $subscription_id, '_stripe_customer_id', $stripe_customer->get_id() ); |
|
1477 | - update_post_meta( $order_id, '_stripe_customer_id', $stripe_customer->get_id() ); |
|
1471 | + public function ensure_subscription_has_customer_id($order_id) { |
|
1472 | + $subscriptions_ids = wcs_get_subscriptions_for_order($order_id, array('order_type' => 'any')); |
|
1473 | + foreach ($subscriptions_ids as $subscription_id => $subscription) { |
|
1474 | + if ( ! metadata_exists('post', $subscription_id, '_stripe_customer_id')) { |
|
1475 | + $stripe_customer = new WC_Stripe_Customer($subscription->get_user_id()); |
|
1476 | + update_post_meta($subscription_id, '_stripe_customer_id', $stripe_customer->get_id()); |
|
1477 | + update_post_meta($order_id, '_stripe_customer_id', $stripe_customer->get_id()); |
|
1478 | 1478 | } |
1479 | 1479 | } |
1480 | 1480 | } |
@@ -1484,7 +1484,7 @@ discard block |
||
1484 | 1484 | * @param string $zip The ZIP code to verify. |
1485 | 1485 | * @return boolean |
1486 | 1486 | */ |
1487 | - public function is_valid_us_zip_code( $zip ) { |
|
1488 | - return ! empty( $zip ) && preg_match( '/^\d{5,5}(-\d{4,4})?$/', $zip ); |
|
1487 | + public function is_valid_us_zip_code($zip) { |
|
1488 | + return ! empty($zip) && preg_match('/^\d{5,5}(-\d{4,4})?$/', $zip); |
|
1489 | 1489 | } |
1490 | 1490 | } |
@@ -1,19 +1,19 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -if ( woocommerce_gateway_stripe()->connect->is_connected() ) { |
|
6 | +if (woocommerce_gateway_stripe()->connect->is_connected()) { |
|
7 | 7 | $reset_link = add_query_arg( |
8 | 8 | array( |
9 | - '_wpnonce' => wp_create_nonce( 'reset_stripe_api_credentials' ), |
|
9 | + '_wpnonce' => wp_create_nonce('reset_stripe_api_credentials'), |
|
10 | 10 | 'reset_stripe_api_credentials' => true, |
11 | 11 | ), |
12 | - admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) |
|
12 | + admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe') |
|
13 | 13 | ); |
14 | 14 | |
15 | 15 | $api_credentials_text = sprintf( |
16 | - __( '%1$sClear all Stripe account keys.%2$s %3$sThis will disable any connection to Stripe.%4$s', 'woocommerce-gateway-stripe' ), |
|
16 | + __('%1$sClear all Stripe account keys.%2$s %3$sThis will disable any connection to Stripe.%4$s', 'woocommerce-gateway-stripe'), |
|
17 | 17 | '<a id="wc_stripe_connect_button" href="' . $reset_link . '" class="button button-secondary">', |
18 | 18 | '</a>', |
19 | 19 | '<span style="color:red;">', |
@@ -22,16 +22,16 @@ discard block |
||
22 | 22 | } else { |
23 | 23 | $oauth_url = woocommerce_gateway_stripe()->connect->get_oauth_url(); |
24 | 24 | |
25 | - if ( ! is_wp_error( $oauth_url ) ) { |
|
25 | + if ( ! is_wp_error($oauth_url)) { |
|
26 | 26 | $api_credentials_text = sprintf( |
27 | - __( '%1$sSetup or link an existing Stripe account.%2$s By clicking this button you agree to the %3$sTerms of Service%2$s. Or, manually enter Stripe account keys below.', 'woocommerce-gateway-stripe' ), |
|
27 | + __('%1$sSetup or link an existing Stripe account.%2$s By clicking this button you agree to the %3$sTerms of Service%2$s. Or, manually enter Stripe account keys below.', 'woocommerce-gateway-stripe'), |
|
28 | 28 | '<a id="wc_stripe_connect_button" href="' . $oauth_url . '" class="button button-primary">', |
29 | 29 | '</a>', |
30 | 30 | '<a href="https://wordpress.com/tos">' |
31 | 31 | |
32 | 32 | ); |
33 | 33 | } else { |
34 | - $api_credentials_text = __( 'Manually enter Stripe keys below.', 'woocommerce-gateway-stripe' ); |
|
34 | + $api_credentials_text = __('Manually enter Stripe keys below.', 'woocommerce-gateway-stripe'); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -39,114 +39,114 @@ discard block |
||
39 | 39 | 'wc_stripe_settings', |
40 | 40 | array( |
41 | 41 | 'enabled' => array( |
42 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
43 | - 'label' => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ), |
|
42 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
43 | + 'label' => __('Enable Stripe', 'woocommerce-gateway-stripe'), |
|
44 | 44 | 'type' => 'checkbox', |
45 | 45 | 'description' => '', |
46 | 46 | 'default' => 'no', |
47 | 47 | ), |
48 | 48 | 'title' => array( |
49 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
49 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
50 | 50 | 'type' => 'text', |
51 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
52 | - 'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ), |
|
51 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
52 | + 'default' => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'), |
|
53 | 53 | 'desc_tip' => true, |
54 | 54 | ), |
55 | 55 | 'description' => array( |
56 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
56 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
57 | 57 | 'type' => 'text', |
58 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
59 | - 'default' => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ), |
|
58 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
59 | + 'default' => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
60 | 60 | 'desc_tip' => true, |
61 | 61 | ), |
62 | 62 | 'webhook' => array( |
63 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
63 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
64 | 64 | 'type' => 'title', |
65 | 65 | /* translators: webhook URL */ |
66 | 66 | 'description' => $this->display_admin_settings_webhook_description(), |
67 | 67 | ), |
68 | 68 | 'api_credentials' => array( |
69 | - 'title' => __( 'Stripe Account Keys', 'woocommerce-gateway-stripe' ), |
|
69 | + 'title' => __('Stripe Account Keys', 'woocommerce-gateway-stripe'), |
|
70 | 70 | 'type' => 'title', |
71 | 71 | 'description' => $api_credentials_text |
72 | 72 | ), |
73 | 73 | 'testmode' => array( |
74 | - 'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ), |
|
75 | - 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ), |
|
74 | + 'title' => __('Test mode', 'woocommerce-gateway-stripe'), |
|
75 | + 'label' => __('Enable Test Mode', 'woocommerce-gateway-stripe'), |
|
76 | 76 | 'type' => 'checkbox', |
77 | - 'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ), |
|
77 | + 'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'), |
|
78 | 78 | 'default' => 'yes', |
79 | 79 | 'desc_tip' => true, |
80 | 80 | ), |
81 | 81 | 'test_publishable_key' => array( |
82 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
82 | + 'title' => __('Test Publishable Key', 'woocommerce-gateway-stripe'), |
|
83 | 83 | 'type' => 'text', |
84 | - 'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_test_" will be saved.', 'woocommerce-gateway-stripe' ), |
|
84 | + 'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_test_" will be saved.', 'woocommerce-gateway-stripe'), |
|
85 | 85 | 'default' => '', |
86 | 86 | 'desc_tip' => true, |
87 | 87 | ), |
88 | 88 | 'test_secret_key' => array( |
89 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
89 | + 'title' => __('Test Secret Key', 'woocommerce-gateway-stripe'), |
|
90 | 90 | 'type' => 'password', |
91 | - 'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_test_" or "rk_test_" will be saved.', 'woocommerce-gateway-stripe' ), |
|
91 | + 'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_test_" or "rk_test_" will be saved.', 'woocommerce-gateway-stripe'), |
|
92 | 92 | 'default' => '', |
93 | 93 | 'desc_tip' => true, |
94 | 94 | ), |
95 | 95 | 'test_webhook_secret' => array( |
96 | - 'title' => __( 'Test Webhook Secret', 'woocommerce-gateway-stripe' ), |
|
96 | + 'title' => __('Test Webhook Secret', 'woocommerce-gateway-stripe'), |
|
97 | 97 | 'type' => 'password', |
98 | - 'description' => __( 'Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe' ), |
|
98 | + 'description' => __('Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe'), |
|
99 | 99 | 'default' => '', |
100 | 100 | 'desc_tip' => true, |
101 | 101 | ), |
102 | 102 | 'publishable_key' => array( |
103 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
103 | + 'title' => __('Live Publishable Key', 'woocommerce-gateway-stripe'), |
|
104 | 104 | 'type' => 'text', |
105 | - 'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_live_" will be saved.', 'woocommerce-gateway-stripe' ), |
|
105 | + 'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_live_" will be saved.', 'woocommerce-gateway-stripe'), |
|
106 | 106 | 'default' => '', |
107 | 107 | 'desc_tip' => true, |
108 | 108 | ), |
109 | 109 | 'secret_key' => array( |
110 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
110 | + 'title' => __('Live Secret Key', 'woocommerce-gateway-stripe'), |
|
111 | 111 | 'type' => 'password', |
112 | - 'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_live_" or "rk_live_" will be saved.', 'woocommerce-gateway-stripe' ), |
|
112 | + 'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_live_" or "rk_live_" will be saved.', 'woocommerce-gateway-stripe'), |
|
113 | 113 | 'default' => '', |
114 | 114 | 'desc_tip' => true, |
115 | 115 | ), |
116 | 116 | 'webhook_secret' => array( |
117 | - 'title' => __( 'Webhook Secret', 'woocommerce-gateway-stripe' ), |
|
117 | + 'title' => __('Webhook Secret', 'woocommerce-gateway-stripe'), |
|
118 | 118 | 'type' => 'password', |
119 | - 'description' => __( 'Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe' ), |
|
119 | + 'description' => __('Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe'), |
|
120 | 120 | 'default' => '', |
121 | 121 | 'desc_tip' => true, |
122 | 122 | ), |
123 | 123 | 'inline_cc_form' => array( |
124 | - 'title' => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ), |
|
124 | + 'title' => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'), |
|
125 | 125 | 'type' => 'checkbox', |
126 | - 'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ), |
|
126 | + 'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'), |
|
127 | 127 | 'default' => 'no', |
128 | 128 | 'desc_tip' => true, |
129 | 129 | ), |
130 | 130 | 'statement_descriptor' => array( |
131 | - 'title' => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ), |
|
131 | + 'title' => __('Statement Descriptor', 'woocommerce-gateway-stripe'), |
|
132 | 132 | 'type' => 'text', |
133 | - 'description' => __( 'Statement descriptors are limited to 22 characters, cannot use the special characters >, <, ", \, \', *, /, (, ), {, }, and must not consist solely of numbers. This will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ), |
|
133 | + 'description' => __('Statement descriptors are limited to 22 characters, cannot use the special characters >, <, ", \, \', *, /, (, ), {, }, and must not consist solely of numbers. This will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'), |
|
134 | 134 | 'default' => '', |
135 | 135 | 'desc_tip' => true, |
136 | 136 | ), |
137 | 137 | 'capture' => array( |
138 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
139 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
138 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
139 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
140 | 140 | 'type' => 'checkbox', |
141 | - 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ), |
|
141 | + 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'), |
|
142 | 142 | 'default' => 'yes', |
143 | 143 | 'desc_tip' => true, |
144 | 144 | ), |
145 | 145 | 'payment_request' => array( |
146 | - 'title' => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ), |
|
146 | + 'title' => __('Payment Request Buttons', 'woocommerce-gateway-stripe'), |
|
147 | 147 | 'label' => sprintf( |
148 | 148 | /* translators: 1) br tag 2) Stripe anchor tag 3) Apple anchor tag 4) Stripe dashboard opening anchor tag 5) Stripe dashboard closing anchor tag */ |
149 | - __( 'Enable Payment Request Buttons. (Apple Pay/Google Pay) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service. (Apple Pay domain verification is performed automatically; configuration can be found on the %4$sStripe dashboard%5$s.)', 'woocommerce-gateway-stripe' ), |
|
149 | + __('Enable Payment Request Buttons. (Apple Pay/Google Pay) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service. (Apple Pay domain verification is performed automatically; configuration can be found on the %4$sStripe dashboard%5$s.)', 'woocommerce-gateway-stripe'), |
|
150 | 150 | '<br />', |
151 | 151 | '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', |
152 | 152 | '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>', |
@@ -154,79 +154,79 @@ discard block |
||
154 | 154 | '</a>' |
155 | 155 | ), |
156 | 156 | 'type' => 'checkbox', |
157 | - 'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ), |
|
157 | + 'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'), |
|
158 | 158 | 'default' => 'yes', |
159 | 159 | 'desc_tip' => true, |
160 | 160 | ), |
161 | 161 | 'payment_request_button_type' => array( |
162 | - 'title' => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ), |
|
163 | - 'label' => __( 'Button Type', 'woocommerce-gateway-stripe' ), |
|
162 | + 'title' => __('Payment Request Button Type', 'woocommerce-gateway-stripe'), |
|
163 | + 'label' => __('Button Type', 'woocommerce-gateway-stripe'), |
|
164 | 164 | 'type' => 'select', |
165 | - 'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ), |
|
165 | + 'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'), |
|
166 | 166 | 'default' => 'buy', |
167 | 167 | 'desc_tip' => true, |
168 | 168 | 'options' => array( |
169 | - 'default' => __( 'Default', 'woocommerce-gateway-stripe' ), |
|
170 | - 'buy' => __( 'Buy', 'woocommerce-gateway-stripe' ), |
|
171 | - 'donate' => __( 'Donate', 'woocommerce-gateway-stripe' ), |
|
172 | - 'branded' => __( 'Branded', 'woocommerce-gateway-stripe' ), |
|
173 | - 'custom' => __( 'Custom', 'woocommerce-gateway-stripe' ), |
|
169 | + 'default' => __('Default', 'woocommerce-gateway-stripe'), |
|
170 | + 'buy' => __('Buy', 'woocommerce-gateway-stripe'), |
|
171 | + 'donate' => __('Donate', 'woocommerce-gateway-stripe'), |
|
172 | + 'branded' => __('Branded', 'woocommerce-gateway-stripe'), |
|
173 | + 'custom' => __('Custom', 'woocommerce-gateway-stripe'), |
|
174 | 174 | ), |
175 | 175 | ), |
176 | 176 | 'payment_request_button_theme' => array( |
177 | - 'title' => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ), |
|
178 | - 'label' => __( 'Button Theme', 'woocommerce-gateway-stripe' ), |
|
177 | + 'title' => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'), |
|
178 | + 'label' => __('Button Theme', 'woocommerce-gateway-stripe'), |
|
179 | 179 | 'type' => 'select', |
180 | - 'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ), |
|
180 | + 'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'), |
|
181 | 181 | 'default' => 'dark', |
182 | 182 | 'desc_tip' => true, |
183 | 183 | 'options' => array( |
184 | - 'dark' => __( 'Dark', 'woocommerce-gateway-stripe' ), |
|
185 | - 'light' => __( 'Light', 'woocommerce-gateway-stripe' ), |
|
186 | - 'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ), |
|
184 | + 'dark' => __('Dark', 'woocommerce-gateway-stripe'), |
|
185 | + 'light' => __('Light', 'woocommerce-gateway-stripe'), |
|
186 | + 'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'), |
|
187 | 187 | ), |
188 | 188 | ), |
189 | 189 | 'payment_request_button_height' => array( |
190 | - 'title' => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ), |
|
191 | - 'label' => __( 'Button Height', 'woocommerce-gateway-stripe' ), |
|
190 | + 'title' => __('Payment Request Button Height', 'woocommerce-gateway-stripe'), |
|
191 | + 'label' => __('Button Height', 'woocommerce-gateway-stripe'), |
|
192 | 192 | 'type' => 'text', |
193 | - 'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ), |
|
193 | + 'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'), |
|
194 | 194 | 'default' => '44', |
195 | 195 | 'desc_tip' => true, |
196 | 196 | ), |
197 | 197 | 'payment_request_button_label' => array( |
198 | - 'title' => __( 'Payment Request Button Label', 'woocommerce-gateway-stripe' ), |
|
199 | - 'label' => __( 'Button Label', 'woocommerce-gateway-stripe' ), |
|
198 | + 'title' => __('Payment Request Button Label', 'woocommerce-gateway-stripe'), |
|
199 | + 'label' => __('Button Label', 'woocommerce-gateway-stripe'), |
|
200 | 200 | 'type' => 'text', |
201 | - 'description' => __( 'Enter the custom text you would like the button to have.', 'woocommerce-gateway-stripe' ), |
|
202 | - 'default' => __( 'Buy now', 'woocommerce-gateway-stripe' ), |
|
201 | + 'description' => __('Enter the custom text you would like the button to have.', 'woocommerce-gateway-stripe'), |
|
202 | + 'default' => __('Buy now', 'woocommerce-gateway-stripe'), |
|
203 | 203 | 'desc_tip' => true, |
204 | 204 | ), |
205 | 205 | 'payment_request_button_branded_type' => array( |
206 | - 'title' => __( 'Payment Request Branded Button Label Format', 'woocommerce-gateway-stripe' ), |
|
207 | - 'label' => __( 'Branded Button Label Format', 'woocommerce-gateway-stripe' ), |
|
206 | + 'title' => __('Payment Request Branded Button Label Format', 'woocommerce-gateway-stripe'), |
|
207 | + 'label' => __('Branded Button Label Format', 'woocommerce-gateway-stripe'), |
|
208 | 208 | 'type' => 'select', |
209 | - 'description' => __( 'Select the branded button label format.', 'woocommerce-gateway-stripe' ), |
|
209 | + 'description' => __('Select the branded button label format.', 'woocommerce-gateway-stripe'), |
|
210 | 210 | 'default' => 'long', |
211 | 211 | 'desc_tip' => true, |
212 | 212 | 'options' => array( |
213 | - 'short' => __( 'Logo only', 'woocommerce-gateway-stripe' ), |
|
214 | - 'long' => __( 'Text and logo', 'woocommerce-gateway-stripe' ), |
|
213 | + 'short' => __('Logo only', 'woocommerce-gateway-stripe'), |
|
214 | + 'long' => __('Text and logo', 'woocommerce-gateway-stripe'), |
|
215 | 215 | ), |
216 | 216 | ), |
217 | 217 | 'saved_cards' => array( |
218 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
219 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
218 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
219 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
220 | 220 | 'type' => 'checkbox', |
221 | - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ), |
|
221 | + 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'), |
|
222 | 222 | 'default' => 'yes', |
223 | 223 | 'desc_tip' => true, |
224 | 224 | ), |
225 | 225 | 'logging' => array( |
226 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
227 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
226 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
227 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
228 | 228 | 'type' => 'checkbox', |
229 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
229 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
230 | 230 | 'default' => 'no', |
231 | 231 | 'desc_tip' => true, |
232 | 232 | ), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -22,12 +22,12 @@ discard block |
||
22 | 22 | * @param object $order |
23 | 23 | * @return string $currency |
24 | 24 | */ |
25 | - public static function get_stripe_currency( $order = null ) { |
|
26 | - if ( is_null( $order ) ) { |
|
25 | + public static function get_stripe_currency($order = null) { |
|
26 | + if (is_null($order)) { |
|
27 | 27 | return false; |
28 | 28 | } |
29 | 29 | |
30 | - return $order->get_meta( self::META_NAME_STRIPE_CURRENCY, true ); |
|
30 | + return $order->get_meta(self::META_NAME_STRIPE_CURRENCY, true); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @param object $order |
38 | 38 | * @param string $currency |
39 | 39 | */ |
40 | - public static function update_stripe_currency( $order = null, $currency ) { |
|
41 | - if ( is_null( $order ) ) { |
|
40 | + public static function update_stripe_currency($order = null, $currency) { |
|
41 | + if (is_null($order)) { |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | |
45 | - $order->update_meta_data( self::META_NAME_STRIPE_CURRENCY, $currency ); |
|
45 | + $order->update_meta_data(self::META_NAME_STRIPE_CURRENCY, $currency); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -52,20 +52,20 @@ discard block |
||
52 | 52 | * @param object $order |
53 | 53 | * @return string $amount |
54 | 54 | */ |
55 | - public static function get_stripe_fee( $order = null ) { |
|
56 | - if ( is_null( $order ) ) { |
|
55 | + public static function get_stripe_fee($order = null) { |
|
56 | + if (is_null($order)) { |
|
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | - $amount = $order->get_meta( self::META_NAME_FEE, true ); |
|
60 | + $amount = $order->get_meta(self::META_NAME_FEE, true); |
|
61 | 61 | |
62 | 62 | // If not found let's check for legacy name. |
63 | - if ( empty( $amount ) ) { |
|
64 | - $amount = $order->get_meta( self::LEGACY_META_NAME_FEE, true ); |
|
63 | + if (empty($amount)) { |
|
64 | + $amount = $order->get_meta(self::LEGACY_META_NAME_FEE, true); |
|
65 | 65 | |
66 | 66 | // If found update to new name. |
67 | - if ( $amount ) { |
|
68 | - self::update_stripe_fee( $order, $amount ); |
|
67 | + if ($amount) { |
|
68 | + self::update_stripe_fee($order, $amount); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | * @param object $order |
80 | 80 | * @param float $amount |
81 | 81 | */ |
82 | - public static function update_stripe_fee( $order = null, $amount = 0.0 ) { |
|
83 | - if ( is_null( $order ) ) { |
|
82 | + public static function update_stripe_fee($order = null, $amount = 0.0) { |
|
83 | + if (is_null($order)) { |
|
84 | 84 | return false; |
85 | 85 | } |
86 | 86 | |
87 | - $order->update_meta_data( self::META_NAME_FEE, $amount ); |
|
87 | + $order->update_meta_data(self::META_NAME_FEE, $amount); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | * @since 4.1.0 |
94 | 94 | * @param object $order |
95 | 95 | */ |
96 | - public static function delete_stripe_fee( $order = null ) { |
|
97 | - if ( is_null( $order ) ) { |
|
96 | + public static function delete_stripe_fee($order = null) { |
|
97 | + if (is_null($order)) { |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $order_id = $order->get_id(); |
102 | 102 | |
103 | - delete_post_meta( $order_id, self::META_NAME_FEE ); |
|
104 | - delete_post_meta( $order_id, self::LEGACY_META_NAME_FEE ); |
|
103 | + delete_post_meta($order_id, self::META_NAME_FEE); |
|
104 | + delete_post_meta($order_id, self::LEGACY_META_NAME_FEE); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,20 +111,20 @@ discard block |
||
111 | 111 | * @param object $order |
112 | 112 | * @return string $amount |
113 | 113 | */ |
114 | - public static function get_stripe_net( $order = null ) { |
|
115 | - if ( is_null( $order ) ) { |
|
114 | + public static function get_stripe_net($order = null) { |
|
115 | + if (is_null($order)) { |
|
116 | 116 | return false; |
117 | 117 | } |
118 | 118 | |
119 | - $amount = $order->get_meta( self::META_NAME_NET, true ); |
|
119 | + $amount = $order->get_meta(self::META_NAME_NET, true); |
|
120 | 120 | |
121 | 121 | // If not found let's check for legacy name. |
122 | - if ( empty( $amount ) ) { |
|
123 | - $amount = $order->get_meta( self::LEGACY_META_NAME_NET, true ); |
|
122 | + if (empty($amount)) { |
|
123 | + $amount = $order->get_meta(self::LEGACY_META_NAME_NET, true); |
|
124 | 124 | |
125 | 125 | // If found update to new name. |
126 | - if ( $amount ) { |
|
127 | - self::update_stripe_net( $order, $amount ); |
|
126 | + if ($amount) { |
|
127 | + self::update_stripe_net($order, $amount); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @param object $order |
139 | 139 | * @param float $amount |
140 | 140 | */ |
141 | - public static function update_stripe_net( $order = null, $amount = 0.0 ) { |
|
142 | - if ( is_null( $order ) ) { |
|
141 | + public static function update_stripe_net($order = null, $amount = 0.0) { |
|
142 | + if (is_null($order)) { |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | - $order->update_meta_data( self::META_NAME_NET, $amount ); |
|
146 | + $order->update_meta_data(self::META_NAME_NET, $amount); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | * @since 4.1.0 |
153 | 153 | * @param object $order |
154 | 154 | */ |
155 | - public static function delete_stripe_net( $order = null ) { |
|
156 | - if ( is_null( $order ) ) { |
|
155 | + public static function delete_stripe_net($order = null) { |
|
156 | + if (is_null($order)) { |
|
157 | 157 | return false; |
158 | 158 | } |
159 | 159 | |
160 | 160 | $order_id = $order->get_id(); |
161 | 161 | |
162 | - delete_post_meta( $order_id, self::META_NAME_NET ); |
|
163 | - delete_post_meta( $order_id, self::LEGACY_META_NAME_NET ); |
|
162 | + delete_post_meta($order_id, self::META_NAME_NET); |
|
163 | + delete_post_meta($order_id, self::LEGACY_META_NAME_NET); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -171,15 +171,15 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @return float|int |
173 | 173 | */ |
174 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
175 | - if ( ! $currency ) { |
|
174 | + public static function get_stripe_amount($total, $currency = '') { |
|
175 | + if ( ! $currency) { |
|
176 | 176 | $currency = get_woocommerce_currency(); |
177 | 177 | } |
178 | 178 | |
179 | - if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
180 | - return absint( $total ); |
|
179 | + if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
180 | + return absint($total); |
|
181 | 181 | } else { |
182 | - return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
182 | + return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
@@ -194,26 +194,26 @@ discard block |
||
194 | 194 | return apply_filters( |
195 | 195 | 'wc_stripe_localized_messages', |
196 | 196 | array( |
197 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
198 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
199 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
200 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
201 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
202 | - 'incomplete_number' => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
203 | - 'incomplete_cvc' => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
204 | - 'incomplete_expiry' => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ), |
|
205 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
206 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
207 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
208 | - 'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
209 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
210 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
211 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
212 | - 'invalid_sofort_country' => __( 'The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe' ), |
|
213 | - 'email_invalid' => __( 'Invalid email address, please correct and try again.', 'woocommerce-gateway-stripe' ), |
|
197 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
198 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
199 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
200 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
201 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
202 | + 'incomplete_number' => __('The card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
203 | + 'incomplete_cvc' => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
204 | + 'incomplete_expiry' => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'), |
|
205 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
206 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
207 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
208 | + 'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
209 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
210 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
211 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
212 | + 'invalid_sofort_country' => __('The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe'), |
|
213 | + 'email_invalid' => __('Invalid email address, please correct and try again.', 'woocommerce-gateway-stripe'), |
|
214 | 214 | 'invalid_request_error' => is_add_payment_method_page() |
215 | - ? __( 'Unable to save this payment method, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) |
|
216 | - : __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ), |
|
215 | + ? __('Unable to save this payment method, please try again or use alternative method.', 'woocommerce-gateway-stripe') |
|
216 | + : __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'), |
|
217 | 217 | ) |
218 | 218 | ); |
219 | 219 | } |
@@ -254,24 +254,24 @@ discard block |
||
254 | 254 | * @param string $type Type of number to format |
255 | 255 | * @return string |
256 | 256 | */ |
257 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
258 | - if ( ! is_object( $balance_transaction ) ) { |
|
257 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
258 | + if ( ! is_object($balance_transaction)) { |
|
259 | 259 | return; |
260 | 260 | } |
261 | 261 | |
262 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
263 | - if ( 'fee' === $type ) { |
|
262 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
263 | + if ('fee' === $type) { |
|
264 | 264 | return $balance_transaction->fee; |
265 | 265 | } |
266 | 266 | |
267 | 267 | return $balance_transaction->net; |
268 | 268 | } |
269 | 269 | |
270 | - if ( 'fee' === $type ) { |
|
271 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
270 | + if ('fee' === $type) { |
|
271 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
272 | 272 | } |
273 | 273 | |
274 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
274 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public static function get_minimum_amount() { |
281 | 281 | // Check order amount |
282 | - switch ( get_woocommerce_currency() ) { |
|
282 | + switch (get_woocommerce_currency()) { |
|
283 | 283 | case 'USD': |
284 | 284 | case 'CAD': |
285 | 285 | case 'EUR': |
@@ -324,14 +324,14 @@ discard block |
||
324 | 324 | * @param string $method The payment method to get the settings from. |
325 | 325 | * @param string $setting The name of the setting to get. |
326 | 326 | */ |
327 | - public static function get_settings( $method = null, $setting = null ) { |
|
328 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
327 | + public static function get_settings($method = null, $setting = null) { |
|
328 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
329 | 329 | |
330 | - if ( null === $setting ) { |
|
330 | + if (null === $setting) { |
|
331 | 331 | return $all_settings; |
332 | 332 | } |
333 | 333 | |
334 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
334 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | * @return bool |
342 | 342 | */ |
343 | 343 | public static function is_pre_orders_exists() { |
344 | - return class_exists( 'WC_Pre_Orders_Order' ); |
|
344 | + return class_exists('WC_Pre_Orders_Order'); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | * @param string $version Version to check against. |
352 | 352 | * @return bool |
353 | 353 | */ |
354 | - public static function is_wc_lt( $version ) { |
|
355 | - return version_compare( WC_VERSION, $version, '<' ); |
|
354 | + public static function is_wc_lt($version) { |
|
355 | + return version_compare(WC_VERSION, $version, '<'); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * @return string |
366 | 366 | */ |
367 | 367 | public static function get_webhook_url() { |
368 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
368 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -375,13 +375,13 @@ discard block |
||
375 | 375 | * @version 4.0.0 |
376 | 376 | * @param string $source_id |
377 | 377 | */ |
378 | - public static function get_order_by_source_id( $source_id ) { |
|
378 | + public static function get_order_by_source_id($source_id) { |
|
379 | 379 | global $wpdb; |
380 | 380 | |
381 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id' ) ); |
|
381 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id')); |
|
382 | 382 | |
383 | - if ( ! empty( $order_id ) ) { |
|
384 | - return wc_get_order( $order_id ); |
|
383 | + if ( ! empty($order_id)) { |
|
384 | + return wc_get_order($order_id); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return false; |
@@ -394,17 +394,17 @@ discard block |
||
394 | 394 | * @since 4.1.16 Return false if charge_id is empty. |
395 | 395 | * @param string $charge_id |
396 | 396 | */ |
397 | - public static function get_order_by_charge_id( $charge_id ) { |
|
397 | + public static function get_order_by_charge_id($charge_id) { |
|
398 | 398 | global $wpdb; |
399 | 399 | |
400 | - if ( empty( $charge_id ) ) { |
|
400 | + if (empty($charge_id)) { |
|
401 | 401 | return false; |
402 | 402 | } |
403 | 403 | |
404 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id' ) ); |
|
404 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id')); |
|
405 | 405 | |
406 | - if ( ! empty( $order_id ) ) { |
|
407 | - return wc_get_order( $order_id ); |
|
406 | + if ( ! empty($order_id)) { |
|
407 | + return wc_get_order($order_id); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | return false; |
@@ -417,13 +417,13 @@ discard block |
||
417 | 417 | * @param string $intent_id The ID of the intent. |
418 | 418 | * @return WC_Order|bool Either an order or false when not found. |
419 | 419 | */ |
420 | - public static function get_order_by_intent_id( $intent_id ) { |
|
420 | + public static function get_order_by_intent_id($intent_id) { |
|
421 | 421 | global $wpdb; |
422 | 422 | |
423 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_intent_id' ) ); |
|
423 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_intent_id')); |
|
424 | 424 | |
425 | - if ( ! empty( $order_id ) ) { |
|
426 | - return wc_get_order( $order_id ); |
|
425 | + if ( ! empty($order_id)) { |
|
426 | + return wc_get_order($order_id); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | return false; |
@@ -436,13 +436,13 @@ discard block |
||
436 | 436 | * @param string $intent_id The ID of the intent. |
437 | 437 | * @return WC_Order|bool Either an order or false when not found. |
438 | 438 | */ |
439 | - public static function get_order_by_setup_intent_id( $intent_id ) { |
|
439 | + public static function get_order_by_setup_intent_id($intent_id) { |
|
440 | 440 | global $wpdb; |
441 | 441 | |
442 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_setup_intent' ) ); |
|
442 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_setup_intent')); |
|
443 | 443 | |
444 | - if ( ! empty( $order_id ) ) { |
|
445 | - return wc_get_order( $order_id ); |
|
444 | + if ( ! empty($order_id)) { |
|
445 | + return wc_get_order($order_id); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | return false; |
@@ -457,21 +457,21 @@ discard block |
||
457 | 457 | * @param string $statement_descriptor |
458 | 458 | * @return string $statement_descriptor Sanitized statement descriptor |
459 | 459 | */ |
460 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
461 | - $disallowed_characters = array( '<', '>', '\\', '*', '"', "'", '/', '(', ')', '{', '}' ); |
|
460 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
461 | + $disallowed_characters = array('<', '>', '\\', '*', '"', "'", '/', '(', ')', '{', '}'); |
|
462 | 462 | |
463 | 463 | // Strip any tags. |
464 | - $statement_descriptor = strip_tags( $statement_descriptor ); |
|
464 | + $statement_descriptor = strip_tags($statement_descriptor); |
|
465 | 465 | |
466 | 466 | // Strip any HTML entities. |
467 | 467 | // Props https://stackoverflow.com/questions/657643/how-to-remove-html-special-chars . |
468 | - $statement_descriptor = preg_replace( "/&#?[a-z0-9]{2,8};/i", "", $statement_descriptor ); |
|
468 | + $statement_descriptor = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $statement_descriptor); |
|
469 | 469 | |
470 | 470 | // Next, remove any remaining disallowed characters. |
471 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
471 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
472 | 472 | |
473 | 473 | // Trim any whitespace at the ends and limit to 22 characters. |
474 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
474 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
475 | 475 | |
476 | 476 | return $statement_descriptor; |
477 | 477 | } |