Completed
Push — master ( fe3b76...0a744c )
by Roy
29:18
created
includes/admin/class-wc-stripe-admin-notices.php 1 patch
Spacing   +85 added lines, -85 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
 
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 	 * @since 4.1.0
22 22
 	 */
23 23
 	public function __construct() {
24
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
25
-		add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
24
+		add_action('admin_notices', array($this, 'admin_notices'));
25
+		add_action('wp_loaded', array($this, 'hide_notices'));
26 26
 	}
27 27
 
28 28
 	/**
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 	 * @since 1.0.0
32 32
 	 * @version 4.0.0
33 33
 	 */
34
-	public function add_admin_notice( $slug, $class, $message, $dismissible = false ) {
35
-		$this->notices[ $slug ] = array(
34
+	public function add_admin_notice($slug, $class, $message, $dismissible = false) {
35
+		$this->notices[$slug] = array(
36 36
 			'class'       => $class,
37 37
 			'message'     => $message,
38 38
 			'dismissible' => $dismissible,
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 * @version 4.0.0
47 47
 	 */
48 48
 	public function admin_notices() {
49
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
49
+		if ( ! current_user_can('manage_woocommerce')) {
50 50
 			return;
51 51
 		}
52 52
 
@@ -56,17 +56,17 @@  discard block
 block discarded – undo
56 56
 		// All other payment methods.
57 57
 		$this->payment_methods_check_environment();
58 58
 
59
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
60
-			echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">';
59
+		foreach ((array) $this->notices as $notice_key => $notice) {
60
+			echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">';
61 61
 
62
-			if ( $notice['dismissible'] ) {
62
+			if ($notice['dismissible']) {
63 63
 				?>
64
-				<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a>
64
+				<a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a>
65 65
 				<?php
66 66
 			}
67 67
 
68 68
 			echo '<p>';
69
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
69
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
70 70
 			echo '</p></div>';
71 71
 		}
72 72
 	}
@@ -99,95 +99,95 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function stripe_check_environment() {
102
-		$show_styles_notice = get_option( 'wc_stripe_show_styles_notice' );
103
-		$show_ssl_notice    = get_option( 'wc_stripe_show_ssl_notice' );
104
-		$show_keys_notice   = get_option( 'wc_stripe_show_keys_notice' );
105
-		$show_phpver_notice = get_option( 'wc_stripe_show_phpver_notice' );
106
-		$show_wcver_notice  = get_option( 'wc_stripe_show_wcver_notice' );
107
-		$show_curl_notice   = get_option( 'wc_stripe_show_curl_notice' );
108
-		$options            = get_option( 'woocommerce_stripe_settings' );
109
-		$testmode           = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false;
110
-		$test_pub_key       = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : '';
111
-		$test_secret_key    = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : '';
112
-		$live_pub_key       = isset( $options['publishable_key'] ) ? $options['publishable_key'] : '';
113
-		$live_secret_key    = isset( $options['secret_key'] ) ? $options['secret_key'] : '';
114
-
115
-		if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) {
116
-			if ( empty( $show_phpver_notice ) ) {
117
-				if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
102
+		$show_styles_notice = get_option('wc_stripe_show_styles_notice');
103
+		$show_ssl_notice    = get_option('wc_stripe_show_ssl_notice');
104
+		$show_keys_notice   = get_option('wc_stripe_show_keys_notice');
105
+		$show_phpver_notice = get_option('wc_stripe_show_phpver_notice');
106
+		$show_wcver_notice  = get_option('wc_stripe_show_wcver_notice');
107
+		$show_curl_notice   = get_option('wc_stripe_show_curl_notice');
108
+		$options            = get_option('woocommerce_stripe_settings');
109
+		$testmode           = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false;
110
+		$test_pub_key       = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : '';
111
+		$test_secret_key    = isset($options['test_secret_key']) ? $options['test_secret_key'] : '';
112
+		$live_pub_key       = isset($options['publishable_key']) ? $options['publishable_key'] : '';
113
+		$live_secret_key    = isset($options['secret_key']) ? $options['secret_key'] : '';
114
+
115
+		if (isset($options['enabled']) && 'yes' === $options['enabled']) {
116
+			if (empty($show_phpver_notice)) {
117
+				if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
118 118
 					/* translators: 1) int version 2) int version */
119
-					$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
119
+					$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
120 120
 
121
-					$this->add_admin_notice( 'phpver', 'error', sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ), true );
121
+					$this->add_admin_notice('phpver', 'error', sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()), true);
122 122
 
123 123
 					return;
124 124
 				}
125 125
 			}
126 126
 
127 127
 			// To be removed 4.1.12.
128
-			if ( empty( $show_styles_notice ) ) {
129
-				if ( version_compare( WC_STRIPE_VERSION, '4.1.12', '<' ) ) {
130
-					$message = __( 'Action required: In January 2019 we will be introducing changes that could affect how Stripe looks in your checkout. <a href="https://docs.woocommerce.com/document/stripe/#section-45" target="_blank">Learn more</a> about how to make sure your site continues to look great.', 'woocommerce-gateway-stripe' );
128
+			if (empty($show_styles_notice)) {
129
+				if (version_compare(WC_STRIPE_VERSION, '4.1.12', '<')) {
130
+					$message = __('Action required: In January 2019 we will be introducing changes that could affect how Stripe looks in your checkout. <a href="https://docs.woocommerce.com/document/stripe/#section-45" target="_blank">Learn more</a> about how to make sure your site continues to look great.', 'woocommerce-gateway-stripe');
131 131
 
132
-					$this->add_admin_notice( 'styles', 'notice notice-warning', $message, true );
132
+					$this->add_admin_notice('styles', 'notice notice-warning', $message, true);
133 133
 
134 134
 					return;
135 135
 				}
136 136
 			}
137 137
 
138
-			if ( empty( $show_wcver_notice ) ) {
139
-				if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
138
+			if (empty($show_wcver_notice)) {
139
+				if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
140 140
 					/* translators: 1) int version 2) int version */
141
-					$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
141
+					$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
142 142
 
143
-					$this->add_admin_notice( 'wcver', 'notice notice-warning', sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ), true );
143
+					$this->add_admin_notice('wcver', 'notice notice-warning', sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION), true);
144 144
 
145 145
 					return;
146 146
 				}
147 147
 			}
148 148
 
149
-			if ( empty( $show_curl_notice ) ) {
150
-				if ( ! function_exists( 'curl_init' ) ) {
151
-					$this->add_admin_notice( 'curl', 'notice notice-warning', __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ), true );
149
+			if (empty($show_curl_notice)) {
150
+				if ( ! function_exists('curl_init')) {
151
+					$this->add_admin_notice('curl', 'notice notice-warning', __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'), true);
152 152
 				}
153 153
 			}
154 154
 
155
-			if ( empty( $show_keys_notice ) ) {
155
+			if (empty($show_keys_notice)) {
156 156
 				$secret = WC_Stripe_API::get_secret_key();
157 157
 
158
-				if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
158
+				if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
159 159
 					$setting_link = $this->get_setting_link();
160 160
 					/* translators: 1) link */
161
-					$this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
161
+					$this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
162 162
 				}
163 163
 
164 164
 				// Check if keys are entered properly per live/test mode.
165
-				if ( $testmode ) {
165
+				if ($testmode) {
166 166
 					if (
167
-						! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key )
168
-						|| ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key )
169
-						&& ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) {
167
+						! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key)
168
+						|| ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key)
169
+						&& ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) {
170 170
 						$setting_link = $this->get_setting_link();
171 171
 						/* translators: 1) link */
172
-						$this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
172
+						$this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
173 173
 					}
174 174
 				} else {
175 175
 					if (
176
-						! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key )
177
-						|| ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key )
178
-						&& ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) {
176
+						! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key)
177
+						|| ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key)
178
+						&& ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) {
179 179
 						$setting_link = $this->get_setting_link();
180 180
 						/* translators: 1) link */
181
-						$this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
181
+						$this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
182 182
 					}
183 183
 				}
184 184
 			}
185 185
 
186
-			if ( empty( $show_ssl_notice ) ) {
186
+			if (empty($show_ssl_notice)) {
187 187
 				// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
188
-				if ( ! wc_checkout_is_https() ) {
188
+				if ( ! wc_checkout_is_https()) {
189 189
 					/* translators: 1) link */
190
-					$this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but a SSL certificate is not detected. Your checkout may not be secure! Please ensure your server has a valid <a href="%1$s" target="_blank">SSL certificate</a>', 'woocommerce-gateway-stripe' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true );
190
+					$this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but a SSL certificate is not detected. Your checkout may not be secure! Please ensure your server has a valid <a href="%1$s" target="_blank">SSL certificate</a>', 'woocommerce-gateway-stripe'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true);
191 191
 				}
192 192
 			}
193 193
 		}
@@ -201,17 +201,17 @@  discard block
 block discarded – undo
201 201
 	public function payment_methods_check_environment() {
202 202
 		$payment_methods = $this->get_payment_methods();
203 203
 
204
-		foreach ( $payment_methods as $method => $class ) {
205
-			$show_notice = get_option( 'wc_stripe_show_' . strtolower( $method ) . '_notice' );
204
+		foreach ($payment_methods as $method => $class) {
205
+			$show_notice = get_option('wc_stripe_show_' . strtolower($method) . '_notice');
206 206
 			$gateway     = new $class();
207 207
 
208
-			if ( 'yes' !== $gateway->enabled || 'no' === $show_notice ) {
208
+			if ('yes' !== $gateway->enabled || 'no' === $show_notice) {
209 209
 				continue;
210 210
 			}
211 211
 
212
-			if ( ! in_array( get_woocommerce_currency(), $gateway->get_supported_currency() ) ) {
212
+			if ( ! in_array(get_woocommerce_currency(), $gateway->get_supported_currency())) {
213 213
 				/* translators: %1$s Payment method, %2$s List of supported currencies */
214
-				$this->add_admin_notice( $method, 'notice notice-error', sprintf( __( '%1$s is enabled - it requires store currency to be set to %2$s', 'woocommerce-gateway-stripe' ), $method, implode( ', ', $gateway->get_supported_currency() ) ), true );
214
+				$this->add_admin_notice($method, 'notice notice-error', sprintf(__('%1$s is enabled - it requires store currency to be set to %2$s', 'woocommerce-gateway-stripe'), $method, implode(', ', $gateway->get_supported_currency())), true);
215 215
 			}
216 216
 		}
217 217
 	}
@@ -223,62 +223,62 @@  discard block
 block discarded – undo
223 223
 	 * @version 4.0.0
224 224
 	 */
225 225
 	public function hide_notices() {
226
-		if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) {
227
-			if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) {
228
-				wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) );
226
+		if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) {
227
+			if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) {
228
+				wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe'));
229 229
 			}
230 230
 
231
-			if ( ! current_user_can( 'manage_woocommerce' ) ) {
232
-				wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
231
+			if ( ! current_user_can('manage_woocommerce')) {
232
+				wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
233 233
 			}
234 234
 
235
-			$notice = wc_clean( $_GET['wc-stripe-hide-notice'] );
235
+			$notice = wc_clean($_GET['wc-stripe-hide-notice']);
236 236
 
237
-			switch ( $notice ) {
237
+			switch ($notice) {
238 238
 				case 'styles':
239
-					update_option( 'wc_stripe_show_styles_notice', 'no' );
239
+					update_option('wc_stripe_show_styles_notice', 'no');
240 240
 					break;
241 241
 				case 'styles':
242
-					update_option( 'wc_stripe_show_phpver_notice', 'no' );
242
+					update_option('wc_stripe_show_phpver_notice', 'no');
243 243
 					break;
244 244
 				case 'wcver':
245
-					update_option( 'wc_stripe_show_wcver_notice', 'no' );
245
+					update_option('wc_stripe_show_wcver_notice', 'no');
246 246
 					break;
247 247
 				case 'curl':
248
-					update_option( 'wc_stripe_show_curl_notice', 'no' );
248
+					update_option('wc_stripe_show_curl_notice', 'no');
249 249
 					break;
250 250
 				case 'ssl':
251
-					update_option( 'wc_stripe_show_ssl_notice', 'no' );
251
+					update_option('wc_stripe_show_ssl_notice', 'no');
252 252
 					break;
253 253
 				case 'keys':
254
-					update_option( 'wc_stripe_show_keys_notice', 'no' );
254
+					update_option('wc_stripe_show_keys_notice', 'no');
255 255
 					break;
256 256
 				case 'Alipay':
257
-					update_option( 'wc_stripe_show_alipay_notice', 'no' );
257
+					update_option('wc_stripe_show_alipay_notice', 'no');
258 258
 					break;
259 259
 				case 'Bancontact':
260
-					update_option( 'wc_stripe_show_bancontact_notice', 'no' );
260
+					update_option('wc_stripe_show_bancontact_notice', 'no');
261 261
 					break;
262 262
 				case 'EPS':
263
-					update_option( 'wc_stripe_show_eps_notice', 'no' );
263
+					update_option('wc_stripe_show_eps_notice', 'no');
264 264
 					break;
265 265
 				case 'Giropay':
266
-					update_option( 'wc_stripe_show_giropay_notice', 'no' );
266
+					update_option('wc_stripe_show_giropay_notice', 'no');
267 267
 					break;
268 268
 				case 'iDeal':
269
-					update_option( 'wc_stripe_show_ideal_notice', 'no' );
269
+					update_option('wc_stripe_show_ideal_notice', 'no');
270 270
 					break;
271 271
 				case 'Multibanco':
272
-					update_option( 'wc_stripe_show_multibanco_notice', 'no' );
272
+					update_option('wc_stripe_show_multibanco_notice', 'no');
273 273
 					break;
274 274
 				case 'P24':
275
-					update_option( 'wc_stripe_show_p24_notice', 'no' );
275
+					update_option('wc_stripe_show_p24_notice', 'no');
276 276
 					break;
277 277
 				case 'SEPA':
278
-					update_option( 'wc_stripe_show_sepa_notice', 'no' );
278
+					update_option('wc_stripe_show_sepa_notice', 'no');
279 279
 					break;
280 280
 				case 'SOFORT':
281
-					update_option( 'wc_stripe_show_sofort_notice', 'no' );
281
+					update_option('wc_stripe_show_sofort_notice', 'no');
282 282
 					break;
283 283
 			}
284 284
 		}
@@ -292,11 +292,11 @@  discard block
 block discarded – undo
292 292
 	 * @return string Setting link
293 293
 	 */
294 294
 	public function get_setting_link() {
295
-		$use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
295
+		$use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
296 296
 
297
-		$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
297
+		$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
298 298
 
299
-		return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
299
+		return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
300 300
 	}
301 301
 }
302 302
 
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +89 added lines, -89 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
 
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$this->retry_interval = 1;
25 25
 
26
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
31 31
 	}
32 32
 
33 33
 	/**
@@ -51,25 +51,25 @@  discard block
 block discarded – undo
51 51
 	 * @param bool $retry
52 52
 	 * @param mix $previous_error Any error message from previous request.
53 53
 	 */
54
-	public function process_redirect_payment( $order_id, $retry = true, $previous_error = false ) {
54
+	public function process_redirect_payment($order_id, $retry = true, $previous_error = false) {
55 55
 		try {
56
-			$source = wc_clean( $_GET['source'] );
56
+			$source = wc_clean($_GET['source']);
57 57
 
58
-			if ( empty( $source ) ) {
58
+			if (empty($source)) {
59 59
 				return;
60 60
 			}
61 61
 
62
-			if ( empty( $order_id ) ) {
62
+			if (empty($order_id)) {
63 63
 				return;
64 64
 			}
65 65
 
66
-			$order = wc_get_order( $order_id );
66
+			$order = wc_get_order($order_id);
67 67
 
68
-			if ( ! is_object( $order ) ) {
68
+			if ( ! is_object($order)) {
69 69
 				return;
70 70
 			}
71 71
 
72
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
72
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
73 73
 				return;
74 74
 			}
75 75
 
@@ -77,124 +77,124 @@  discard block
 block discarded – undo
77 77
 			$response = null;
78 78
 
79 79
 			// This will throw exception if not valid.
80
-			$this->validate_minimum_order_amount( $order );
80
+			$this->validate_minimum_order_amount($order);
81 81
 
82
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
82
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
83 83
 
84 84
 			/**
85 85
 			 * First check if the source is chargeable at this time. If not,
86 86
 			 * webhook will take care of it later.
87 87
 			 */
88
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
88
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
89 89
 
90
-			if ( ! empty( $source_info->error ) ) {
91
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
90
+			if ( ! empty($source_info->error)) {
91
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
92 92
 			}
93 93
 
94
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
95
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
94
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
95
+				throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
96 96
 			}
97 97
 
98 98
 			// If already consumed, then ignore request.
99
-			if ( 'consumed' === $source_info->status ) {
99
+			if ('consumed' === $source_info->status) {
100 100
 				return;
101 101
 			}
102 102
 
103 103
 			// If not chargeable, then ignore request.
104
-			if ( 'chargeable' !== $source_info->status ) {
104
+			if ('chargeable' !== $source_info->status) {
105 105
 				return;
106 106
 			}
107 107
 
108 108
 			// Prep source object.
109 109
 			$source_object           = new stdClass();
110 110
 			$source_object->token_id = '';
111
-			$source_object->customer = $this->get_stripe_customer_id( $order );
111
+			$source_object->customer = $this->get_stripe_customer_id($order);
112 112
 			$source_object->source   = $source_info->id;
113 113
 			$source_object->status   = 'chargeable';
114 114
 
115 115
 			/* If we're doing a retry and source is chargeable, we need to pass
116 116
 			 * a different idempotency key and retry for success.
117 117
 			 */
118
-			if ( $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
119
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
118
+			if ($this->need_update_idempotency_key($source_object, $previous_error)) {
119
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
120 120
 			}
121 121
 
122 122
 			// Make the request.
123
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
123
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
124 124
 			$headers  = $response['headers'];
125 125
 			$response = $response['body'];
126 126
 
127
-			if ( ! empty( $response->error ) ) {
127
+			if ( ! empty($response->error)) {
128 128
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
129
-				if ( $this->is_no_such_customer_error( $response->error ) ) {
130
-					if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
131
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
132
-						delete_post_meta( $order_id, '_stripe_customer_id' );
129
+				if ($this->is_no_such_customer_error($response->error)) {
130
+					if (WC_Stripe_Helper::is_wc_lt('3.0')) {
131
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
132
+						delete_post_meta($order_id, '_stripe_customer_id');
133 133
 					} else {
134
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
135
-						$order->delete_meta_data( '_stripe_customer_id' );
134
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
135
+						$order->delete_meta_data('_stripe_customer_id');
136 136
 						$order->save();
137 137
 					}
138 138
 				}
139 139
 
140
-				if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
140
+				if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
141 141
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
142
-					$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
142
+					$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
143 143
 					$wc_token->delete();
144
-					$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
145
-					$order->add_order_note( $localized_message );
146
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
144
+					$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
145
+					$order->add_order_note($localized_message);
146
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
147 147
 				}
148 148
 
149 149
 				// We want to retry.
150
-				if ( $this->is_retryable_error( $response->error ) ) {
151
-					if ( $retry ) {
150
+				if ($this->is_retryable_error($response->error)) {
151
+					if ($retry) {
152 152
 						// Don't do anymore retries after this.
153
-						if ( 5 <= $this->retry_interval ) {
154
-							return $this->process_redirect_payment( $order_id, false, $response->error );
153
+						if (5 <= $this->retry_interval) {
154
+							return $this->process_redirect_payment($order_id, false, $response->error);
155 155
 						}
156 156
 
157
-						sleep( $this->retry_interval );
157
+						sleep($this->retry_interval);
158 158
 
159 159
 						$this->retry_interval++;
160
-						return $this->process_redirect_payment( $order_id, true, $response->error );
160
+						return $this->process_redirect_payment($order_id, true, $response->error);
161 161
 					} else {
162
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
163
-						$order->add_order_note( $localized_message );
164
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
162
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
163
+						$order->add_order_note($localized_message);
164
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
165 165
 					}
166 166
 				}
167 167
 
168 168
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
169 169
 
170
-				if ( 'card_error' === $response->error->type ) {
171
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
170
+				if ('card_error' === $response->error->type) {
171
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
172 172
 				} else {
173
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
173
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
174 174
 				}
175 175
 
176
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
176
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
177 177
 			}
178 178
 
179 179
 			// To prevent double processing the order on WC side.
180
-			if ( ! $this->is_original_request( $headers ) ) {
180
+			if ( ! $this->is_original_request($headers)) {
181 181
 				return;
182 182
 			}
183 183
 
184
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
184
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
185 185
 
186
-			$this->process_response( $response, $order );
186
+			$this->process_response($response, $order);
187 187
 
188
-		} catch ( WC_Stripe_Exception $e ) {
189
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
188
+		} catch (WC_Stripe_Exception $e) {
189
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
190 190
 
191
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
191
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
192 192
 
193 193
 			/* translators: error message */
194
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
194
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
195 195
 
196
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
197
-			wp_safe_redirect( wc_get_checkout_url() );
196
+			wc_add_notice($e->getLocalizedMessage(), 'error');
197
+			wp_safe_redirect(wc_get_checkout_url());
198 198
 			exit;
199 199
 		}
200 200
 	}
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
 	 * @version 4.0.0
207 207
 	 */
208 208
 	public function maybe_process_redirect_order() {
209
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
209
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
210 210
 			return;
211 211
 		}
212 212
 
213
-		$order_id = wc_clean( $_GET['order_id'] );
213
+		$order_id = wc_clean($_GET['order_id']);
214 214
 
215
-		$this->process_redirect_payment( $order_id );
215
+		$this->process_redirect_payment($order_id);
216 216
 	}
217 217
 
218 218
 	/**
@@ -222,59 +222,59 @@  discard block
 block discarded – undo
222 222
 	 * @version 4.0.0
223 223
 	 * @param  int $order_id
224 224
 	 */
225
-	public function capture_payment( $order_id ) {
226
-		$order = wc_get_order( $order_id );
225
+	public function capture_payment($order_id) {
226
+		$order = wc_get_order($order_id);
227 227
 
228
-		if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) {
229
-			$charge             = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
230
-			$captured           = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
228
+		if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) {
229
+			$charge             = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
230
+			$captured           = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
231 231
 			$is_stripe_captured = false;
232 232
 
233
-			if ( $charge && 'no' === $captured ) {
233
+			if ($charge && 'no' === $captured) {
234 234
 				$order_total = $order->get_total();
235 235
 
236
-				if ( 0 < $order->get_total_refunded() ) {
236
+				if (0 < $order->get_total_refunded()) {
237 237
 					$order_total = $order_total - $order->get_total_refunded();
238 238
 				}
239 239
 
240 240
 				// First retrieve charge to see if it has been captured.
241
-				$result = WC_Stripe_API::retrieve( 'charges/' . $charge );
241
+				$result = WC_Stripe_API::retrieve('charges/' . $charge);
242 242
 
243
-				if ( ! empty( $result->error ) ) {
243
+				if ( ! empty($result->error)) {
244 244
 					/* translators: error message */
245
-					$order->add_order_note( sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
246
-				} elseif ( false === $result->captured ) {
245
+					$order->add_order_note(sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
246
+				} elseif (false === $result->captured) {
247 247
 					$result = WC_Stripe_API::request(
248 248
 						array(
249
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
249
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
250 250
 							'expand[]' => 'balance_transaction',
251 251
 						),
252 252
 						'charges/' . $charge . '/capture'
253 253
 					);
254 254
 
255
-					if ( ! empty( $result->error ) ) {
255
+					if ( ! empty($result->error)) {
256 256
 						/* translators: error message */
257
-						$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
257
+						$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
258 258
 					} else {
259 259
 						$is_stripe_captured = true;
260 260
 					}
261
-				} elseif ( true === $result->captured ) {
261
+				} elseif (true === $result->captured) {
262 262
 					$is_stripe_captured = true;
263 263
 				}
264 264
 
265
-				if ( $is_stripe_captured ) {
265
+				if ($is_stripe_captured) {
266 266
 					/* translators: transaction id */
267
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
268
-					WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
267
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
268
+					WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
269 269
 
270 270
 					// Store other data such as fees
271
-					WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
271
+					WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
272 272
 
273
-					$this->update_fees( $order, $result->balance_transaction->id );
273
+					$this->update_fees($order, $result->balance_transaction->id);
274 274
 				}
275 275
 
276 276
 				// This hook fires when admin manually changes order status to processing or completed.
277
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
277
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
278 278
 			}
279 279
 		}
280 280
 	}
@@ -286,14 +286,14 @@  discard block
 block discarded – undo
286 286
 	 * @version 4.0.0
287 287
 	 * @param  int $order_id
288 288
 	 */
289
-	public function cancel_payment( $order_id ) {
290
-		$order = wc_get_order( $order_id );
289
+	public function cancel_payment($order_id) {
290
+		$order = wc_get_order($order_id);
291 291
 
292
-		if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) {
293
-			$this->process_refund( $order_id );
292
+		if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) {
293
+			$this->process_refund($order_id);
294 294
 
295 295
 			// This hook fires when admin manually changes order status to cancel.
296
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
296
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
297 297
 		}
298 298
 	}
299 299
 }
Please login to merge, or discard this patch.