Completed
Pull Request — master (#1192)
by Dwain
01:49
created
includes/payment-methods/class-wc-gateway-stripe-p24.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id           = 'stripe_p24';
60
-		$this->method_title = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
60
+		$this->method_title = __('Stripe P24', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports           = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @return bool
116 116
 	 */
117 117
 	public function is_available() {
118
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
118
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
119 119
 			return false;
120 120
 		}
121 121
 
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 
135 135
 		$icons_str = '';
136 136
 
137
-		$icons_str .= isset( $icons['p24'] ) ? $icons['p24'] : '';
137
+		$icons_str .= isset($icons['p24']) ? $icons['p24'] : '';
138 138
 
139
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
139
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
140 140
 	}
141 141
 
142 142
 	/**
@@ -147,19 +147,19 @@  discard block
 block discarded – undo
147 147
 	 * @access public
148 148
 	 */
149 149
 	public function payment_scripts() {
150
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
150
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
151 151
 			return;
152 152
 		}
153 153
 
154
-		wp_enqueue_style( 'stripe_styles' );
155
-		wp_enqueue_script( 'woocommerce_stripe' );
154
+		wp_enqueue_style('stripe_styles');
155
+		wp_enqueue_script('woocommerce_stripe');
156 156
 	}
157 157
 
158 158
 	/**
159 159
 	 * Initialize Gateway Settings Form Fields.
160 160
 	 */
161 161
 	public function init_form_fields() {
162
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' );
162
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php');
163 163
 	}
164 164
 
165 165
 	/**
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
 		$description = $this->get_description();
173 173
 
174 174
 		// If paying from order, we need to get total from order not cart.
175
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
176
-			$order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) );
175
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
176
+			$order = wc_get_order(wc_clean($wp->query_vars['order-pay']));
177 177
 			$total = $order->get_total();
178 178
 		}
179 179
 
180
-		if ( is_add_payment_method_page() ) {
181
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
180
+		if (is_add_payment_method_page()) {
181
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
182 182
 			$total           = '';
183 183
 		} else {
184 184
 			$pay_button_text = '';
@@ -186,11 +186,11 @@  discard block
 block discarded – undo
186 186
 
187 187
 		echo '<div
188 188
 			id="stripe-p24-payment-data"
189
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
190
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
189
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
190
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
191 191
 
192
-		if ( $description ) {
193
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
192
+		if ($description) {
193
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
194 194
 		}
195 195
 
196 196
 		echo '</div>';
@@ -204,20 +204,20 @@  discard block
 block discarded – undo
204 204
 	 * @param object $order
205 205
 	 * @return mixed
206 206
 	 */
207
-	public function create_source( $order ) {
208
-		$currency              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency();
209
-		$order_id              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
210
-		$return_url            = $this->get_stripe_return_url( $order );
207
+	public function create_source($order) {
208
+		$currency              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency();
209
+		$order_id              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
210
+		$return_url            = $this->get_stripe_return_url($order);
211 211
 		$post_data             = array();
212
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
213
-		$post_data['currency'] = strtolower( $currency );
212
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
213
+		$post_data['currency'] = strtolower($currency);
214 214
 		$post_data['type']     = 'p24';
215
-		$post_data['owner']    = $this->get_owner_details( $order );
216
-		$post_data['redirect'] = array( 'return_url' => $return_url );
215
+		$post_data['owner']    = $this->get_owner_details($order);
216
+		$post_data['redirect'] = array('return_url' => $return_url);
217 217
 
218
-		WC_Stripe_Logger::log( 'Info: Begin creating P24 source' );
218
+		WC_Stripe_Logger::log('Info: Begin creating P24 source');
219 219
 
220
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_p24_source', $post_data, $order ), 'sources' );
220
+		return WC_Stripe_API::request(apply_filters('wc_stripe_p24_source', $post_data, $order), 'sources');
221 221
 	}
222 222
 
223 223
 	/**
@@ -231,51 +231,51 @@  discard block
 block discarded – undo
231 231
 	 *
232 232
 	 * @return array|void
233 233
 	 */
234
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
234
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
235 235
 		try {
236
-			$order = wc_get_order( $order_id );
236
+			$order = wc_get_order($order_id);
237 237
 
238 238
 			// This will throw exception if not valid.
239
-			$this->validate_minimum_order_amount( $order );
239
+			$this->validate_minimum_order_amount($order);
240 240
 
241 241
 			// This comes from the create account checkbox in the checkout page.
242
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
242
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
243 243
 
244
-			if ( $create_account ) {
245
-				$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
246
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
244
+			if ($create_account) {
245
+				$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
246
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
247 247
 				$new_stripe_customer->create_customer();
248 248
 			}
249 249
 
250
-			$response = $this->create_source( $order );
250
+			$response = $this->create_source($order);
251 251
 
252
-			if ( ! empty( $response->error ) ) {
253
-				$order->add_order_note( $response->error->message );
252
+			if ( ! empty($response->error)) {
253
+				$order->add_order_note($response->error->message);
254 254
 
255
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
255
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
256 256
 			}
257 257
 
258
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
259
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
258
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
259
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
260 260
 			} else {
261
-				$order->update_meta_data( '_stripe_source_id', $response->id );
261
+				$order->update_meta_data('_stripe_source_id', $response->id);
262 262
 				$order->save();
263 263
 			}
264 264
 
265
-			WC_Stripe_Logger::log( 'Info: Redirecting to P24...' );
265
+			WC_Stripe_Logger::log('Info: Redirecting to P24...');
266 266
 
267 267
 			return array(
268 268
 				'result'   => 'success',
269
-				'redirect' => esc_url_raw( $response->redirect->url ),
269
+				'redirect' => esc_url_raw($response->redirect->url),
270 270
 			);
271
-		} catch ( WC_Stripe_Exception $e ) {
272
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
273
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
271
+		} catch (WC_Stripe_Exception $e) {
272
+			wc_add_notice($e->getLocalizedMessage(), 'error');
273
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
274 274
 
275
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
275
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
276 276
 
277
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
278
-				$this->send_failed_order_email( $order_id );
277
+			if ($order->has_status(array('pending', 'failed'))) {
278
+				$this->send_failed_order_email($order_id);
279 279
 			}
280 280
 
281 281
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-eps.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id           = 'stripe_eps';
60
-		$this->method_title = __( 'Stripe EPS', 'woocommerce-gateway-stripe' );
60
+		$this->method_title = __('Stripe EPS', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports           = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @return bool
115 115
 	 */
116 116
 	public function is_available() {
117
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
117
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
118 118
 			return false;
119 119
 		}
120 120
 
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
 
134 134
 		$icons_str = '';
135 135
 
136
-		$icons_str .= isset( $icons['eps'] ) ? $icons['eps'] : '';
136
+		$icons_str .= isset($icons['eps']) ? $icons['eps'] : '';
137 137
 
138
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
138
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
139 139
 	}
140 140
 
141 141
 	/**
@@ -146,19 +146,19 @@  discard block
 block discarded – undo
146 146
 	 * @access public
147 147
 	 */
148 148
 	public function payment_scripts() {
149
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
149
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
150 150
 			return;
151 151
 		}
152 152
 
153
-		wp_enqueue_style( 'stripe_styles' );
154
-		wp_enqueue_script( 'woocommerce_stripe' );
153
+		wp_enqueue_style('stripe_styles');
154
+		wp_enqueue_script('woocommerce_stripe');
155 155
 	}
156 156
 
157 157
 	/**
158 158
 	 * Initialize Gateway Settings Form Fields.
159 159
 	 */
160 160
 	public function init_form_fields() {
161
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php' );
161
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php');
162 162
 	}
163 163
 
164 164
 	/**
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 		$description = $this->get_description();
172 172
 
173 173
 		// If paying from order, we need to get total from order not cart.
174
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
175
-			$order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) );
174
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
175
+			$order = wc_get_order(wc_clean($wp->query_vars['order-pay']));
176 176
 			$total = $order->get_total();
177 177
 		}
178 178
 
179
-		if ( is_add_payment_method_page() ) {
180
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
179
+		if (is_add_payment_method_page()) {
180
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
181 181
 			$total           = '';
182 182
 		} else {
183 183
 			$pay_button_text = '';
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 
186 186
 		echo '<div
187 187
 			id="stripe-eps-payment-data"
188
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
189
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
188
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
189
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
190 190
 
191
-		if ( $description ) {
192
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
191
+		if ($description) {
192
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
193 193
 		}
194 194
 
195 195
 		echo '</div>';
@@ -203,24 +203,24 @@  discard block
 block discarded – undo
203 203
 	 * @param object $order
204 204
 	 * @return mixed
205 205
 	 */
206
-	public function create_source( $order ) {
207
-		$currency              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency();
208
-		$order_id              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
209
-		$return_url            = $this->get_stripe_return_url( $order );
206
+	public function create_source($order) {
207
+		$currency              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency();
208
+		$order_id              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
209
+		$return_url            = $this->get_stripe_return_url($order);
210 210
 		$post_data             = array();
211
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
212
-		$post_data['currency'] = strtolower( $currency );
211
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
212
+		$post_data['currency'] = strtolower($currency);
213 213
 		$post_data['type']     = 'eps';
214
-		$post_data['owner']    = $this->get_owner_details( $order );
215
-		$post_data['redirect'] = array( 'return_url' => $return_url );
214
+		$post_data['owner']    = $this->get_owner_details($order);
215
+		$post_data['redirect'] = array('return_url' => $return_url);
216 216
 
217
-		if ( ! empty( $this->statement_descriptor ) ) {
218
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
217
+		if ( ! empty($this->statement_descriptor)) {
218
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
219 219
 		}
220 220
 
221
-		WC_Stripe_Logger::log( 'Info: Begin creating EPS source' );
221
+		WC_Stripe_Logger::log('Info: Begin creating EPS source');
222 222
 
223
-		return WC_Stripe_API::request( $post_data, 'sources' );
223
+		return WC_Stripe_API::request($post_data, 'sources');
224 224
 	}
225 225
 
226 226
 	/**
@@ -234,51 +234,51 @@  discard block
 block discarded – undo
234 234
 	 *
235 235
 	 * @return array|void
236 236
 	 */
237
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
237
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
238 238
 		try {
239
-			$order = wc_get_order( $order_id );
239
+			$order = wc_get_order($order_id);
240 240
 
241 241
 			// This will throw exception if not valid.
242
-			$this->validate_minimum_order_amount( $order );
242
+			$this->validate_minimum_order_amount($order);
243 243
 
244 244
 			// This comes from the create account checkbox in the checkout page.
245
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
245
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
246 246
 
247
-			if ( $create_account ) {
248
-				$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
249
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
247
+			if ($create_account) {
248
+				$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
249
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
250 250
 				$new_stripe_customer->create_customer();
251 251
 			}
252 252
 
253
-			$response = $this->create_source( $order );
253
+			$response = $this->create_source($order);
254 254
 
255
-			if ( ! empty( $response->error ) ) {
256
-				$order->add_order_note( $response->error->message );
255
+			if ( ! empty($response->error)) {
256
+				$order->add_order_note($response->error->message);
257 257
 
258
-				throw new Exception( $response->error->message );
258
+				throw new Exception($response->error->message);
259 259
 			}
260 260
 
261
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
262
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
261
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
262
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
263 263
 			} else {
264
-				$order->update_meta_data( '_stripe_source_id', $response->id );
264
+				$order->update_meta_data('_stripe_source_id', $response->id);
265 265
 				$order->save();
266 266
 			}
267 267
 
268
-			WC_Stripe_Logger::log( 'Info: Redirecting to EPS...' );
268
+			WC_Stripe_Logger::log('Info: Redirecting to EPS...');
269 269
 
270 270
 			return array(
271 271
 				'result'   => 'success',
272
-				'redirect' => esc_url_raw( $response->redirect->url ),
272
+				'redirect' => esc_url_raw($response->redirect->url),
273 273
 			);
274
-		} catch ( Exception $e ) {
275
-			wc_add_notice( $e->getMessage(), 'error' );
276
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
274
+		} catch (Exception $e) {
275
+			wc_add_notice($e->getMessage(), 'error');
276
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
277 277
 
278
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
278
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
279 279
 
280
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
281
-				$this->send_failed_order_email( $order_id );
280
+			if ($order->has_status(array('pending', 'failed'))) {
281
+				$this->send_failed_order_email($order_id);
282 282
 			}
283 283
 
284 284
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-alipay.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id           = 'stripe_alipay';
60
-		$this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports           = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * @return bool
123 123
 	 */
124 124
 	public function is_available() {
125
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
125
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
126 126
 			return false;
127 127
 		}
128 128
 
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 
142 142
 		$icons_str = '';
143 143
 
144
-		$icons_str .= isset( $icons['alipay'] ) ? $icons['alipay'] : '';
144
+		$icons_str .= isset($icons['alipay']) ? $icons['alipay'] : '';
145 145
 
146
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
146
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
147 147
 	}
148 148
 
149 149
 	/**
@@ -153,19 +153,19 @@  discard block
 block discarded – undo
153 153
 	 * @version 4.0.0
154 154
 	 */
155 155
 	public function payment_scripts() {
156
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
156
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
157 157
 			return;
158 158
 		}
159 159
 
160
-		wp_enqueue_style( 'stripe_styles' );
161
-		wp_enqueue_script( 'woocommerce_stripe' );
160
+		wp_enqueue_style('stripe_styles');
161
+		wp_enqueue_script('woocommerce_stripe');
162 162
 	}
163 163
 
164 164
 	/**
165 165
 	 * Initialize Gateway Settings Form Fields.
166 166
 	 */
167 167
 	public function init_form_fields() {
168
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' );
168
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php');
169 169
 	}
170 170
 
171 171
 	/**
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 		$description = $this->get_description();
179 179
 
180 180
 		// If paying from order, we need to get total from order not cart.
181
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
182
-			$order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) );
181
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
182
+			$order = wc_get_order(wc_clean($wp->query_vars['order-pay']));
183 183
 			$total = $order->get_total();
184 184
 		}
185 185
 
186
-		if ( is_add_payment_method_page() ) {
187
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
186
+		if (is_add_payment_method_page()) {
187
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
188 188
 			$total           = '';
189 189
 		} else {
190 190
 			$pay_button_text = '';
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 
193 193
 		echo '<div
194 194
 			id="stripe-alipay-payment-data"
195
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
196
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
195
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
196
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
197 197
 
198
-		if ( $description ) {
199
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
198
+		if ($description) {
199
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
200 200
 		}
201 201
 
202 202
 		echo '</div>';
@@ -210,24 +210,24 @@  discard block
 block discarded – undo
210 210
 	 * @param object $order
211 211
 	 * @return mixed
212 212
 	 */
213
-	public function create_source( $order ) {
214
-		$currency              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency();
215
-		$order_id              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
216
-		$return_url            = $this->get_stripe_return_url( $order );
213
+	public function create_source($order) {
214
+		$currency              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency();
215
+		$order_id              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
216
+		$return_url            = $this->get_stripe_return_url($order);
217 217
 		$post_data             = array();
218
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
219
-		$post_data['currency'] = strtolower( $currency );
218
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
219
+		$post_data['currency'] = strtolower($currency);
220 220
 		$post_data['type']     = 'alipay';
221
-		$post_data['owner']    = $this->get_owner_details( $order );
222
-		$post_data['redirect'] = array( 'return_url' => $return_url );
221
+		$post_data['owner']    = $this->get_owner_details($order);
222
+		$post_data['redirect'] = array('return_url' => $return_url);
223 223
 
224
-		if ( ! empty( $this->statement_descriptor ) ) {
225
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
224
+		if ( ! empty($this->statement_descriptor)) {
225
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
226 226
 		}
227 227
 
228
-		WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' );
228
+		WC_Stripe_Logger::log('Info: Begin creating Alipay source');
229 229
 
230
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' );
230
+		return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources');
231 231
 	}
232 232
 
233 233
 	/**
@@ -241,53 +241,53 @@  discard block
 block discarded – undo
241 241
 	 *
242 242
 	 * @return array|void
243 243
 	 */
244
-	public function process_payment( $order_id, $retry = true, $force_save_save = false ) {
244
+	public function process_payment($order_id, $retry = true, $force_save_save = false) {
245 245
 		try {
246
-			$order = wc_get_order( $order_id );
246
+			$order = wc_get_order($order_id);
247 247
 
248 248
 			// This will throw exception if not valid.
249
-			$this->validate_minimum_order_amount( $order );
249
+			$this->validate_minimum_order_amount($order);
250 250
 
251 251
 			// This comes from the create account checkbox in the checkout page.
252
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
252
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
253 253
 
254
-			if ( $create_account ) {
255
-				$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
256
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
254
+			if ($create_account) {
255
+				$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
256
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
257 257
 				$new_stripe_customer->create_customer();
258 258
 			}
259 259
 
260
-			$response = $this->create_source( $order );
260
+			$response = $this->create_source($order);
261 261
 
262
-			if ( ! empty( $response->error ) ) {
263
-				$order->add_order_note( $response->error->message );
262
+			if ( ! empty($response->error)) {
263
+				$order->add_order_note($response->error->message);
264 264
 
265
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
265
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
266 266
 			}
267 267
 
268
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
269
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
268
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
269
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
270 270
 			} else {
271
-				$order->update_meta_data( '_stripe_source_id', $response->id );
271
+				$order->update_meta_data('_stripe_source_id', $response->id);
272 272
 				$order->save();
273 273
 			}
274 274
 
275
-			WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' );
275
+			WC_Stripe_Logger::log('Info: Redirecting to Alipay...');
276 276
 
277 277
 			return array(
278 278
 				'result'   => 'success',
279
-				'redirect' => esc_url_raw( $response->redirect->url ),
279
+				'redirect' => esc_url_raw($response->redirect->url),
280 280
 			);
281
-		} catch ( WC_Stripe_Exception $e ) {
282
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
283
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
281
+		} catch (WC_Stripe_Exception $e) {
282
+			wc_add_notice($e->getLocalizedMessage(), 'error');
283
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
284 284
 
285
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
285
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
286 286
 
287
-			$statuses = array( 'pending', 'failed' );
287
+			$statuses = array('pending', 'failed');
288 288
 
289
-			if ( $order->has_status( $statuses ) ) {
290
-				$this->send_failed_order_email( $order_id );
289
+			if ($order->has_status($statuses)) {
290
+				$this->send_failed_order_email($order_id);
291 291
 			}
292 292
 
293 293
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sepa.php 1 patch
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
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&section=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&section=stripe'));
78 78
 		$this->has_fields         = true;
79 79
 		$this->supports           = array(
80 80
 			'products',
@@ -100,28 +100,28 @@  discard block
 block discarded – undo
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->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
108
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
109
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
110
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
111
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
112
-
113
-		if ( $this->testmode ) {
114
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
115
-			$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->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
108
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
109
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
110
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
111
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
112
+
113
+		if ($this->testmode) {
114
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
115
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
116 116
 		}
117 117
 
118
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
119
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
118
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
119
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
120 120
 
121
-		if ( WC_Stripe_Helper::is_pre_orders_exists() ) {
121
+		if (WC_Stripe_Helper::is_pre_orders_exists()) {
122 122
 			$this->pre_orders = new WC_Stripe_Pre_Orders_Compat();
123 123
 
124
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) );
124
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment'));
125 125
 		}
126 126
 	}
127 127
 
@@ -149,11 +149,11 @@  discard block
 block discarded – undo
149 149
 	 * @return bool
150 150
 	 */
151 151
 	public function is_available() {
152
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
152
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
153 153
 			return false;
154 154
 		}
155 155
 
156
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
156
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
157 157
 			return false;
158 158
 		}
159 159
 
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
 
173 173
 		$icons_str = '';
174 174
 
175
-		$icons_str .= isset( $icons['sepa'] ) ? $icons['sepa'] : '';
175
+		$icons_str .= isset($icons['sepa']) ? $icons['sepa'] : '';
176 176
 
177
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
177
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
178 178
 	}
179 179
 
180 180
 	/**
@@ -185,19 +185,19 @@  discard block
 block discarded – undo
185 185
 	 * @access public
186 186
 	 */
187 187
 	public function payment_scripts() {
188
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
188
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
189 189
 			return;
190 190
 		}
191 191
 
192
-		wp_enqueue_style( 'stripe_styles' );
193
-		wp_enqueue_script( 'woocommerce_stripe' );
192
+		wp_enqueue_style('stripe_styles');
193
+		wp_enqueue_script('woocommerce_stripe');
194 194
 	}
195 195
 
196 196
 	/**
197 197
 	 * Initialize Gateway Settings Form Fields.
198 198
 	 */
199 199
 	public function init_form_fields() {
200
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
200
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
201 201
 	}
202 202
 
203 203
 	/**
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 */
210 210
 	public function mandate_display() {
211 211
 		/* translators: statement descriptor */
212
-		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 ) );
212
+		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));
213 213
 	}
214 214
 
215 215
 	/**
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
 	 */
221 221
 	public function form() {
222 222
 		?>
223
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
224
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
223
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
224
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
225 225
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
226 226
 			<p class="form-row form-row-wide">
227 227
 				<label for="stripe-iban-element">
228
-					<?php esc_html_e( 'IBAN.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
228
+					<?php esc_html_e('IBAN.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
229 229
 				</label>
230 230
 				<div id="stripe-iban-element" class="wc-stripe-iban-element-field">
231 231
 					<!-- A Stripe Element will be inserted here. -->
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 			<!-- Used to display form errors -->
236 236
 			<div class="stripe-source-errors" role="alert"></div>
237 237
 			<br />
238
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
238
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
239 239
 			<div class="clear"></div>
240 240
 		</fieldset>
241 241
 		<?php
@@ -247,45 +247,45 @@  discard block
 block discarded – undo
247 247
 	public function payment_fields() {
248 248
 		global $wp;
249 249
 		$total                = WC()->cart->total;
250
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
250
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
251 251
 		$description          = $this->get_description();
252
-		$description          = ! empty( $description ) ? $description : '';
252
+		$description          = ! empty($description) ? $description : '';
253 253
 
254 254
 		// If paying from order, we need to get total from order not cart.
255
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
256
-			$order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) );
255
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
256
+			$order = wc_get_order(wc_clean($wp->query_vars['order-pay']));
257 257
 			$total = $order->get_total();
258 258
 		}
259 259
 
260
-		if ( is_add_payment_method_page() ) {
260
+		if (is_add_payment_method_page()) {
261 261
 			$total = '';
262 262
 		}
263 263
 
264 264
 		echo '<div
265 265
 			id="stripe-sepa_debit-payment-data"
266
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
267
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
266
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
267
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
268 268
 
269
-		if ( $this->testmode ) {
270
-			$description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
269
+		if ($this->testmode) {
270
+			$description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
271 271
 		}
272 272
 
273
-		$description = trim( $description );
273
+		$description = trim($description);
274 274
 
275
-		echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
275
+		echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
276 276
 
277
-		if ( $display_tokenization ) {
277
+		if ($display_tokenization) {
278 278
 			$this->tokenization_script();
279 279
 			$this->saved_payment_methods();
280 280
 		}
281 281
 
282 282
 		$this->form();
283 283
 
284
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
284
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
285 285
 			$this->save_payment_method_checkbox();
286 286
 		}
287 287
 
288
-		do_action( 'wc_stripe_sepa_payment_fields', $this->id );
288
+		do_action('wc_stripe_sepa_payment_fields', $this->id);
289 289
 
290 290
 		echo '</div>';
291 291
 	}
@@ -301,99 +301,99 @@  discard block
 block discarded – undo
301 301
 	 *
302 302
 	 * @return array|void
303 303
 	 */
304
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
304
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
305 305
 		try {
306
-			$order = wc_get_order( $order_id );
306
+			$order = wc_get_order($order_id);
307 307
 
308
-			if ( $this->maybe_process_pre_orders( $order_id ) ) {
309
-				return $this->pre_orders->process_pre_order( $order_id );
308
+			if ($this->maybe_process_pre_orders($order_id)) {
309
+				return $this->pre_orders->process_pre_order($order_id);
310 310
 			}
311 311
 
312 312
 			// This comes from the create account checkbox in the checkout page.
313
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
313
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
314 314
 
315
-			if ( $create_account ) {
316
-				$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
317
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
315
+			if ($create_account) {
316
+				$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
317
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
318 318
 				$new_stripe_customer->create_customer();
319 319
 			}
320 320
 
321
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
321
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
322 322
 
323
-			$this->save_source_to_order( $order, $prepared_source );
323
+			$this->save_source_to_order($order, $prepared_source);
324 324
 
325 325
 			// Result from Stripe API request.
326 326
 			$response = null;
327 327
 
328
-			if ( $order->get_total() > 0 ) {
328
+			if ($order->get_total() > 0) {
329 329
 				// This will throw exception if not valid.
330
-				$this->validate_minimum_order_amount( $order );
330
+				$this->validate_minimum_order_amount($order);
331 331
 
332
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
332
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
333 333
 
334 334
 				// Make the request.
335
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
335
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
336 336
 
337
-				if ( ! empty( $response->error ) ) {
337
+				if ( ! empty($response->error)) {
338 338
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
339
-					if ( $this->is_no_such_customer_error( $response->error ) ) {
340
-						if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
341
-							delete_user_option( $order->customer_user, '_stripe_customer_id' );
342
-							delete_post_meta( $order_id, '_stripe_customer_id' );
339
+					if ($this->is_no_such_customer_error($response->error)) {
340
+						if (WC_Stripe_Helper::is_wc_lt('3.0')) {
341
+							delete_user_option($order->customer_user, '_stripe_customer_id');
342
+							delete_post_meta($order_id, '_stripe_customer_id');
343 343
 						} else {
344
-							delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
345
-							$order->delete_meta_data( '_stripe_customer_id' );
344
+							delete_user_option($order->get_customer_id(), '_stripe_customer_id');
345
+							$order->delete_meta_data('_stripe_customer_id');
346 346
 							$order->save();
347 347
 						}
348 348
 					}
349 349
 
350
-					if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
350
+					if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
351 351
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
352
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
352
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
353 353
 						$wc_token->delete();
354
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
355
-						$order->add_order_note( $localized_message );
356
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
354
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
355
+						$order->add_order_note($localized_message);
356
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
357 357
 					}
358 358
 
359 359
 					// We want to retry.
360
-					if ( $this->is_retryable_error( $response->error ) ) {
361
-						if ( $retry ) {
360
+					if ($this->is_retryable_error($response->error)) {
361
+						if ($retry) {
362 362
 							// Don't do anymore retries after this.
363
-							if ( 5 <= $this->retry_interval ) {
363
+							if (5 <= $this->retry_interval) {
364 364
 
365
-								return $this->process_payment( $order_id, false, $force_save_source );
365
+								return $this->process_payment($order_id, false, $force_save_source);
366 366
 							}
367 367
 
368
-							sleep( $this->retry_interval );
368
+							sleep($this->retry_interval);
369 369
 
370 370
 							$this->retry_interval++;
371 371
 
372
-							return $this->process_payment( $order_id, true, $force_save_source );
372
+							return $this->process_payment($order_id, true, $force_save_source);
373 373
 						} else {
374
-							$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
375
-							$order->add_order_note( $localized_message );
376
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
374
+							$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
375
+							$order->add_order_note($localized_message);
376
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
377 377
 						}
378 378
 					}
379 379
 
380 380
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
381 381
 
382
-					if ( 'card_error' === $response->error->type ) {
383
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
382
+					if ('card_error' === $response->error->type) {
383
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
384 384
 					} else {
385
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
385
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
386 386
 					}
387 387
 
388
-					$order->add_order_note( $localized_message );
388
+					$order->add_order_note($localized_message);
389 389
 
390
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
390
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
391 391
 				}
392 392
 
393
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
393
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
394 394
 
395 395
 				// Process valid response.
396
-				$this->process_response( $response, $order );
396
+				$this->process_response($response, $order);
397 397
 			} else {
398 398
 				$order->payment_complete();
399 399
 			}
@@ -404,17 +404,17 @@  discard block
 block discarded – undo
404 404
 			// Return thank you page redirect.
405 405
 			return array(
406 406
 				'result'   => 'success',
407
-				'redirect' => $this->get_return_url( $order ),
407
+				'redirect' => $this->get_return_url($order),
408 408
 			);
409 409
 
410
-		} catch ( WC_Stripe_Exception $e ) {
411
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
412
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
410
+		} catch (WC_Stripe_Exception $e) {
411
+			wc_add_notice($e->getLocalizedMessage(), 'error');
412
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
413 413
 
414
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
414
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
415 415
 
416
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
417
-				$this->send_failed_order_email( $order_id );
416
+			if ($order->has_status(array('pending', 'failed'))) {
417
+				$this->send_failed_order_email($order_id);
418 418
 			}
419 419
 
420 420
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-multibanco.php 1 patch
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id           = 'stripe_multibanco';
60
-		$this->method_title = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' );
60
+		$this->method_title = __('Stripe Multibanco', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports           = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,27 +71,27 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
91
-		add_action( 'woocommerce_thankyou_stripe_multibanco', array( $this, 'thankyou_page' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91
+		add_action('woocommerce_thankyou_stripe_multibanco', array($this, 'thankyou_page'));
92 92
 
93 93
 		// Customer Emails
94
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
94
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
95 95
 	}
96 96
 
97 97
 	/**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @return bool
119 119
 	 */
120 120
 	public function is_available() {
121
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
121
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
122 122
 			return false;
123 123
 		}
124 124
 
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
 
138 138
 		$icons_str = '';
139 139
 
140
-		$icons_str .= isset( $icons['multibanco'] ) ? $icons['multibanco'] : '';
140
+		$icons_str .= isset($icons['multibanco']) ? $icons['multibanco'] : '';
141 141
 
142
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
142
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
143 143
 	}
144 144
 
145 145
 	/**
@@ -150,19 +150,19 @@  discard block
 block discarded – undo
150 150
 	 * @access public
151 151
 	 */
152 152
 	public function payment_scripts() {
153
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
153
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
154 154
 			return;
155 155
 		}
156 156
 
157
-		wp_enqueue_style( 'stripe_styles' );
158
-		wp_enqueue_script( 'woocommerce_stripe' );
157
+		wp_enqueue_style('stripe_styles');
158
+		wp_enqueue_script('woocommerce_stripe');
159 159
 	}
160 160
 
161 161
 	/**
162 162
 	 * Initialize Gateway Settings Form Fields.
163 163
 	 */
164 164
 	public function init_form_fields() {
165
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-multibanco-settings.php' );
165
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-multibanco-settings.php');
166 166
 	}
167 167
 
168 168
 	/**
@@ -175,13 +175,13 @@  discard block
 block discarded – undo
175 175
 		$description = $this->get_description();
176 176
 
177 177
 		// If paying from order, we need to get total from order not cart.
178
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
179
-			$order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) );
178
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
179
+			$order = wc_get_order(wc_clean($wp->query_vars['order-pay']));
180 180
 			$total = $order->get_total();
181 181
 		}
182 182
 
183
-		if ( is_add_payment_method_page() ) {
184
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
183
+		if (is_add_payment_method_page()) {
184
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
185 185
 			$total           = '';
186 186
 		} else {
187 187
 			$pay_button_text = '';
@@ -189,11 +189,11 @@  discard block
 block discarded – undo
189 189
 
190 190
 		echo '<div
191 191
 			id="stripe-multibanco-payment-data"
192
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
193
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
192
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
193
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
194 194
 
195
-		if ( $description ) {
196
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
195
+		if ($description) {
196
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
197 197
 		}
198 198
 
199 199
 		echo '</div>';
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
 	 *
205 205
 	 * @param int $order_id
206 206
 	 */
207
-	public function thankyou_page( $order_id ) {
208
-		$this->get_instructions( $order_id );
207
+	public function thankyou_page($order_id) {
208
+		$this->get_instructions($order_id);
209 209
 	}
210 210
 
211 211
 	/**
@@ -217,15 +217,15 @@  discard block
 block discarded – undo
217 217
 	 * @param bool $sent_to_admin
218 218
 	 * @param bool $plain_text
219 219
 	 */
220
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
221
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
220
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
221
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
222 222
 
223
-		$payment_method = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method();
223
+		$payment_method = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method();
224 224
 
225
-		if ( ! $sent_to_admin && 'stripe_multibanco' === $payment_method && $order->has_status( 'on-hold' ) ) {
226
-			WC_Stripe_Logger::log( 'Sending multibanco email for order #' . $order_id );
225
+		if ( ! $sent_to_admin && 'stripe_multibanco' === $payment_method && $order->has_status('on-hold')) {
226
+			WC_Stripe_Logger::log('Sending multibanco email for order #' . $order_id);
227 227
 
228
-			$this->get_instructions( $order_id, $plain_text );
228
+			$this->get_instructions($order_id, $plain_text);
229 229
 		}
230 230
 	}
231 231
 
@@ -236,34 +236,34 @@  discard block
 block discarded – undo
236 236
 	 * @version 4.1.0
237 237
 	 * @param int $order_id
238 238
 	 */
239
-	public function get_instructions( $order_id, $plain_text = false ) {
240
-		$data = get_post_meta( $order_id, '_stripe_multibanco', true );
239
+	public function get_instructions($order_id, $plain_text = false) {
240
+		$data = get_post_meta($order_id, '_stripe_multibanco', true);
241 241
 
242
-		if ( $plain_text ) {
243
-			esc_html_e( 'MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe' ) . "\n\n";
242
+		if ($plain_text) {
243
+			esc_html_e('MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe') . "\n\n";
244 244
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
245
-			esc_html_e( 'Montante:', 'woocommerce-gateway-stripe' ) . "\n\n";
245
+			esc_html_e('Montante:', 'woocommerce-gateway-stripe') . "\n\n";
246 246
 			echo $data['amount'] . "\n\n";
247 247
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
248
-			esc_html_e( 'Entidade:', 'woocommerce-gateway-stripe' ) . "\n\n";
248
+			esc_html_e('Entidade:', 'woocommerce-gateway-stripe') . "\n\n";
249 249
 			echo $data['entity'] . "\n\n";
250 250
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
251
-			esc_html_e( 'Referencia:', 'woocommerce-gateway-stripe' ) . "\n\n";
251
+			esc_html_e('Referencia:', 'woocommerce-gateway-stripe') . "\n\n";
252 252
 			echo $data['reference'] . "\n\n";
253 253
 		} else {
254 254
 			?>
255
-			<h3><?php esc_html_e( 'MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe' ); ?></h3>
255
+			<h3><?php esc_html_e('MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe'); ?></h3>
256 256
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
257 257
 			<li class="woocommerce-order-overview__order order">
258
-				<?php esc_html_e( 'Montante:', 'woocommerce-gateway-stripe' ); ?>
258
+				<?php esc_html_e('Montante:', 'woocommerce-gateway-stripe'); ?>
259 259
 				<strong><?php echo $data['amount']; ?></strong>
260 260
 			</li>
261 261
 			<li class="woocommerce-order-overview__order order">
262
-				<?php esc_html_e( 'Entidade:', 'woocommerce-gateway-stripe' ); ?>
262
+				<?php esc_html_e('Entidade:', 'woocommerce-gateway-stripe'); ?>
263 263
 				<strong><?php echo $data['entity']; ?></strong>
264 264
 			</li>
265 265
 			<li class="woocommerce-order-overview__order order">
266
-				<?php esc_html_e( 'Referencia:', 'woocommerce-gateway-stripe' ); ?>
266
+				<?php esc_html_e('Referencia:', 'woocommerce-gateway-stripe'); ?>
267 267
 				<strong><?php echo $data['reference']; ?></strong>
268 268
 			</li>
269 269
 			</ul>
@@ -279,16 +279,16 @@  discard block
 block discarded – undo
279 279
 	 * @param object $order
280 280
 	 * @param object $source_object
281 281
 	 */
282
-	public function save_instructions( $order, $source_object ) {
282
+	public function save_instructions($order, $source_object) {
283 283
 		$data = array(
284 284
 			'amount'    => $order->get_formatted_order_total(),
285 285
 			'entity'    => $source_object->multibanco->entity,
286 286
 			'reference' => $source_object->multibanco->reference,
287 287
 		);
288 288
 
289
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
289
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
290 290
 
291
-		update_post_meta( $order_id, '_stripe_multibanco', $data );
291
+		update_post_meta($order_id, '_stripe_multibanco', $data);
292 292
 	}
293 293
 
294 294
 	/**
@@ -299,24 +299,24 @@  discard block
 block discarded – undo
299 299
 	 * @param object $order
300 300
 	 * @return mixed
301 301
 	 */
302
-	public function create_source( $order ) {
303
-		$currency              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency();
304
-		$order_id              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
305
-		$return_url            = $this->get_stripe_return_url( $order );
302
+	public function create_source($order) {
303
+		$currency              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency();
304
+		$order_id              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
305
+		$return_url            = $this->get_stripe_return_url($order);
306 306
 		$post_data             = array();
307
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
308
-		$post_data['currency'] = strtolower( $currency );
307
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
308
+		$post_data['currency'] = strtolower($currency);
309 309
 		$post_data['type']     = 'multibanco';
310
-		$post_data['owner']    = $this->get_owner_details( $order );
311
-		$post_data['redirect'] = array( 'return_url' => $return_url );
310
+		$post_data['owner']    = $this->get_owner_details($order);
311
+		$post_data['redirect'] = array('return_url' => $return_url);
312 312
 
313
-		if ( ! empty( $this->statement_descriptor ) ) {
314
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
313
+		if ( ! empty($this->statement_descriptor)) {
314
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
315 315
 		}
316 316
 
317
-		WC_Stripe_Logger::log( 'Info: Begin creating Multibanco source' );
317
+		WC_Stripe_Logger::log('Info: Begin creating Multibanco source');
318 318
 
319
-		return WC_Stripe_API::request( $post_data, 'sources' );
319
+		return WC_Stripe_API::request($post_data, 'sources');
320 320
 	}
321 321
 
322 322
 	/**
@@ -330,62 +330,62 @@  discard block
 block discarded – undo
330 330
 	 *
331 331
 	 * @return array|void
332 332
 	 */
333
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
333
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
334 334
 		try {
335
-			$order = wc_get_order( $order_id );
335
+			$order = wc_get_order($order_id);
336 336
 
337 337
 			// This will throw exception if not valid.
338
-			$this->validate_minimum_order_amount( $order );
338
+			$this->validate_minimum_order_amount($order);
339 339
 
340 340
 			// This comes from the create account checkbox in the checkout page.
341
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
341
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
342 342
 
343
-			if ( $create_account ) {
344
-				$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
345
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
343
+			if ($create_account) {
344
+				$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
345
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
346 346
 				$new_stripe_customer->create_customer();
347 347
 			}
348 348
 
349
-			$response = $this->create_source( $order );
349
+			$response = $this->create_source($order);
350 350
 
351
-			if ( ! empty( $response->error ) ) {
352
-				$order->add_order_note( $response->error->message );
351
+			if ( ! empty($response->error)) {
352
+				$order->add_order_note($response->error->message);
353 353
 
354
-				throw new Exception( $response->error->message );
354
+				throw new Exception($response->error->message);
355 355
 			}
356 356
 
357
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
358
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
357
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
358
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
359 359
 			} else {
360
-				$order->update_meta_data( '_stripe_source_id', $response->id );
360
+				$order->update_meta_data('_stripe_source_id', $response->id);
361 361
 				$order->save();
362 362
 			}
363 363
 
364
-			$this->save_instructions( $order, $response );
364
+			$this->save_instructions($order, $response);
365 365
 
366 366
 			// Mark as on-hold (we're awaiting the payment)
367
-			$order->update_status( 'on-hold', __( 'Awaiting Multibanco payment', 'woocommerce-gateway-stripe' ) );
367
+			$order->update_status('on-hold', __('Awaiting Multibanco payment', 'woocommerce-gateway-stripe'));
368 368
 
369 369
 			// Reduce stock levels
370
-			wc_reduce_stock_levels( $order_id );
370
+			wc_reduce_stock_levels($order_id);
371 371
 
372 372
 			// Remove cart
373 373
 			WC()->cart->empty_cart();
374 374
 
375
-			WC_Stripe_Logger::log( 'Info: Redirecting to Multibanco...' );
375
+			WC_Stripe_Logger::log('Info: Redirecting to Multibanco...');
376 376
 
377 377
 			return array(
378 378
 				'result'   => 'success',
379
-				'redirect' => esc_url_raw( $response->redirect->url ),
379
+				'redirect' => esc_url_raw($response->redirect->url),
380 380
 			);
381
-		} catch ( Exception $e ) {
382
-			wc_add_notice( $e->getMessage(), 'error' );
383
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
381
+		} catch (Exception $e) {
382
+			wc_add_notice($e->getMessage(), 'error');
383
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
384 384
 
385
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
385
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
386 386
 
387
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
388
-				$this->send_failed_order_email( $order_id );
387
+			if ($order->has_status(array('pending', 'failed'))) {
388
+				$this->send_failed_order_email($order_id);
389 389
 			}
390 390
 
391 391
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-ideal.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id           = 'stripe_ideal';
60
-		$this->method_title = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
60
+		$this->method_title = __('Stripe iDeal', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports           = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @return bool
115 115
 	 */
116 116
 	public function is_available() {
117
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
117
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
118 118
 			return false;
119 119
 		}
120 120
 
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
 
134 134
 		$icons_str = '';
135 135
 
136
-		$icons_str .= isset( $icons['ideal'] ) ? $icons['ideal'] : '';
136
+		$icons_str .= isset($icons['ideal']) ? $icons['ideal'] : '';
137 137
 
138
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
138
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
139 139
 	}
140 140
 
141 141
 	/**
@@ -146,19 +146,19 @@  discard block
 block discarded – undo
146 146
 	 * @access public
147 147
 	 */
148 148
 	public function payment_scripts() {
149
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
149
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
150 150
 			return;
151 151
 		}
152 152
 
153
-		wp_enqueue_style( 'stripe_styles' );
154
-		wp_enqueue_script( 'woocommerce_stripe' );
153
+		wp_enqueue_style('stripe_styles');
154
+		wp_enqueue_script('woocommerce_stripe');
155 155
 	}
156 156
 
157 157
 	/**
158 158
 	 * Initialize Gateway Settings Form Fields.
159 159
 	 */
160 160
 	public function init_form_fields() {
161
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' );
161
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php');
162 162
 	}
163 163
 
164 164
 	/**
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 		$description = $this->get_description();
172 172
 
173 173
 		// If paying from order, we need to get total from order not cart.
174
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
175
-			$order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) );
174
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
175
+			$order = wc_get_order(wc_clean($wp->query_vars['order-pay']));
176 176
 			$total = $order->get_total();
177 177
 		}
178 178
 
179
-		if ( is_add_payment_method_page() ) {
180
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
179
+		if (is_add_payment_method_page()) {
180
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
181 181
 			$total           = '';
182 182
 		} else {
183 183
 			$pay_button_text = '';
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 
186 186
 		echo '<div
187 187
 			id="stripe-ideal-payment-data"
188
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
189
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
188
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
189
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
190 190
 
191
-		if ( $description ) {
192
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
191
+		if ($description) {
192
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
193 193
 		}
194 194
 
195 195
 		echo '</div>';
@@ -203,24 +203,24 @@  discard block
 block discarded – undo
203 203
 	 * @param object $order
204 204
 	 * @return mixed
205 205
 	 */
206
-	public function create_source( $order ) {
207
-		$currency              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency();
208
-		$order_id              = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
209
-		$return_url            = $this->get_stripe_return_url( $order );
206
+	public function create_source($order) {
207
+		$currency              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency();
208
+		$order_id              = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
209
+		$return_url            = $this->get_stripe_return_url($order);
210 210
 		$post_data             = array();
211
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
212
-		$post_data['currency'] = strtolower( $currency );
211
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
212
+		$post_data['currency'] = strtolower($currency);
213 213
 		$post_data['type']     = 'ideal';
214
-		$post_data['owner']    = $this->get_owner_details( $order );
215
-		$post_data['redirect'] = array( 'return_url' => $return_url );
214
+		$post_data['owner']    = $this->get_owner_details($order);
215
+		$post_data['redirect'] = array('return_url' => $return_url);
216 216
 
217
-		if ( ! empty( $this->statement_descriptor ) ) {
218
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
217
+		if ( ! empty($this->statement_descriptor)) {
218
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
219 219
 		}
220 220
 
221
-		WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' );
221
+		WC_Stripe_Logger::log('Info: Begin creating iDeal source');
222 222
 
223
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_ideal_source', $post_data, $order ), 'sources' );
223
+		return WC_Stripe_API::request(apply_filters('wc_stripe_ideal_source', $post_data, $order), 'sources');
224 224
 	}
225 225
 
226 226
 	/**
@@ -234,51 +234,51 @@  discard block
 block discarded – undo
234 234
 	 *
235 235
 	 * @return array|void
236 236
 	 */
237
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
237
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
238 238
 		try {
239
-			$order = wc_get_order( $order_id );
239
+			$order = wc_get_order($order_id);
240 240
 
241 241
 			// This will throw exception if not valid.
242
-			$this->validate_minimum_order_amount( $order );
242
+			$this->validate_minimum_order_amount($order);
243 243
 
244 244
 			// This comes from the create account checkbox in the checkout page.
245
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
245
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
246 246
 
247
-			if ( $create_account ) {
248
-				$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
249
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
247
+			if ($create_account) {
248
+				$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
249
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
250 250
 				$new_stripe_customer->create_customer();
251 251
 			}
252 252
 
253
-			$response = $this->create_source( $order );
253
+			$response = $this->create_source($order);
254 254
 
255
-			if ( ! empty( $response->error ) ) {
256
-				$order->add_order_note( $response->error->message );
255
+			if ( ! empty($response->error)) {
256
+				$order->add_order_note($response->error->message);
257 257
 
258
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
258
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
259 259
 			}
260 260
 
261
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
262
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
261
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
262
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
263 263
 			} else {
264
-				$order->update_meta_data( '_stripe_source_id', $response->id );
264
+				$order->update_meta_data('_stripe_source_id', $response->id);
265 265
 				$order->save();
266 266
 			}
267 267
 
268
-			WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' );
268
+			WC_Stripe_Logger::log('Info: Redirecting to iDeal...');
269 269
 
270 270
 			return array(
271 271
 				'result'   => 'success',
272
-				'redirect' => esc_url_raw( $response->redirect->url ),
272
+				'redirect' => esc_url_raw($response->redirect->url),
273 273
 			);
274
-		} catch ( WC_Stripe_Exception $e ) {
275
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
276
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
274
+		} catch (WC_Stripe_Exception $e) {
275
+			wc_add_notice($e->getLocalizedMessage(), 'error');
276
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
277 277
 
278
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
278
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
279 279
 
280
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
281
-				$this->send_failed_order_email( $order_id );
280
+			if ($order->has_status(array('pending', 'failed'))) {
281
+				$this->send_failed_order_email($order_id);
282 282
 			}
283 283
 
284 284
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bancontact.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id           = 'stripe_bancontact';
60
-		$this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
60
+		$this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports           = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
91 91
 	}
92 92
 
93 93
 	/**
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @return bool
115 115
 	 */
116 116
 	public function is_available() {
117
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
117
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
118 118
 			return false;
119 119
 		}
120 120
 
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
 
134 134
 		$icons_str = '';
135 135
 
136
-		$icons_str .= isset( $icons['bancontact'] ) ? $icons['bancontact'] : '';
136
+		$icons_str .= isset($icons['bancontact']) ? $icons['bancontact'] : '';
137 137
 
138
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
138
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
139 139
 	}
140 140
 
141 141
 	/**
@@ -146,19 +146,19 @@  discard block
 block discarded – undo
146 146
 	 * @access public
147 147
 	 */
148 148
 	public function payment_scripts() {
149
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
149
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
150 150
 			return;
151 151
 		}
152 152
 
153
-		wp_enqueue_style( 'stripe_styles' );
154
-		wp_enqueue_script( 'woocommerce_stripe' );
153
+		wp_enqueue_style('stripe_styles');
154
+		wp_enqueue_script('woocommerce_stripe');
155 155
 	}
156 156
 
157 157
 	/**
158 158
 	 * Initialize Gateway Settings Form Fields.
159 159
 	 */
160 160
 	public function init_form_fields() {
161
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' );
161
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php');
162 162
 	}
163 163
 
164 164
 	/**
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 		$description = $this->get_description();
172 172
 
173 173
 		// If paying from order, we need to get total from order not cart.
174
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
175
-			$order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) );
174
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
175
+			$order = wc_get_order(wc_clean($wp->query_vars['order-pay']));
176 176
 			$total = $order->get_total();
177 177
 		}
178 178
 
179
-		if ( is_add_payment_method_page() ) {
180
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
179
+		if (is_add_payment_method_page()) {
180
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
181 181
 			$total           = '';
182 182
 		} else {
183 183
 			$pay_button_text = '';
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 
186 186
 		echo '<div
187 187
 			id="stripe-bancontact-payment-data"
188
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
189
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
188
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
189
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
190 190
 
191
-		if ( $description ) {
192
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
191
+		if ($description) {
192
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
193 193
 		}
194 194
 
195 195
 		echo '</div>';
@@ -203,25 +203,25 @@  discard block
 block discarded – undo
203 203
 	 * @param object $order
204 204
 	 * @return mixed
205 205
 	 */
206
-	public function create_source( $order ) {
207
-		$currency                = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency();
208
-		$order_id                = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
209
-		$return_url              = $this->get_stripe_return_url( $order );
206
+	public function create_source($order) {
207
+		$currency                = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency();
208
+		$order_id                = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
209
+		$return_url              = $this->get_stripe_return_url($order);
210 210
 		$post_data               = array();
211
-		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
212
-		$post_data['currency']   = strtolower( $currency );
211
+		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
212
+		$post_data['currency']   = strtolower($currency);
213 213
 		$post_data['type']       = 'bancontact';
214
-		$post_data['owner']      = $this->get_owner_details( $order );
215
-		$post_data['redirect']   = array( 'return_url' => $return_url );
216
-		$post_data['bancontact'] = array( 'preferred_language' => $this->get_locale() );
214
+		$post_data['owner']      = $this->get_owner_details($order);
215
+		$post_data['redirect']   = array('return_url' => $return_url);
216
+		$post_data['bancontact'] = array('preferred_language' => $this->get_locale());
217 217
 
218
-		if ( ! empty( $this->statement_descriptor ) ) {
219
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
218
+		if ( ! empty($this->statement_descriptor)) {
219
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
220 220
 		}
221 221
 
222
-		WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' );
222
+		WC_Stripe_Logger::log('Info: Begin creating Bancontact source');
223 223
 
224
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' );
224
+		return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources');
225 225
 	}
226 226
 
227 227
 	/**
@@ -235,51 +235,51 @@  discard block
 block discarded – undo
235 235
 	 *
236 236
 	 * @return array|void
237 237
 	 */
238
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
238
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
239 239
 		try {
240
-			$order = wc_get_order( $order_id );
240
+			$order = wc_get_order($order_id);
241 241
 
242 242
 			// This will throw exception if not valid.
243
-			$this->validate_minimum_order_amount( $order );
243
+			$this->validate_minimum_order_amount($order);
244 244
 
245 245
 			// This comes from the create account checkbox in the checkout page.
246
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
246
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
247 247
 
248
-			if ( $create_account ) {
249
-				$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
250
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
248
+			if ($create_account) {
249
+				$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
250
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
251 251
 				$new_stripe_customer->create_customer();
252 252
 			}
253 253
 
254
-			$response = $this->create_source( $order );
254
+			$response = $this->create_source($order);
255 255
 
256
-			if ( ! empty( $response->error ) ) {
257
-				$order->add_order_note( $response->error->message );
256
+			if ( ! empty($response->error)) {
257
+				$order->add_order_note($response->error->message);
258 258
 
259
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
259
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
260 260
 			}
261 261
 
262
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
263
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
262
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
263
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
264 264
 			} else {
265
-				$order->update_meta_data( '_stripe_source_id', $response->id );
265
+				$order->update_meta_data('_stripe_source_id', $response->id);
266 266
 				$order->save();
267 267
 			}
268 268
 
269
-			WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' );
269
+			WC_Stripe_Logger::log('Info: Redirecting to Bancontact...');
270 270
 
271 271
 			return array(
272 272
 				'result'   => 'success',
273
-				'redirect' => esc_url_raw( $response->redirect->url ),
273
+				'redirect' => esc_url_raw($response->redirect->url),
274 274
 			);
275
-		} catch ( WC_Stripe_Exception $e ) {
276
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
277
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
275
+		} catch (WC_Stripe_Exception $e) {
276
+			wc_add_notice($e->getLocalizedMessage(), 'error');
277
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
278 278
 
279
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
279
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
280 280
 
281
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
282
-				$this->send_failed_order_email( $order_id );
281
+			if ($order->has_status(array('pending', 'failed'))) {
282
+				$this->send_failed_order_email($order_id);
283 283
 			}
284 284
 
285 285
 			return array(
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-subs-compat.php 1 patch
Spacing   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,21 +15,21 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
23
-			add_action( 'wc_stripe_cards_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) );
24
-			add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23
+			add_action('wc_stripe_cards_payment_fields', array($this, 'display_update_subs_payment_checkout'));
24
+			add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2);
25 25
 
26 26
 			// display the credit card used for a subscription in the "My Subscriptions" table
27
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
27
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
28 28
 
29 29
 			// allow store managers to manually set Stripe as the payment method on a subscription
30
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
31
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
32
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
30
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
31
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
32
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
33 33
 
34 34
 			/*
35 35
 			 * WC subscriptions hooks into the "template_redirect" hook with priority 100.
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 			 * See: https://github.com/woocommerce/woocommerce-subscriptions/blob/99a75687e109b64cbc07af6e5518458a6305f366/includes/class-wcs-cart-renewal.php#L165
38 38
 			 * If we are in the "You just need to authorize SCA" flow, we don't want that redirection to happen.
39 39
 			 */
40
-			add_action( 'template_redirect', array( $this, 'remove_order_pay_var' ), 99 );
41
-			add_action( 'template_redirect', array( $this, 'restore_order_pay_var' ), 101 );
40
+			add_action('template_redirect', array($this, 'remove_order_pay_var'), 99);
41
+			add_action('template_redirect', array($this, 'restore_order_pay_var'), 101);
42 42
 		}
43 43
 	}
44 44
 
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
53
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
52
+	public function maybe_hide_save_checkbox($display_tokenization) {
53
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
54 54
 			return false;
55 55
 		}
56 56
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @param  int  $order_id
63 63
 	 * @return boolean
64 64
 	 */
65
-	public function has_subscription( $order_id ) {
66
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
65
+	public function has_subscription($order_id) {
66
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
67 67
 	}
68 68
 
69 69
 	/**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return bool
74 74
 	 */
75 75
 	public function is_subs_change_payment() {
76
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
76
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
77 77
 	}
78 78
 
79 79
 	/**
@@ -83,20 +83,20 @@  discard block
 block discarded – undo
83 83
 	 * @since 4.1.11
84 84
 	 */
85 85
 	public function display_update_subs_payment_checkout() {
86
-		$subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) );
86
+		$subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active'));
87 87
 		if (
88
-			apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) &&
89
-			wcs_user_has_subscription( get_current_user_id(), '', $subs_statuses ) &&
88
+			apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) &&
89
+			wcs_user_has_subscription(get_current_user_id(), '', $subs_statuses) &&
90 90
 			is_add_payment_method_page()
91 91
 		) {
92
-			$label = esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe' ) ) );
93
-			$id    = sprintf( 'wc-%1$s-update-subs-payment-method-card', $this->id );
92
+			$label = esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe')));
93
+			$id    = sprintf('wc-%1$s-update-subs-payment-method-card', $this->id);
94 94
 			woocommerce_form_field(
95 95
 				$id,
96 96
 				array(
97 97
 					'type'    => 'checkbox',
98 98
 					'label'   => $label,
99
-					'default' => apply_filters( 'wc_stripe_save_to_subs_checked', false ),
99
+					'default' => apply_filters('wc_stripe_save_to_subs_checked', false),
100 100
 				)
101 101
 			);
102 102
 		}
@@ -109,19 +109,19 @@  discard block
 block discarded – undo
109 109
 	 * @param string $source_id
110 110
 	 * @param object $source_object
111 111
 	 */
112
-	public function handle_add_payment_method_success( $source_id, $source_object ) {
113
-		if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) {
112
+	public function handle_add_payment_method_success($source_id, $source_object) {
113
+		if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) {
114 114
 			$all_subs        = wcs_get_users_subscriptions();
115
-			$subs_statuses   = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) );
116
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
117
-
118
-			if ( ! empty( $all_subs ) ) {
119
-				foreach ( $all_subs as $sub ) {
120
-					if ( $sub->has_status( $subs_statuses ) ) {
121
-						update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id );
122
-						update_post_meta( $sub->get_id(), '_stripe_customer_id', $stripe_customer->get_id() );
123
-						update_post_meta( $sub->get_id(), '_payment_method', $this->id );
124
-						update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title );
115
+			$subs_statuses   = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active'));
116
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
117
+
118
+			if ( ! empty($all_subs)) {
119
+				foreach ($all_subs as $sub) {
120
+					if ($sub->has_status($subs_statuses)) {
121
+						update_post_meta($sub->get_id(), '_stripe_source_id', $source_id);
122
+						update_post_meta($sub->get_id(), '_stripe_customer_id', $stripe_customer->get_id());
123
+						update_post_meta($sub->get_id(), '_payment_method', $this->id);
124
+						update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title);
125 125
 					}
126 126
 				}
127 127
 			}
@@ -135,24 +135,24 @@  discard block
 block discarded – undo
135 135
 	 * @since 4.1.11 Remove 3DS check as it is not needed.
136 136
 	 * @param int $order_id
137 137
 	 */
138
-	public function change_subs_payment_method( $order_id ) {
138
+	public function change_subs_payment_method($order_id) {
139 139
 		try {
140
-			$subscription    = wc_get_order( $order_id );
141
-			$prepared_source = $this->prepare_source( get_current_user_id(), true );
140
+			$subscription    = wc_get_order($order_id);
141
+			$prepared_source = $this->prepare_source(get_current_user_id(), true);
142 142
 
143
-			$this->maybe_disallow_prepaid_card( $prepared_source );
144
-			$this->check_source( $prepared_source );
145
-			$this->save_source_to_order( $subscription, $prepared_source );
143
+			$this->maybe_disallow_prepaid_card($prepared_source);
144
+			$this->check_source($prepared_source);
145
+			$this->save_source_to_order($subscription, $prepared_source);
146 146
 
147
-			do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source );
147
+			do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source);
148 148
 
149 149
 			return array(
150 150
 				'result'   => 'success',
151
-				'redirect' => $this->get_return_url( $subscription ),
151
+				'redirect' => $this->get_return_url($subscription),
152 152
 			);
153
-		} catch ( WC_Stripe_Exception $e ) {
154
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
155
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
153
+		} catch (WC_Stripe_Exception $e) {
154
+			wc_add_notice($e->getLocalizedMessage(), 'error');
155
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
156 156
 		}
157 157
 	}
158 158
 
@@ -161,16 +161,16 @@  discard block
 block discarded – undo
161 161
 	 * @param  int $order_id
162 162
 	 * @return array
163 163
 	 */
164
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false ) {
165
-		if ( $this->has_subscription( $order_id ) ) {
166
-			if ( $this->is_subs_change_payment() ) {
167
-				return $this->change_subs_payment_method( $order_id );
164
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false) {
165
+		if ($this->has_subscription($order_id)) {
166
+			if ($this->is_subs_change_payment()) {
167
+				return $this->change_subs_payment_method($order_id);
168 168
 			}
169 169
 
170 170
 			// Regular payment with force customer enabled
171
-			return parent::process_payment( $order_id, $retry, true, $previous_error, $use_order_source );
171
+			return parent::process_payment($order_id, $retry, true, $previous_error, $use_order_source);
172 172
 		} else {
173
-			return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error, $use_order_source );
173
+			return parent::process_payment($order_id, $retry, $force_save_source, $previous_error, $use_order_source);
174 174
 		}
175 175
 	}
176 176
 
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
 	 * @param object   $prepared_source The source that is used for the payment.
183 183
 	 * @return array                    The arguments for the request.
184 184
 	 */
185
-	public function generate_create_intent_request( $order, $prepared_source ) {
186
-		$request = parent::generate_create_intent_request( $order, $prepared_source );
185
+	public function generate_create_intent_request($order, $prepared_source) {
186
+		$request = parent::generate_create_intent_request($order, $prepared_source);
187 187
 
188 188
 		// Non-subscription orders do not need any additional parameters.
189
-		if ( ! $this->has_subscription( $order ) ) {
189
+		if ( ! $this->has_subscription($order)) {
190 190
 			return $request;
191 191
 		}
192 192
 
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 	 * @param $amount_to_charge float The amount to charge.
203 203
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
204 204
 	 */
205
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
206
-		$this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false );
205
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
206
+		$this->process_subscription_payment($amount_to_charge, $renewal_order, true, false);
207 207
 	}
208 208
 
209 209
 	/**
@@ -217,154 +217,154 @@  discard block
 block discarded – undo
217 217
 	 * @param bool $retry Should we retry the process?
218 218
 	 * @param object $previous_error
219 219
 	 */
220
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) {
220
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) {
221 221
 		try {
222
-			if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
222
+			if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
223 223
 				/* translators: minimum amount */
224
-				$message = 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 ) );
224
+				$message = 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));
225 225
 				throw new WC_Stripe_Exception(
226 226
 					'Error while processing renewal order ' . $renewal_order->get_id() . ' : ' . $message,
227 227
 					$message
228 228
 				);
229 229
 			}
230 230
 
231
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
231
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
232 232
 
233
-			$this->ensure_subscription_has_customer_id( $order_id );
233
+			$this->ensure_subscription_has_customer_id($order_id);
234 234
 
235 235
 			// Unlike regular off-session subscription payments, early renewals are treated as on-session payments, involving the customer.
236
-			if ( isset( $_REQUEST['process_early_renewal'] ) ) { // wpcs: csrf ok.
237
-				$response = parent::process_payment( $order_id, true, false, $previous_error, true );
236
+			if (isset($_REQUEST['process_early_renewal'])) { // wpcs: csrf ok.
237
+				$response = parent::process_payment($order_id, true, false, $previous_error, true);
238 238
 
239
-				if( 'success' === $response['result'] && isset( $response['payment_intent_secret'] ) ) {
239
+				if ('success' === $response['result'] && isset($response['payment_intent_secret'])) {
240 240
 					$verification_url = add_query_arg(
241 241
 						array(
242 242
 							'order'         => $order_id,
243
-							'nonce'         => wp_create_nonce( 'wc_stripe_confirm_pi' ),
244
-							'redirect_to'   => remove_query_arg( array( 'process_early_renewal', 'subscription_id', 'wcs_nonce' ) ),
243
+							'nonce'         => wp_create_nonce('wc_stripe_confirm_pi'),
244
+							'redirect_to'   => remove_query_arg(array('process_early_renewal', 'subscription_id', 'wcs_nonce')),
245 245
 							'early_renewal' => true,
246 246
 						),
247
-						WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' )
247
+						WC_AJAX::get_endpoint('wc_stripe_verify_intent')
248 248
 					);
249 249
 
250
-					echo wp_json_encode( array(
250
+					echo wp_json_encode(array(
251 251
 						'stripe_sca_required' => true,
252 252
 						'intent_secret'       => $response['payment_intent_secret'],
253 253
 						'redirect_url'        => $verification_url,
254
-					) );
254
+					));
255 255
 
256 256
 					exit;
257 257
 				}
258 258
 
259 259
 				// Hijack all other redirects in order to do the redirection in JavaScript.
260
-				add_action( 'wp_redirect', array( $this, 'redirect_after_early_renewal' ), 100 );
260
+				add_action('wp_redirect', array($this, 'redirect_after_early_renewal'), 100);
261 261
 
262 262
 				return;
263 263
 			}
264 264
 
265 265
 			// Check for an existing intent, which is associated with the order.
266
-			if ( $this->has_authentication_already_failed( $renewal_order ) ) {
266
+			if ($this->has_authentication_already_failed($renewal_order)) {
267 267
 				return;
268 268
 			}
269 269
 
270 270
 			// Get source from order
271
-			$prepared_source = $this->prepare_order_source( $renewal_order );
271
+			$prepared_source = $this->prepare_order_source($renewal_order);
272 272
 			$source_object   = $prepared_source->source_object;
273 273
 
274
-			if ( ! $prepared_source->customer ) {
274
+			if ( ! $prepared_source->customer) {
275 275
 				throw new WC_Stripe_Exception(
276 276
 					'Failed to process renewal for order ' . $renewal_order->get_id() . '. Stripe customer id is missing in the order',
277
-					__( 'Customer not found', 'woocommerce-gateway-stripe' )
277
+					__('Customer not found', 'woocommerce-gateway-stripe')
278 278
 				);
279 279
 			}
280 280
 
281
-			WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
281
+			WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
282 282
 
283 283
 			/* If we're doing a retry and source is chargeable, we need to pass
284 284
 			 * a different idempotency key and retry for success.
285 285
 			 */
286
-			if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
287
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
286
+			if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) {
287
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
288 288
 			}
289 289
 
290
-			if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
290
+			if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) {
291 291
 				// Passing empty source will charge customer default.
292 292
 				$prepared_source->source = '';
293 293
 			}
294 294
 
295
-			$this->lock_order_payment( $renewal_order );
295
+			$this->lock_order_payment($renewal_order);
296 296
 
297
-			$response                   = $this->create_and_confirm_intent_for_off_session( $renewal_order, $prepared_source, $amount );
298
-			$is_authentication_required = $this->is_authentication_required_for_payment( $response );
297
+			$response                   = $this->create_and_confirm_intent_for_off_session($renewal_order, $prepared_source, $amount);
298
+			$is_authentication_required = $this->is_authentication_required_for_payment($response);
299 299
 
300 300
 			// It's only a failed payment if it's an error and it's not of the type 'authentication_required'.
301 301
 			// If it's 'authentication_required', then we should email the user and ask them to authenticate.
302
-			if ( ! empty( $response->error ) && ! $is_authentication_required ) {
302
+			if ( ! empty($response->error) && ! $is_authentication_required) {
303 303
 				// We want to retry.
304
-				if ( $this->is_retryable_error( $response->error ) ) {
305
-					if ( $retry ) {
304
+				if ($this->is_retryable_error($response->error)) {
305
+					if ($retry) {
306 306
 						// Don't do anymore retries after this.
307
-						if ( 5 <= $this->retry_interval ) {
308
-							return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error );
307
+						if (5 <= $this->retry_interval) {
308
+							return $this->process_subscription_payment($amount, $renewal_order, false, $response->error);
309 309
 						}
310 310
 
311
-						sleep( $this->retry_interval );
311
+						sleep($this->retry_interval);
312 312
 
313 313
 						$this->retry_interval++;
314 314
 
315
-						return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error );
315
+						return $this->process_subscription_payment($amount, $renewal_order, true, $response->error);
316 316
 					} else {
317
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
318
-						$renewal_order->add_order_note( $localized_message );
319
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
317
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
318
+						$renewal_order->add_order_note($localized_message);
319
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
320 320
 					}
321 321
 				}
322 322
 
323 323
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
324 324
 
325
-				if ( 'card_error' === $response->error->type ) {
326
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
325
+				if ('card_error' === $response->error->type) {
326
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
327 327
 				} else {
328
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
328
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
329 329
 				}
330 330
 
331
-				$renewal_order->add_order_note( $localized_message );
331
+				$renewal_order->add_order_note($localized_message);
332 332
 
333
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
333
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
334 334
 			}
335 335
 
336 336
 			// Either the charge was successfully captured, or it requires further authentication.
337 337
 
338
-			if ( $is_authentication_required ) {
339
-				do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response );
338
+			if ($is_authentication_required) {
339
+				do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response);
340 340
 
341
-				$error_message = __( 'This transaction requires authentication.', 'woocommerce-gateway-stripe' );
342
-				$renewal_order->add_order_note( $error_message );
341
+				$error_message = __('This transaction requires authentication.', 'woocommerce-gateway-stripe');
342
+				$renewal_order->add_order_note($error_message);
343 343
 
344
-				$charge = end( $response->error->payment_intent->charges->data );
344
+				$charge = end($response->error->payment_intent->charges->data);
345 345
 				$id = $charge->id;
346
-				$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
346
+				$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
347 347
 
348
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $id ) : $renewal_order->set_transaction_id( $id );
349
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $id ) );
350
-				if ( is_callable( array( $renewal_order, 'save' ) ) ) {
348
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $id) : $renewal_order->set_transaction_id($id);
349
+				$renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $id));
350
+				if (is_callable(array($renewal_order, 'save'))) {
351 351
 					$renewal_order->save();
352 352
 				}
353 353
 			} else {
354 354
 				// The charge was successfully captured
355
-				do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order );
355
+				do_action('wc_gateway_stripe_process_payment', $response, $renewal_order);
356 356
 
357
-				$this->process_response( end( $response->charges->data ), $renewal_order );
357
+				$this->process_response(end($response->charges->data), $renewal_order);
358 358
 			}
359 359
 
360
-			$this->unlock_order_payment( $renewal_order );
361
-		} catch ( WC_Stripe_Exception $e ) {
362
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
360
+			$this->unlock_order_payment($renewal_order);
361
+		} catch (WC_Stripe_Exception $e) {
362
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
363 363
 
364
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order );
364
+			do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order);
365 365
 
366 366
 			/* translators: error message */
367
-			$renewal_order->update_status( 'failed' );
367
+			$renewal_order->update_status('failed');
368 368
 		}
369 369
 	}
370 370
 
@@ -374,24 +374,24 @@  discard block
 block discarded – undo
374 374
 	 * @since 3.1.0
375 375
 	 * @version 4.0.0
376 376
 	 */
377
-	public function save_source_to_order( $order, $source ) {
378
-		parent::save_source_to_order( $order, $source );
377
+	public function save_source_to_order($order, $source) {
378
+		parent::save_source_to_order($order, $source);
379 379
 
380
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
380
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
381 381
 
382 382
 		// Also store it on the subscriptions being purchased or paid for in the order
383
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
384
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
385
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
386
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
383
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
384
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
385
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
386
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
387 387
 		} else {
388 388
 			$subscriptions = array();
389 389
 		}
390 390
 
391
-		foreach ( $subscriptions as $subscription ) {
392
-			$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
393
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
394
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
391
+		foreach ($subscriptions as $subscription) {
392
+			$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
393
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
394
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
395 395
 		}
396 396
 	}
397 397
 
@@ -399,26 +399,26 @@  discard block
 block discarded – undo
399 399
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
400 400
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
401 401
 	 */
402
-	public function delete_resubscribe_meta( $resubscribe_order ) {
403
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
404
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
402
+	public function delete_resubscribe_meta($resubscribe_order) {
403
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
404
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
405 405
 		// For BW compat will remove in future
406
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
406
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
407 407
 		// delete payment intent ID
408
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_intent_id' );
409
-		$this->delete_renewal_meta( $resubscribe_order );
408
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_intent_id');
409
+		$this->delete_renewal_meta($resubscribe_order);
410 410
 	}
411 411
 
412 412
 	/**
413 413
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
414 414
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
415 415
 	 */
416
-	public function delete_renewal_meta( $renewal_order ) {
417
-		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
418
-		WC_Stripe_Helper::delete_stripe_net( $renewal_order );
416
+	public function delete_renewal_meta($renewal_order) {
417
+		WC_Stripe_Helper::delete_stripe_fee($renewal_order);
418
+		WC_Stripe_Helper::delete_stripe_net($renewal_order);
419 419
 
420 420
 		// delete payment intent ID
421
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id() ), '_stripe_intent_id' );
421
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id()), '_stripe_intent_id');
422 422
 
423 423
 		return $renewal_order;
424 424
 	}
@@ -432,14 +432,14 @@  discard block
 block discarded – undo
432 432
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
433 433
 	 * @return void
434 434
 	 */
435
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
436
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
437
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
438
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
435
+	public function update_failing_payment_method($subscription, $renewal_order) {
436
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
437
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
438
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
439 439
 
440 440
 		} else {
441
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
442
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
441
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
442
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
443 443
 		}
444 444
 	}
445 445
 
@@ -452,23 +452,23 @@  discard block
 block discarded – undo
452 452
 	 * @param WC_Subscription $subscription An instance of a subscription object
453 453
 	 * @return array
454 454
 	 */
455
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
456
-		$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
457
-		$source_id       = get_post_meta( $subscription_id, '_stripe_source_id', true );
455
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
456
+		$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
457
+		$source_id       = get_post_meta($subscription_id, '_stripe_source_id', true);
458 458
 
459 459
 		// For BW compat will remove in future.
460
-		if ( empty( $source_id ) ) {
461
-			$source_id = get_post_meta( $subscription_id, '_stripe_card_id', true );
460
+		if (empty($source_id)) {
461
+			$source_id = get_post_meta($subscription_id, '_stripe_card_id', true);
462 462
 
463 463
 			// Take this opportunity to update the key name.
464
-			update_post_meta( $subscription_id, '_stripe_source_id', $source_id );
465
-			delete_post_meta( $subscription_id, '_stripe_card_id', $source_id );
464
+			update_post_meta($subscription_id, '_stripe_source_id', $source_id);
465
+			delete_post_meta($subscription_id, '_stripe_card_id', $source_id);
466 466
 		}
467 467
 
468
-		$payment_meta[ $this->id ] = array(
468
+		$payment_meta[$this->id] = array(
469 469
 			'post_meta' => array(
470 470
 				'_stripe_customer_id' => array(
471
-					'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ),
471
+					'value' => get_post_meta($subscription_id, '_stripe_customer_id', true),
472 472
 					'label' => 'Stripe Customer ID',
473 473
 				),
474 474
 				'_stripe_source_id'   => array(
@@ -491,26 +491,26 @@  discard block
 block discarded – undo
491 491
 	 * @param array $payment_meta associative array of meta data required for automatic payments
492 492
 	 * @return array
493 493
 	 */
494
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
495
-		if ( $this->id === $payment_method_id ) {
494
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
495
+		if ($this->id === $payment_method_id) {
496 496
 
497
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
497
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
498 498
 
499 499
 				// Allow empty stripe customer id during subscription renewal. It will be added when processing payment if required.
500
-				if ( ! isset( $_POST['wc_order_action'] ) || 'wcs_process_renewal' !== $_POST['wc_order_action'] ) {
501
-					throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
500
+				if ( ! isset($_POST['wc_order_action']) || 'wcs_process_renewal' !== $_POST['wc_order_action']) {
501
+					throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
502 502
 				}
503
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
504
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
503
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
504
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
505 505
 			}
506 506
 
507 507
 			if (
508
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
509
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
510
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
511
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
508
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
509
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
510
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
511
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
512 512
 
513
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
513
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
514 514
 			}
515 515
 		}
516 516
 	}
@@ -523,75 +523,75 @@  discard block
 block discarded – undo
523 523
 	 * @param WC_Subscription $subscription the subscription details
524 524
 	 * @return string the subscription payment method
525 525
 	 */
526
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
527
-		$customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id();
526
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
527
+		$customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id();
528 528
 
529 529
 		// bail for other payment methods
530
-		if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
530
+		if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
531 531
 			return $payment_method_to_display;
532 532
 		}
533 533
 
534
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
534
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
535 535
 
536 536
 		// For BW compat will remove in future.
537
-		if ( empty( $stripe_source_id ) ) {
538
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
537
+		if (empty($stripe_source_id)) {
538
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
539 539
 
540 540
 			// Take this opportunity to update the key name.
541
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
541
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
542 542
 		}
543 543
 
544 544
 		$stripe_customer    = new WC_Stripe_Customer();
545
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
545
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
546 546
 
547 547
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
548
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
548
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
549 549
 			$user_id            = $customer_user;
550
-			$stripe_customer_id = get_user_option( '_stripe_customer_id', $user_id );
551
-			$stripe_source_id   = get_user_option( '_stripe_source_id', $user_id );
550
+			$stripe_customer_id = get_user_option('_stripe_customer_id', $user_id);
551
+			$stripe_source_id   = get_user_option('_stripe_source_id', $user_id);
552 552
 
553 553
 			// For BW compat will remove in future.
554
-			if ( empty( $stripe_source_id ) ) {
555
-				$stripe_source_id = get_user_option( '_stripe_card_id', $user_id );
554
+			if (empty($stripe_source_id)) {
555
+				$stripe_source_id = get_user_option('_stripe_card_id', $user_id);
556 556
 
557 557
 				// Take this opportunity to update the key name.
558
-				update_user_option( $user_id, '_stripe_source_id', $stripe_source_id, false );
558
+				update_user_option($user_id, '_stripe_source_id', $stripe_source_id, false);
559 559
 			}
560 560
 		}
561 561
 
562 562
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
563
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
564
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
565
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
563
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
564
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
565
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
566 566
 
567 567
 			// For BW compat will remove in future.
568
-			if ( empty( $stripe_source_id ) ) {
569
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
568
+			if (empty($stripe_source_id)) {
569
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
570 570
 
571 571
 				// Take this opportunity to update the key name.
572
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
572
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
573 573
 			}
574 574
 		}
575 575
 
576
-		$stripe_customer->set_id( $stripe_customer_id );
576
+		$stripe_customer->set_id($stripe_customer_id);
577 577
 
578 578
 		$sources                   = $stripe_customer->get_sources();
579
-		$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
579
+		$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
580 580
 
581
-		if ( $sources ) {
581
+		if ($sources) {
582 582
 			$card = false;
583 583
 
584
-			foreach ( $sources as $source ) {
585
-				if ( isset( $source->type ) && 'card' === $source->type ) {
584
+			foreach ($sources as $source) {
585
+				if (isset($source->type) && 'card' === $source->type) {
586 586
 					$card = $source->card;
587
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
587
+				} elseif (isset($source->object) && 'card' === $source->object) {
588 588
 					$card = $source;
589 589
 				}
590 590
 
591
-				if ( $source->id === $stripe_source_id ) {
592
-					if ( $card ) {
591
+				if ($source->id === $stripe_source_id) {
592
+					if ($card) {
593 593
 						/* translators: 1) card brand 2) last 4 digits */
594
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
594
+						$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
595 595
 					}
596 596
 
597 597
 					break;
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 	 */
609 609
 	public function remove_order_pay_var() {
610 610
 		global $wp;
611
-		if ( isset( $_GET['wc-stripe-confirmation'] ) ) {
611
+		if (isset($_GET['wc-stripe-confirmation'])) {
612 612
 			$this->order_pay_var = $wp->query_vars['order-pay'];
613 613
 			$wp->query_vars['order-pay'] = null;
614 614
 		}
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 	 */
620 620
 	public function restore_order_pay_var() {
621 621
 		global $wp;
622
-		if ( isset( $this->order_pay_var ) ) {
622
+		if (isset($this->order_pay_var)) {
623 623
 			$wp->query_vars['order-pay'] = $this->order_pay_var;
624 624
 		}
625 625
 	}
@@ -630,13 +630,13 @@  discard block
 block discarded – undo
630 630
 	 * @param WC_Order $renewal_order The renewal order.
631 631
 	 * @return boolean
632 632
 	 */
633
-	public function has_authentication_already_failed( $renewal_order ) {
634
-		$existing_intent = $this->get_intent_from_order( $renewal_order );
633
+	public function has_authentication_already_failed($renewal_order) {
634
+		$existing_intent = $this->get_intent_from_order($renewal_order);
635 635
 
636 636
 		if (
637 637
 			! $existing_intent
638 638
 			|| 'requires_payment_method' !== $existing_intent->status
639
-			|| empty( $existing_intent->last_payment_error )
639
+			|| empty($existing_intent->last_payment_error)
640 640
 			|| 'authentication_required' !== $existing_intent->last_payment_error->code
641 641
 		) {
642 642
 			return false;
@@ -650,12 +650,12 @@  discard block
 block discarded – undo
650 650
 		 *
651 651
 		 * @param WC_Order $renewal_order The order that is being renewed.
652 652
 		 */
653
-		do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order );
653
+		do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order);
654 654
 
655 655
 		// Fail the payment attempt (order would be currently pending because of retry rules).
656
-		$charge    = end( $existing_intent->charges->data );
656
+		$charge    = end($existing_intent->charges->data);
657 657
 		$charge_id = $charge->id;
658
-		$renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $charge_id ) );
658
+		$renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $charge_id));
659 659
 
660 660
 		return true;
661 661
 	}
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 	 * @param string $url The URL that Subscriptions attempts a redirect to.
667 667
 	 * @return void
668 668
 	 */
669
-	public function redirect_after_early_renewal( $url ) {
669
+	public function redirect_after_early_renewal($url) {
670 670
 		echo wp_json_encode(
671 671
 			array(
672 672
 				'stripe_sca_required' => false,
@@ -683,12 +683,12 @@  discard block
 block discarded – undo
683 683
 	 * @param WC_Order $order The renewal order.
684 684
 	 * @param stdClass $intent The Payment Intent object.
685 685
 	 */
686
-	protected function handle_intent_verification_success( $order, $intent ) {
687
-		parent::handle_intent_verification_success( $order, $intent );
686
+	protected function handle_intent_verification_success($order, $intent) {
687
+		parent::handle_intent_verification_success($order, $intent);
688 688
 
689
-		if ( isset( $_GET['early_renewal'] ) ) { // wpcs: csrf ok.
690
-			wcs_update_dates_after_early_renewal( wcs_get_subscription( $order->get_meta( '_subscription_renewal' ) ), $order );
691
-			wc_add_notice( __( 'Your early renewal order was successful.', 'woocommerce-gateway-stripe' ), 'success' );
689
+		if (isset($_GET['early_renewal'])) { // wpcs: csrf ok.
690
+			wcs_update_dates_after_early_renewal(wcs_get_subscription($order->get_meta('_subscription_renewal')), $order);
691
+			wc_add_notice(__('Your early renewal order was successful.', 'woocommerce-gateway-stripe'), 'success');
692 692
 		}
693 693
 	}
694 694
 
@@ -698,12 +698,12 @@  discard block
 block discarded – undo
698 698
 	 * @param WC_Order $order The renewal order.
699 699
 	 * @param stdClass $intent The Payment Intent object (unused).
700 700
 	 */
701
-	protected function handle_intent_verification_failure( $order, $intent ) {
702
-		if ( isset( $_GET['early_renewal'] ) ) {
703
-			$order->delete( true );
704
-			wc_add_notice( __( 'Payment authorization for the renewal order was unsuccessful, please try again.', 'woocommerce-gateway-stripe' ), 'error' );
705
-			$renewal_url = wcs_get_early_renewal_url( wcs_get_subscription( $order->get_meta( '_subscription_renewal' ) ) );
706
-			wp_redirect( $renewal_url ); exit;
701
+	protected function handle_intent_verification_failure($order, $intent) {
702
+		if (isset($_GET['early_renewal'])) {
703
+			$order->delete(true);
704
+			wc_add_notice(__('Payment authorization for the renewal order was unsuccessful, please try again.', 'woocommerce-gateway-stripe'), 'error');
705
+			$renewal_url = wcs_get_early_renewal_url(wcs_get_subscription($order->get_meta('_subscription_renewal')));
706
+			wp_redirect($renewal_url); exit;
707 707
 		}
708 708
 	}
709 709
 }
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-subs-compat.php 1 patch
Spacing   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -15,21 +15,21 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
23
-			add_action( 'wc_stripe_sepa_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) );
24
-			add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23
+			add_action('wc_stripe_sepa_payment_fields', array($this, 'display_update_subs_payment_checkout'));
24
+			add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2);
25 25
 
26 26
 			// Display the credit card used for a subscription in the "My Subscriptions" table.
27
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
27
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
28 28
 
29 29
 			// Allow store managers to manually set Stripe as the payment method on a subscription.
30
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
31
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
32
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
30
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
31
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
32
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
33 33
 		}
34 34
 	}
35 35
 
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	 * @since 4.0.0
41 41
 	 * @version 4.0.0
42 42
 	 */
43
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
44
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
43
+	public function maybe_hide_save_checkbox($display_tokenization) {
44
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
45 45
 			return false;
46 46
 		}
47 47
 
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 * @param  int  $order_id
54 54
 	 * @return boolean
55 55
 	 */
56
-	public function has_subscription( $order_id ) {
57
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
56
+	public function has_subscription($order_id) {
57
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
58 58
 	}
59 59
 
60 60
 	/**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @return bool
65 65
 	 */
66 66
 	public function is_subs_change_payment() {
67
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
67
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
68 68
 	}
69 69
 
70 70
 	/**
@@ -74,20 +74,20 @@  discard block
 block discarded – undo
74 74
 	 * @since 4.1.11
75 75
 	 */
76 76
 	public function display_update_subs_payment_checkout() {
77
-		$subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) );
77
+		$subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active'));
78 78
 		if (
79
-			apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) &&
80
-			wcs_user_has_subscription( get_current_user_id(), '', $subs_statuses ) &&
79
+			apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) &&
80
+			wcs_user_has_subscription(get_current_user_id(), '', $subs_statuses) &&
81 81
 			is_add_payment_method_page()
82 82
 		) {
83
-			$label = esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe' ) ) );
84
-			$id    = sprintf( 'wc-%1$s-update-subs-payment-method-card', $this->id );
83
+			$label = esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe')));
84
+			$id    = sprintf('wc-%1$s-update-subs-payment-method-card', $this->id);
85 85
 			woocommerce_form_field(
86 86
 				$id,
87 87
 				array(
88 88
 					'type'    => 'checkbox',
89 89
 					'label'   => $label,
90
-					'default' => apply_filters( 'wc_stripe_save_to_subs_checked', false ),
90
+					'default' => apply_filters('wc_stripe_save_to_subs_checked', false),
91 91
 				)
92 92
 			);
93 93
 		}
@@ -100,19 +100,19 @@  discard block
 block discarded – undo
100 100
 	 * @param string $source_id
101 101
 	 * @param object $source_object
102 102
 	 */
103
-	public function handle_add_payment_method_success( $source_id, $source_object ) {
104
-		if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) {
103
+	public function handle_add_payment_method_success($source_id, $source_object) {
104
+		if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) {
105 105
 			$all_subs        = wcs_get_users_subscriptions();
106
-			$subs_statuses   = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) );
107
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
108
-
109
-			if ( ! empty( $all_subs ) ) {
110
-				foreach ( $all_subs as $sub ) {
111
-					if ( $sub->has_status( $subs_statuses ) ) {
112
-						update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id );
113
-						update_post_meta( $sub->get_id(), '_stripe_customer_id', $stripe_customer->get_id() );
114
-						update_post_meta( $sub->get_id(), '_payment_method', $this->id );
115
-						update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title );
106
+			$subs_statuses   = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active'));
107
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
108
+
109
+			if ( ! empty($all_subs)) {
110
+				foreach ($all_subs as $sub) {
111
+					if ($sub->has_status($subs_statuses)) {
112
+						update_post_meta($sub->get_id(), '_stripe_source_id', $source_id);
113
+						update_post_meta($sub->get_id(), '_stripe_customer_id', $stripe_customer->get_id());
114
+						update_post_meta($sub->get_id(), '_payment_method', $this->id);
115
+						update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title);
116 116
 					}
117 117
 				}
118 118
 			}
@@ -125,24 +125,24 @@  discard block
 block discarded – undo
125 125
 	 * @since 3.1.0
126 126
 	 * @version 4.0.0
127 127
 	 */
128
-	public function save_source_to_order( $order, $source ) {
129
-		parent::save_source_to_order( $order, $source );
128
+	public function save_source_to_order($order, $source) {
129
+		parent::save_source_to_order($order, $source);
130 130
 
131
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
131
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
132 132
 
133 133
 		// Also store it on the subscriptions being purchased or paid for in the order.
134
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
135
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
136
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
137
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
134
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
135
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
136
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
137
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
138 138
 		} else {
139 139
 			$subscriptions = array();
140 140
 		}
141 141
 
142
-		foreach ( $subscriptions as $subscription ) {
143
-			$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
144
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
145
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
142
+		foreach ($subscriptions as $subscription) {
143
+			$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
144
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
145
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
146 146
 		}
147 147
 	}
148 148
 
@@ -151,16 +151,16 @@  discard block
 block discarded – undo
151 151
 	 * @param  int $order_id
152 152
 	 * @return array
153 153
 	 */
154
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) {
155
-		if ( $this->has_subscription( $order_id ) ) {
156
-			if ( $this->is_subs_change_payment() ) {
157
-				return $this->change_subs_payment_method( $order_id );
154
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) {
155
+		if ($this->has_subscription($order_id)) {
156
+			if ($this->is_subs_change_payment()) {
157
+				return $this->change_subs_payment_method($order_id);
158 158
 			}
159 159
 
160 160
 			// Regular payment with force customer enabled
161
-			return parent::process_payment( $order_id, $retry, true, $previous_error );
161
+			return parent::process_payment($order_id, $retry, true, $previous_error);
162 162
 		} else {
163
-			return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error );
163
+			return parent::process_payment($order_id, $retry, $force_save_source, $previous_error);
164 164
 		}
165 165
 	}
166 166
 
@@ -170,27 +170,27 @@  discard block
 block discarded – undo
170 170
 	 * @since 4.0.4
171 171
 	 * @param int $order_id
172 172
 	 */
173
-	public function change_subs_payment_method( $order_id ) {
173
+	public function change_subs_payment_method($order_id) {
174 174
 		try {
175
-			$subscription    = wc_get_order( $order_id );
176
-			$prepared_source = $this->prepare_source( get_current_user_id(), true );
175
+			$subscription    = wc_get_order($order_id);
176
+			$prepared_source = $this->prepare_source(get_current_user_id(), true);
177 177
 
178
-			if ( empty( $prepared_source->source ) ) {
179
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
180
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
178
+			if (empty($prepared_source->source)) {
179
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
180
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
181 181
 			}
182 182
 
183
-			$this->save_source_to_order( $subscription, $prepared_source );
183
+			$this->save_source_to_order($subscription, $prepared_source);
184 184
 
185
-			do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source );
185
+			do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source);
186 186
 
187 187
 			return array(
188 188
 				'result'   => 'success',
189
-				'redirect' => $this->get_return_url( $subscription ),
189
+				'redirect' => $this->get_return_url($subscription),
190 190
 			);
191
-		} catch ( WC_Stripe_Exception $e ) {
192
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
193
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
191
+		} catch (WC_Stripe_Exception $e) {
192
+			wc_add_notice($e->getLocalizedMessage(), 'error');
193
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
194 194
 		}
195 195
 	}
196 196
 
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 	 * @param $amount_to_charge float The amount to charge.
201 201
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
202 202
 	 */
203
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
204
-		$this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false );
203
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
204
+		$this->process_subscription_payment($amount_to_charge, $renewal_order, true, false);
205 205
 	}
206 206
 
207 207
 	/**
@@ -215,95 +215,95 @@  discard block
 block discarded – undo
215 215
 	 * @param bool $retry Should we retry the process?
216 216
 	 * @param object $previous_error
217 217
 	 */
218
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) {
218
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) {
219 219
 		try {
220
-			if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
220
+			if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
221 221
 				/* translators: minimum amount */
222
-				$message = 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 ) );
222
+				$message = 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));
223 223
 				throw new WC_Stripe_Exception(
224 224
 					'Error while processing renewal order ' . $renewal_order->get_id() . ' : ' . $message,
225 225
 					$message
226 226
 				);
227 227
 			}
228 228
 
229
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
229
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
230 230
 
231
-			$this->ensure_subscription_has_customer_id( $order_id );
231
+			$this->ensure_subscription_has_customer_id($order_id);
232 232
 
233 233
 			// Get source from order
234
-			$prepared_source = $this->prepare_order_source( $renewal_order );
234
+			$prepared_source = $this->prepare_order_source($renewal_order);
235 235
 			$source_object   = $prepared_source->source_object;
236 236
 
237
-			if ( ! $prepared_source->customer ) {
237
+			if ( ! $prepared_source->customer) {
238 238
 				throw new WC_Stripe_Exception(
239 239
 					'Failed to process renewal for order ' . $renewal_order->get_id() . '. Stripe customer id is missing in the order',
240
-					__( 'Customer not found', 'woocommerce-gateway-stripe' )
240
+					__('Customer not found', 'woocommerce-gateway-stripe')
241 241
 				);
242 242
 			}
243 243
 
244
-			WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
244
+			WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
245 245
 
246 246
 			/* If we're doing a retry and source is chargeable, we need to pass
247 247
 			 * a different idempotency key and retry for success.
248 248
 			 */
249
-			if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
250
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
249
+			if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) {
250
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
251 251
 			}
252 252
 
253
-			if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
253
+			if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) {
254 254
 				// Passing empty source will charge customer default.
255 255
 				$prepared_source->source = '';
256 256
 			}
257 257
 
258
-			$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
258
+			$request            = $this->generate_payment_request($renewal_order, $prepared_source);
259 259
 			$request['capture'] = 'true';
260
-			$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
261
-			$response           = WC_Stripe_API::request( $request );
260
+			$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
261
+			$response           = WC_Stripe_API::request($request);
262 262
 
263
-			if ( ! empty( $response->error ) ) {
263
+			if ( ! empty($response->error)) {
264 264
 				// We want to retry.
265
-				if ( $this->is_retryable_error( $response->error ) ) {
266
-					if ( $retry ) {
265
+				if ($this->is_retryable_error($response->error)) {
266
+					if ($retry) {
267 267
 						// Don't do anymore retries after this.
268
-						if ( 5 <= $this->retry_interval ) {
269
-							return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error );
268
+						if (5 <= $this->retry_interval) {
269
+							return $this->process_subscription_payment($amount, $renewal_order, false, $response->error);
270 270
 						}
271 271
 
272
-						sleep( $this->retry_interval );
272
+						sleep($this->retry_interval);
273 273
 
274 274
 						$this->retry_interval++;
275 275
 
276
-						return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error );
276
+						return $this->process_subscription_payment($amount, $renewal_order, true, $response->error);
277 277
 					} else {
278
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
279
-						$renewal_order->add_order_note( $localized_message );
280
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
278
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
279
+						$renewal_order->add_order_note($localized_message);
280
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
281 281
 					}
282 282
 				}
283 283
 
284 284
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
285 285
 
286
-				if ( 'card_error' === $response->error->type ) {
287
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
286
+				if ('card_error' === $response->error->type) {
287
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
288 288
 				} else {
289
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
289
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
290 290
 				}
291 291
 
292
-				$renewal_order->add_order_note( $localized_message );
292
+				$renewal_order->add_order_note($localized_message);
293 293
 
294
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
294
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
295 295
 			}
296 296
 
297
-			do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order );
297
+			do_action('wc_gateway_stripe_process_payment', $response, $renewal_order);
298 298
 
299
-			$this->process_response( $response, $renewal_order );
300
-		} catch ( WC_Stripe_Exception $e ) {
301
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
299
+			$this->process_response($response, $renewal_order);
300
+		} catch (WC_Stripe_Exception $e) {
301
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
302 302
 
303
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order );
303
+			do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order);
304 304
 
305 305
 			/* translators: error message */
306
-			$renewal_order->update_status( 'failed' );
306
+			$renewal_order->update_status('failed');
307 307
 		}
308 308
 	}
309 309
 
@@ -311,21 +311,21 @@  discard block
 block discarded – undo
311 311
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
312 312
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
313 313
 	 */
314
-	public function delete_resubscribe_meta( $resubscribe_order ) {
315
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
316
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
314
+	public function delete_resubscribe_meta($resubscribe_order) {
315
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
316
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
317 317
 		// For BW compat will remove in future
318
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
319
-		$this->delete_renewal_meta( $resubscribe_order );
318
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
319
+		$this->delete_renewal_meta($resubscribe_order);
320 320
 	}
321 321
 
322 322
 	/**
323 323
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
324 324
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
325 325
 	 */
326
-	public function delete_renewal_meta( $renewal_order ) {
327
-		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
328
-		WC_Stripe_Helper::delete_stripe_net( $renewal_order );
326
+	public function delete_renewal_meta($renewal_order) {
327
+		WC_Stripe_Helper::delete_stripe_fee($renewal_order);
328
+		WC_Stripe_Helper::delete_stripe_net($renewal_order);
329 329
 
330 330
 		return $renewal_order;
331 331
 	}
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
340 340
 	 * @return void
341 341
 	 */
342
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
343
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
344
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
345
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
342
+	public function update_failing_payment_method($subscription, $renewal_order) {
343
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
344
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
345
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
346 346
 
347 347
 		} else {
348
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
349
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
348
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
349
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
350 350
 		}
351 351
 	}
352 352
 
@@ -359,21 +359,21 @@  discard block
 block discarded – undo
359 359
 	 * @param WC_Subscription $subscription An instance of a subscription object
360 360
 	 * @return array
361 361
 	 */
362
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
363
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
362
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
363
+		$source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
364 364
 
365 365
 		// For BW compat will remove in future.
366
-		if ( empty( $source_id ) ) {
367
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
366
+		if (empty($source_id)) {
367
+			$source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
368 368
 
369 369
 			// Take this opportunity to update the key name.
370
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
370
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
371 371
 		}
372 372
 
373
-		$payment_meta[ $this->id ] = array(
373
+		$payment_meta[$this->id] = array(
374 374
 			'post_meta' => array(
375 375
 				'_stripe_customer_id' => array(
376
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
376
+					'value' => get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
377 377
 					'label' => 'Stripe Customer ID',
378 378
 				),
379 379
 				'_stripe_source_id'   => array(
@@ -394,26 +394,26 @@  discard block
 block discarded – undo
394 394
 	 * @param array $payment_meta associative array of meta data required for automatic payments
395 395
 	 * @return array
396 396
 	 */
397
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
398
-		if ( $this->id === $payment_method_id ) {
397
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
398
+		if ($this->id === $payment_method_id) {
399 399
 
400
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
400
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
401 401
 
402 402
 				// Allow empty stripe customer id during subscription renewal. It will be added when processing payment if required.
403
-				if ( ! isset( $_POST['wc_order_action'] ) || 'wcs_process_renewal' !== $_POST['wc_order_action'] ) {
404
-					throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
403
+				if ( ! isset($_POST['wc_order_action']) || 'wcs_process_renewal' !== $_POST['wc_order_action']) {
404
+					throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
405 405
 				}
406
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
407
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
406
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
407
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
408 408
 			}
409 409
 
410 410
 			if (
411
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
412
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
413
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
414
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
411
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
412
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
413
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
414
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
415 415
 
416
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
416
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
417 417
 			}
418 418
 		}
419 419
 	}
@@ -426,67 +426,67 @@  discard block
 block discarded – undo
426 426
 	 * @param WC_Subscription $subscription the subscription details
427 427
 	 * @return string the subscription payment method
428 428
 	 */
429
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
430
-		$customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id();
429
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
430
+		$customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id();
431 431
 
432 432
 		// bail for other payment methods
433
-		if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
433
+		if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
434 434
 			return $payment_method_to_display;
435 435
 		}
436 436
 
437
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
437
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
438 438
 
439 439
 		// For BW compat will remove in future.
440
-		if ( empty( $stripe_source_id ) ) {
441
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
440
+		if (empty($stripe_source_id)) {
441
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
442 442
 
443 443
 			// Take this opportunity to update the key name.
444
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
444
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
445 445
 		}
446 446
 
447 447
 		$stripe_customer    = new WC_Stripe_Customer();
448
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
448
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
449 449
 
450 450
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
451
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
451
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
452 452
 			$user_id            = $customer_user;
453
-			$stripe_customer_id = get_user_option( '_stripe_customer_id', $user_id );
454
-			$stripe_source_id   = get_user_option( '_stripe_source_id', $user_id );
453
+			$stripe_customer_id = get_user_option('_stripe_customer_id', $user_id);
454
+			$stripe_source_id   = get_user_option('_stripe_source_id', $user_id);
455 455
 
456 456
 			// For BW compat will remove in future.
457
-			if ( empty( $stripe_source_id ) ) {
458
-				$stripe_source_id = get_user_option( '_stripe_card_id', $user_id );
457
+			if (empty($stripe_source_id)) {
458
+				$stripe_source_id = get_user_option('_stripe_card_id', $user_id);
459 459
 
460 460
 				// Take this opportunity to update the key name.
461
-				update_user_option( $user_id, '_stripe_source_id', $stripe_source_id, false );
461
+				update_user_option($user_id, '_stripe_source_id', $stripe_source_id, false);
462 462
 			}
463 463
 		}
464 464
 
465 465
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
466
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
467
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
468
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
466
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
467
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
468
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
469 469
 
470 470
 			// For BW compat will remove in future.
471
-			if ( empty( $stripe_source_id ) ) {
472
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
471
+			if (empty($stripe_source_id)) {
472
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
473 473
 
474 474
 				// Take this opportunity to update the key name.
475
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
475
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
476 476
 			}
477 477
 		}
478 478
 
479
-		$stripe_customer->set_id( $stripe_customer_id );
479
+		$stripe_customer->set_id($stripe_customer_id);
480 480
 
481 481
 		$sources                   = $stripe_customer->get_sources();
482
-		$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
482
+		$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
483 483
 
484
-		if ( $sources ) {
485
-			foreach ( $sources as $source ) {
486
-				if ( $source->id === $stripe_source_id ) {
487
-					if ( $source->sepa_debit ) {
484
+		if ($sources) {
485
+			foreach ($sources as $source) {
486
+				if ($source->id === $stripe_source_id) {
487
+					if ($source->sepa_debit) {
488 488
 						/* translators: 1) last 4 digits of SEPA Direct Debit */
489
-						$payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 );
489
+						$payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4);
490 490
 					}
491 491
 
492 492
 					break;
Please login to merge, or discard this patch.