@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -7,47 +7,47 @@ discard block |
||
7 | 7 | 'wc_stripe_sepa_settings', |
8 | 8 | array( |
9 | 9 | 'geo_target' => array( |
10 | - 'description' => __( 'Customer Geography: France, Germany, Spain, Belgium, Netherlands, Luxembourg, Italy, Portugal, Austria, Ireland', 'woocommerce-gateway-stripe' ), |
|
10 | + 'description' => __('Customer Geography: France, Germany, Spain, Belgium, Netherlands, Luxembourg, Italy, Portugal, Austria, Ireland', 'woocommerce-gateway-stripe'), |
|
11 | 11 | 'type' => 'title', |
12 | 12 | ), |
13 | 13 | 'guide' => array( |
14 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#sepa-direct-debit" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
14 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#sepa-direct-debit" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
15 | 15 | 'type' => 'title', |
16 | 16 | ), |
17 | 17 | 'activation' => array( |
18 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
18 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
19 | 19 | 'type' => 'title', |
20 | 20 | ), |
21 | 21 | 'enabled' => array( |
22 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
23 | - 'label' => __( 'Enable Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ), |
|
22 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
23 | + 'label' => __('Enable Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'), |
|
24 | 24 | 'type' => 'checkbox', |
25 | 25 | 'description' => '', |
26 | 26 | 'default' => 'no', |
27 | 27 | ), |
28 | 28 | 'activate_subscriptions_early' => array( |
29 | - 'title' => __( 'Subscriptions Status', 'woocommerce-gateway-stripe' ), |
|
30 | - 'label' => __( 'Make subscriptions active while waiting on the payment process to complete', 'woocommerce-gateway-stripe' ), |
|
29 | + 'title' => __('Subscriptions Status', 'woocommerce-gateway-stripe'), |
|
30 | + 'label' => __('Make subscriptions active while waiting on the payment process to complete', 'woocommerce-gateway-stripe'), |
|
31 | 31 | 'type' => 'checkbox', |
32 | 32 | 'description' => '', |
33 | 33 | 'default' => 'no', |
34 | 34 | ), |
35 | 35 | 'title' => array( |
36 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
36 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
37 | 37 | 'type' => 'text', |
38 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
39 | - 'default' => __( 'SEPA Direct Debit', 'woocommerce-gateway-stripe' ), |
|
38 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
39 | + 'default' => __('SEPA Direct Debit', 'woocommerce-gateway-stripe'), |
|
40 | 40 | 'desc_tip' => true, |
41 | 41 | ), |
42 | 42 | 'description' => array( |
43 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
43 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
44 | 44 | 'type' => 'text', |
45 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
46 | - 'default' => __( 'Mandate Information.', 'woocommerce-gateway-stripe' ), |
|
45 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
46 | + 'default' => __('Mandate Information.', 'woocommerce-gateway-stripe'), |
|
47 | 47 | 'desc_tip' => true, |
48 | 48 | ), |
49 | 49 | 'webhook' => array( |
50 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
50 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
51 | 51 | 'type' => 'title', |
52 | 52 | /* translators: webhook URL */ |
53 | 53 | 'description' => $this->display_admin_settings_webhook_description(), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | public function __construct() { |
73 | 73 | $this->retry_interval = 1; |
74 | 74 | $this->id = 'stripe_sepa'; |
75 | - $this->method_title = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
75 | + $this->method_title = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
76 | 76 | /* translators: link */ |
77 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
77 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
78 | 78 | $this->has_fields = true; |
79 | 79 | $this->supports = array( |
80 | 80 | 'products', |
@@ -100,31 +100,31 @@ discard block |
||
100 | 100 | // Load the settings. |
101 | 101 | $this->init_settings(); |
102 | 102 | |
103 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
104 | - $this->title = $this->get_option( 'title' ); |
|
105 | - $this->description = $this->get_option( 'description' ); |
|
106 | - $this->enabled = $this->get_option( 'enabled' ); |
|
107 | - $this->activate_subscriptions_early = $this->get_option( 'activate_subscriptions_early' ); |
|
108 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
109 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
110 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
111 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
112 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
113 | - |
|
114 | - if ( $this->testmode ) { |
|
115 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
116 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
103 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
104 | + $this->title = $this->get_option('title'); |
|
105 | + $this->description = $this->get_option('description'); |
|
106 | + $this->enabled = $this->get_option('enabled'); |
|
107 | + $this->activate_subscriptions_early = $this->get_option('activate_subscriptions_early'); |
|
108 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
109 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
110 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
111 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
112 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
113 | + |
|
114 | + if ($this->testmode) { |
|
115 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
116 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
117 | 117 | } |
118 | 118 | |
119 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
120 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
119 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
120 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
121 | 121 | |
122 | - add_action( 'woocommerce_order_status_changed', array( $this, 'maybe_activate_subscriptions_early'), 10, 4 ); |
|
122 | + add_action('woocommerce_order_status_changed', array($this, 'maybe_activate_subscriptions_early'), 10, 4); |
|
123 | 123 | |
124 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
124 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
125 | 125 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
126 | 126 | |
127 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
127 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | * @return bool |
153 | 153 | */ |
154 | 154 | public function is_available() { |
155 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
155 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | |
159 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
159 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
160 | 160 | return false; |
161 | 161 | } |
162 | 162 | |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str = ''; |
177 | 177 | |
178 | - $icons_str .= isset( $icons['sepa'] ) ? $icons['sepa'] : ''; |
|
178 | + $icons_str .= isset($icons['sepa']) ? $icons['sepa'] : ''; |
|
179 | 179 | |
180 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
180 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -188,19 +188,19 @@ discard block |
||
188 | 188 | * @access public |
189 | 189 | */ |
190 | 190 | public function payment_scripts() { |
191 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
191 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
192 | 192 | return; |
193 | 193 | } |
194 | 194 | |
195 | - wp_enqueue_style( 'stripe_styles' ); |
|
196 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
195 | + wp_enqueue_style('stripe_styles'); |
|
196 | + wp_enqueue_script('woocommerce_stripe'); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
200 | 200 | * Initialize Gateway Settings Form Fields. |
201 | 201 | */ |
202 | 202 | public function init_form_fields() { |
203 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' ); |
|
203 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php'); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function mandate_display() { |
214 | 214 | /* translators: statement descriptor */ |
215 | - printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) ); |
|
215 | + printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor)); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function form() { |
225 | 225 | ?> |
226 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
227 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
226 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
227 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
228 | 228 | <p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p> |
229 | 229 | <p class="form-row form-row-wide"> |
230 | 230 | <label for="stripe-iban-element"> |
231 | - <?php esc_html_e( 'IBAN.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span> |
|
231 | + <?php esc_html_e('IBAN.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span> |
|
232 | 232 | </label> |
233 | 233 | <div id="stripe-iban-element" class="wc-stripe-iban-element-field"> |
234 | 234 | <!-- A Stripe Element will be inserted here. --> |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | <!-- Used to display form errors --> |
239 | 239 | <div class="stripe-source-errors" role="alert"></div> |
240 | 240 | <br /> |
241 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
241 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
242 | 242 | <div class="clear"></div> |
243 | 243 | </fieldset> |
244 | 244 | <?php |
@@ -250,45 +250,45 @@ discard block |
||
250 | 250 | public function payment_fields() { |
251 | 251 | global $wp; |
252 | 252 | $total = WC()->cart->total; |
253 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
253 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
254 | 254 | $description = $this->get_description(); |
255 | - $description = ! empty( $description ) ? $description : ''; |
|
255 | + $description = ! empty($description) ? $description : ''; |
|
256 | 256 | |
257 | 257 | // If paying from order, we need to get total from order not cart. |
258 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
259 | - $order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) ); |
|
258 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
259 | + $order = wc_get_order(wc_clean($wp->query_vars['order-pay'])); |
|
260 | 260 | $total = $order->get_total(); |
261 | 261 | } |
262 | 262 | |
263 | - if ( is_add_payment_method_page() ) { |
|
263 | + if (is_add_payment_method_page()) { |
|
264 | 264 | $total = ''; |
265 | 265 | } |
266 | 266 | |
267 | 267 | echo '<div |
268 | 268 | id="stripe-sepa_debit-payment-data" |
269 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
270 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
269 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
270 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
271 | 271 | |
272 | - if ( $this->testmode ) { |
|
273 | - $description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' ); |
|
272 | + if ($this->testmode) { |
|
273 | + $description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe'); |
|
274 | 274 | } |
275 | 275 | |
276 | - $description = trim( $description ); |
|
276 | + $description = trim($description); |
|
277 | 277 | |
278 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
278 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
279 | 279 | |
280 | - if ( $display_tokenization ) { |
|
280 | + if ($display_tokenization) { |
|
281 | 281 | $this->tokenization_script(); |
282 | 282 | $this->saved_payment_methods(); |
283 | 283 | } |
284 | 284 | |
285 | 285 | $this->form(); |
286 | 286 | |
287 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
287 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
288 | 288 | $this->save_payment_method_checkbox(); |
289 | 289 | } |
290 | 290 | |
291 | - do_action( 'wc_stripe_sepa_payment_fields', $this->id ); |
|
291 | + do_action('wc_stripe_sepa_payment_fields', $this->id); |
|
292 | 292 | |
293 | 293 | echo '</div>'; |
294 | 294 | } |
@@ -304,94 +304,94 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return array|void |
306 | 306 | */ |
307 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
307 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
308 | 308 | try { |
309 | - $order = wc_get_order( $order_id ); |
|
309 | + $order = wc_get_order($order_id); |
|
310 | 310 | |
311 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
312 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
311 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
312 | + return $this->pre_orders->process_pre_order($order_id); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | // This comes from the create account checkbox in the checkout page. |
316 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
316 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
317 | 317 | |
318 | - if ( $create_account ) { |
|
318 | + if ($create_account) { |
|
319 | 319 | $new_customer_id = $order->get_customer_id(); |
320 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
320 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
321 | 321 | $new_stripe_customer->create_customer(); |
322 | 322 | } |
323 | 323 | |
324 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
324 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
325 | 325 | |
326 | - $this->save_source_to_order( $order, $prepared_source ); |
|
326 | + $this->save_source_to_order($order, $prepared_source); |
|
327 | 327 | |
328 | 328 | // Result from Stripe API request. |
329 | 329 | $response = null; |
330 | 330 | |
331 | - if ( $order->get_total() > 0 ) { |
|
331 | + if ($order->get_total() > 0) { |
|
332 | 332 | // This will throw exception if not valid. |
333 | - $this->validate_minimum_order_amount( $order ); |
|
333 | + $this->validate_minimum_order_amount($order); |
|
334 | 334 | |
335 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
335 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
336 | 336 | |
337 | 337 | // Make the request. |
338 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
338 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
339 | 339 | |
340 | - if ( ! empty( $response->error ) ) { |
|
340 | + if ( ! empty($response->error)) { |
|
341 | 341 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
342 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
343 | - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); |
|
344 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
342 | + if ($this->is_no_such_customer_error($response->error)) { |
|
343 | + delete_user_option($order->get_customer_id(), '_stripe_customer_id'); |
|
344 | + $order->delete_meta_data('_stripe_customer_id'); |
|
345 | 345 | $order->save(); |
346 | 346 | } |
347 | 347 | |
348 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
348 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
349 | 349 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
350 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
350 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
351 | 351 | $wc_token->delete(); |
352 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
353 | - $order->add_order_note( $localized_message ); |
|
354 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
352 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
353 | + $order->add_order_note($localized_message); |
|
354 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | // We want to retry. |
358 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
359 | - if ( $retry ) { |
|
358 | + if ($this->is_retryable_error($response->error)) { |
|
359 | + if ($retry) { |
|
360 | 360 | // Don't do anymore retries after this. |
361 | - if ( 5 <= $this->retry_interval ) { |
|
361 | + if (5 <= $this->retry_interval) { |
|
362 | 362 | |
363 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
363 | + return $this->process_payment($order_id, false, $force_save_source); |
|
364 | 364 | } |
365 | 365 | |
366 | - sleep( $this->retry_interval ); |
|
366 | + sleep($this->retry_interval); |
|
367 | 367 | |
368 | 368 | $this->retry_interval++; |
369 | 369 | |
370 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
370 | + return $this->process_payment($order_id, true, $force_save_source); |
|
371 | 371 | } else { |
372 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
373 | - $order->add_order_note( $localized_message ); |
|
374 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
372 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
373 | + $order->add_order_note($localized_message); |
|
374 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
378 | 378 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
379 | 379 | |
380 | - if ( 'card_error' === $response->error->type ) { |
|
381 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
380 | + if ('card_error' === $response->error->type) { |
|
381 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
382 | 382 | } else { |
383 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
383 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
384 | 384 | } |
385 | 385 | |
386 | - $order->add_order_note( $localized_message ); |
|
386 | + $order->add_order_note($localized_message); |
|
387 | 387 | |
388 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
388 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
389 | 389 | } |
390 | 390 | |
391 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
391 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
392 | 392 | |
393 | 393 | // Process valid response. |
394 | - $this->process_response( $response, $order ); |
|
394 | + $this->process_response($response, $order); |
|
395 | 395 | } else { |
396 | 396 | $order->payment_complete(); |
397 | 397 | } |
@@ -402,17 +402,17 @@ discard block |
||
402 | 402 | // Return thank you page redirect. |
403 | 403 | return array( |
404 | 404 | 'result' => 'success', |
405 | - 'redirect' => $this->get_return_url( $order ), |
|
405 | + 'redirect' => $this->get_return_url($order), |
|
406 | 406 | ); |
407 | 407 | |
408 | - } catch ( WC_Stripe_Exception $e ) { |
|
409 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
410 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
408 | + } catch (WC_Stripe_Exception $e) { |
|
409 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
410 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
411 | 411 | |
412 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
412 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
413 | 413 | |
414 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
415 | - $this->send_failed_order_email( $order_id ); |
|
414 | + if ($order->has_status(array('pending', 'failed'))) { |
|
415 | + $this->send_failed_order_email($order_id); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | return array( |
@@ -432,18 +432,18 @@ discard block |
||
432 | 432 | * @param $status_to |
433 | 433 | * @param $order |
434 | 434 | */ |
435 | - function maybe_activate_subscriptions_early ( $order_id, $status_from, $status_to, $order ) { |
|
436 | - if ( 'yes' !== $this->activate_subscriptions_early || $status_to !== 'on-hold' ) { |
|
435 | + function maybe_activate_subscriptions_early($order_id, $status_from, $status_to, $order) { |
|
436 | + if ('yes' !== $this->activate_subscriptions_early || $status_to !== 'on-hold') { |
|
437 | 437 | return; |
438 | 438 | } |
439 | 439 | |
440 | - if ( ! wcs_order_contains_subscription( $order, 'any' ) || ! function_exists( 'wcs_order_contains_subscription' ) ) { |
|
440 | + if ( ! wcs_order_contains_subscription($order, 'any') || ! function_exists('wcs_order_contains_subscription')) { |
|
441 | 441 | return; |
442 | 442 | } |
443 | 443 | |
444 | - $subscriptions = wcs_get_subscriptions_for_order( $order, array( 'order_type' => array( 'any' ) ) ); |
|
445 | - foreach( $subscriptions as $subscription ){ |
|
446 | - $subscription->update_status( 'active' ); |
|
444 | + $subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => array('any'))); |
|
445 | + foreach ($subscriptions as $subscription) { |
|
446 | + $subscription->update_status('active'); |
|
447 | 447 | } |
448 | 448 | } |
449 | 449 | } |