Completed
Pull Request — master (#1160)
by Marcin
01:51
created
includes/class-wc-stripe-apple-pay-registration.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @since 4.0.6
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if ( ! defined('ABSPATH')) {
9 9
 	exit;
10 10
 }
11 11
 
@@ -60,23 +60,23 @@  discard block
 block discarded – undo
60 60
 	public $apple_pay_verify_notice;
61 61
 
62 62
 	public function __construct() {
63
-		add_action( 'woocommerce_stripe_updated', array( $this, 'update_verification_file' ) );
63
+		add_action('woocommerce_stripe_updated', array($this, 'update_verification_file'));
64 64
 
65
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
66
-		$this->stripe_enabled          = $this->get_option( 'enabled' );
67
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
68
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
65
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
66
+		$this->stripe_enabled          = $this->get_option('enabled');
67
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
68
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
69 69
 		$this->apple_pay_verify_notice = '';
70
-		$this->testmode                = 'yes' === $this->get_option( 'testmode', 'no' );
71
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
70
+		$this->testmode                = 'yes' === $this->get_option('testmode', 'no');
71
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
72 72
 
73
-		if ( empty( $this->stripe_settings ) ) {
73
+		if (empty($this->stripe_settings)) {
74 74
 			return;
75 75
 		}
76 76
 
77 77
 		$this->init_apple_pay();
78 78
 
79
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
79
+		add_action('admin_notices', array($this, 'admin_notices'));
80 80
 	}
81 81
 
82 82
 	/**
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
 	 * @param string default
88 88
 	 * @return string $setting_value
89 89
 	 */
90
-	public function get_option( $setting = '', $default = '' ) {
91
-		if ( empty( $this->stripe_settings ) ) {
90
+	public function get_option($setting = '', $default = '') {
91
+		if (empty($this->stripe_settings)) {
92 92
 			return $default;
93 93
 		}
94 94
 
95
-		if ( ! empty( $this->stripe_settings[ $setting ] ) ) {
96
-			return $this->stripe_settings[ $setting ];
95
+		if ( ! empty($this->stripe_settings[$setting])) {
96
+			return $this->stripe_settings[$setting];
97 97
 		}
98 98
 
99 99
 		return $default;
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 	public function init_apple_pay() {
109 109
 		if (
110 110
 			is_admin() &&
111
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
112
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
113
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
111
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
112
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
113
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
114 114
 			$this->payment_request
115 115
 		) {
116 116
 			$this->process_apple_pay_verification();
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 	 * @version 3.1.0
125 125
 	 * @param string $secret_key
126 126
 	 */
127
-	private function register_apple_pay_domain( $secret_key = '' ) {
128
-		if ( empty( $secret_key ) ) {
129
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
127
+	private function register_apple_pay_domain($secret_key = '') {
128
+		if (empty($secret_key)) {
129
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
130 130
 		}
131 131
 
132 132
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -144,22 +144,22 @@  discard block
 block discarded – undo
144 144
 			$endpoint,
145 145
 			array(
146 146
 				'headers' => $headers,
147
-				'body'    => http_build_query( $data ),
147
+				'body'    => http_build_query($data),
148 148
 			)
149 149
 		);
150 150
 
151
-		if ( is_wp_error( $response ) ) {
151
+		if (is_wp_error($response)) {
152 152
 			/* translators: error message */
153
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
153
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
154 154
 		}
155 155
 
156
-		if ( 200 !== $response['response']['code'] ) {
157
-			$parsed_response = json_decode( $response['body'] );
156
+		if (200 !== $response['response']['code']) {
157
+			$parsed_response = json_decode($response['body']);
158 158
 
159 159
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
160 160
 
161 161
 			/* translators: error message */
162
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
162
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
163 163
 		}
164 164
 	}
165 165
 
@@ -172,31 +172,31 @@  discard block
 block discarded – undo
172 172
 	 * @since 4.3.0
173 173
 	 * @return bool True on success, false on failure.
174 174
 	 */
175
-	public function update_verification_file( $force = false ) {
176
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
175
+	public function update_verification_file($force = false) {
176
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
177 177
 			$dir      = '.well-known';
178 178
 			$file     = 'apple-developer-merchantid-domain-association';
179 179
 			$fullpath = $path . '/' . $dir . '/' . $file;
180 180
 
181
-			$existing_contents = @file_get_contents( $fullpath );
182
-			$new_contents = @file_get_contents( WC_STRIPE_PLUGIN_PATH . '/' . $file );
183
-			if ( ( ! $existing_contents && ! $force ) || $existing_contents === $new_contents ) {
181
+			$existing_contents = @file_get_contents($fullpath);
182
+			$new_contents = @file_get_contents(WC_STRIPE_PLUGIN_PATH . '/' . $file);
183
+			if (( ! $existing_contents && ! $force) || $existing_contents === $new_contents) {
184 184
 				return true;
185 185
 			}
186 186
 
187
-			if ( ! file_exists( $path . '/' . $dir ) ) {
188
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine
189
-					WC_Stripe_Logger::log( 'Error: ' . __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
187
+			if ( ! file_exists($path . '/' . $dir)) {
188
+				if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine
189
+					WC_Stripe_Logger::log('Error: ' . __('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
190 190
 					return false;
191 191
 				}
192 192
 			}
193 193
 
194
-			if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine
195
-				WC_Stripe_Logger::log( 'Error: ' . __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
194
+			if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine
195
+				WC_Stripe_Logger::log('Error: ' . __('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
196 196
 				return false;
197 197
 			}
198 198
 
199
-			WC_Stripe_Logger::log( 'Domain association file updated.' );
199
+			WC_Stripe_Logger::log('Domain association file updated.');
200 200
 			return true;
201 201
 	}
202 202
 
@@ -207,31 +207,31 @@  discard block
 block discarded – undo
207 207
 	 * @version 3.1.0
208 208
 	 */
209 209
 	public function process_apple_pay_verification() {
210
-		if ( ! $this->update_verification_file( true ) ) {
210
+		if ( ! $this->update_verification_file(true)) {
211 211
 			$this->stripe_settings['apple_pay_domain_set'] = 'no';
212
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
212
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
213 213
 			return;
214 214
 		}
215 215
 
216 216
 		try {
217 217
 			// At this point then the domain association folder and file should be available.
218 218
 			// Proceed to verify/and or verify again.
219
-			$this->register_apple_pay_domain( $this->secret_key );
219
+			$this->register_apple_pay_domain($this->secret_key);
220 220
 
221 221
 			// No errors to this point, verification success!
222 222
 			$this->stripe_settings['apple_pay_domain_set'] = 'yes';
223 223
 			$this->apple_pay_domain_set                    = true;
224 224
 
225
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
225
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
226 226
 
227
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
227
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
228 228
 
229
-		} catch ( Exception $e ) {
229
+		} catch (Exception $e) {
230 230
 			$this->stripe_settings['apple_pay_domain_set'] = 'no';
231 231
 
232
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
232
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
233 233
 
234
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
234
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
235 235
 		}
236 236
 	}
237 237
 
@@ -241,15 +241,15 @@  discard block
 block discarded – undo
241 241
 	 * @since 4.0.6
242 242
 	 */
243 243
 	public function admin_notices() {
244
-		if ( ! $this->stripe_enabled ) {
244
+		if ( ! $this->stripe_enabled) {
245 245
 			return;
246 246
 		}
247 247
 
248
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
248
+		if ( ! current_user_can('manage_woocommerce')) {
249 249
 			return;
250 250
 		}
251 251
 
252
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
252
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
253 253
 			$allowed_html = array(
254 254
 				'a' => array(
255 255
 					'href'  => array(),
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 				),
258 258
 			);
259 259
 
260
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
260
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
261 261
 		}
262 262
 
263 263
 		/**
@@ -265,9 +265,9 @@  discard block
 block discarded – undo
265 265
 		 * when setting screen is displayed. So if domain verification is not set,
266 266
 		 * something went wrong so lets notify user.
267 267
 		 */
268
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
268
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
269 269
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
270
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
270
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
271 271
 		}
272 272
 	}
273 273
 }
Please login to merge, or discard this patch.
includes/admin/stripe-eps-settings.php 1 patch
Spacing   +12 added lines, -12 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
 
@@ -7,36 +7,36 @@  discard block
 block discarded – undo
7 7
 	'wc_stripe_eps_settings',
8 8
 	array(
9 9
 		'geo_target'  => array(
10
-			'description' => __( 'Relevant Payer Geography: Austria', 'woocommerce-gateway-stripe' ),
10
+			'description' => __('Relevant Payer Geography: Austria', 'woocommerce-gateway-stripe'),
11 11
 			'type'        => 'title',
12 12
 		),
13 13
 		'activation'  => array(
14
-			'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ),
14
+			'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'),
15 15
 			'type'        => 'title',
16 16
 		),
17 17
 		'enabled'     => array(
18
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
19
-			'label'       => __( 'Enable Stripe EPS', 'woocommerce-gateway-stripe' ),
18
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
19
+			'label'       => __('Enable Stripe EPS', 'woocommerce-gateway-stripe'),
20 20
 			'type'        => 'checkbox',
21 21
 			'description' => '',
22 22
 			'default'     => 'no',
23 23
 		),
24 24
 		'title'       => array(
25
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
25
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
26 26
 			'type'        => 'text',
27
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
28
-			'default'     => __( 'EPS', 'woocommerce-gateway-stripe' ),
27
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
28
+			'default'     => __('EPS', 'woocommerce-gateway-stripe'),
29 29
 			'desc_tip'    => true,
30 30
 		),
31 31
 		'description' => array(
32
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
32
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
33 33
 			'type'        => 'text',
34
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
35
-			'default'     => __( 'You will be redirected to EPS.', 'woocommerce-gateway-stripe' ),
34
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
35
+			'default'     => __('You will be redirected to EPS.', 'woocommerce-gateway-stripe'),
36 36
 			'desc_tip'    => true,
37 37
 		),
38 38
 		'webhook'     => array(
39
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
39
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
40 40
 			'type'        => 'title',
41 41
 			/* translators: webhook URL */
42 42
 			'description' => $this->display_admin_settings_webhook_description(),
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +241 added lines, -241 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
 
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	public function __construct() {
41 41
 		$this->retry_interval = 2;
42
-		$stripe_settings      = get_option( 'woocommerce_stripe_settings', array() );
43
-		$this->testmode       = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false;
44
-		$secret_key           = ( $this->testmode ? 'test_' : '' ) . 'webhook_secret';
45
-		$this->secret         = ! empty( $stripe_settings[ $secret_key ] ) ? $stripe_settings[ $secret_key ] : false;
42
+		$stripe_settings      = get_option('woocommerce_stripe_settings', array());
43
+		$this->testmode       = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false;
44
+		$secret_key           = ($this->testmode ? 'test_' : '') . 'webhook_secret';
45
+		$this->secret         = ! empty($stripe_settings[$secret_key]) ? $stripe_settings[$secret_key] : false;
46 46
 
47
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
47
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
48 48
 	}
49 49
 
50 50
 	/**
@@ -54,24 +54,24 @@  discard block
 block discarded – undo
54 54
 	 * @version 4.0.0
55 55
 	 */
56 56
 	public function check_for_webhook() {
57
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
58
-			|| ! isset( $_GET['wc-api'] )
59
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
57
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
58
+			|| ! isset($_GET['wc-api'])
59
+			|| ('wc_stripe' !== $_GET['wc-api'])
60 60
 		) {
61 61
 			return;
62 62
 		}
63 63
 
64
-		$request_body    = file_get_contents( 'php://input' );
65
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
64
+		$request_body    = file_get_contents('php://input');
65
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
66 66
 
67 67
 		// Validate it to make sure it is legit.
68
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
69
-			$this->process_webhook( $request_body );
70
-			status_header( 200 );
68
+		if ($this->is_valid_request($request_headers, $request_body)) {
69
+			$this->process_webhook($request_body);
70
+			status_header(200);
71 71
 			exit;
72 72
 		} else {
73
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
74
-			status_header( 400 );
73
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
74
+			status_header(400);
75 75
 			exit;
76 76
 		}
77 77
 	}
@@ -85,34 +85,34 @@  discard block
 block discarded – undo
85 85
 	 * @param string $request_body The request body from Stripe.
86 86
 	 * @return bool
87 87
 	 */
88
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
89
-		if ( null === $request_headers || null === $request_body ) {
88
+	public function is_valid_request($request_headers = null, $request_body = null) {
89
+		if (null === $request_headers || null === $request_body) {
90 90
 			return false;
91 91
 		}
92 92
 
93
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
93
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
94 94
 			return false;
95 95
 		}
96 96
 
97
-		if ( ! empty( $this->secret ) ) {
97
+		if ( ! empty($this->secret)) {
98 98
 			// Check for a valid signature.
99 99
 			$signature_format = '/^t=(?P<timestamp>\d+)(?P<signatures>(,v\d+=[a-z0-9]+){1,2})$/';
100
-			if ( empty( $request_headers['STRIPE-SIGNATURE'] ) || ! preg_match( $signature_format, $request_headers['STRIPE-SIGNATURE'], $matches ) ) {
100
+			if (empty($request_headers['STRIPE-SIGNATURE']) || ! preg_match($signature_format, $request_headers['STRIPE-SIGNATURE'], $matches)) {
101 101
 				return false;
102 102
 			}
103 103
 
104 104
 			// Verify the timestamp.
105
-			$timestamp = intval( $matches['timestamp'] );
106
-			if ( abs( $timestamp - time() ) > 5 * MINUTE_IN_SECONDS ) {
105
+			$timestamp = intval($matches['timestamp']);
106
+			if (abs($timestamp - time()) > 5 * MINUTE_IN_SECONDS) {
107 107
 				return;
108 108
 			}
109 109
 
110 110
 			// Generate the expected signature.
111 111
 			$signed_payload     = $timestamp . '.' . $request_body;
112
-			$expected_signature = hash_hmac( 'sha256', $signed_payload, $this->secret );
112
+			$expected_signature = hash_hmac('sha256', $signed_payload, $this->secret);
113 113
 
114 114
 			// Check if the expected signature is present.
115
-			if ( ! preg_match( '/,v\d+=' . preg_quote( $expected_signature, '/' ) . '/', $matches['signatures'] ) ) {
115
+			if ( ! preg_match('/,v\d+=' . preg_quote($expected_signature, '/') . '/', $matches['signatures'])) {
116 116
 				return false;
117 117
 			}
118 118
 		}
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 	 * @version 4.0.0
130 130
 	 */
131 131
 	public function get_request_headers() {
132
-		if ( ! function_exists( 'getallheaders' ) ) {
132
+		if ( ! function_exists('getallheaders')) {
133 133
 			$headers = array();
134 134
 
135
-			foreach ( $_SERVER as $name => $value ) {
136
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
137
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
135
+			foreach ($_SERVER as $name => $value) {
136
+				if ('HTTP_' === substr($name, 0, 5)) {
137
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
138 138
 				}
139 139
 			}
140 140
 
@@ -153,30 +153,30 @@  discard block
 block discarded – undo
153 153
 	 * @param object $notification
154 154
 	 * @param bool $retry
155 155
 	 */
156
-	public function process_webhook_payment( $notification, $retry = true ) {
156
+	public function process_webhook_payment($notification, $retry = true) {
157 157
 		// The following 3 payment methods are synchronous so does not need to be handle via webhook.
158
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) {
158
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) {
159 159
 			return;
160 160
 		}
161 161
 
162
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
162
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
163 163
 
164
-		if ( ! $order ) {
165
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
164
+		if ( ! $order) {
165
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
166 166
 			return;
167 167
 		}
168 168
 
169
-		$order_id  = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
169
+		$order_id  = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
170 170
 		$source_id = $notification->data->object->id;
171 171
 
172
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
172
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
173 173
 
174 174
 		try {
175
-			if ( $order->has_status( array( 'processing', 'completed' ) ) ) {
175
+			if ($order->has_status(array('processing', 'completed'))) {
176 176
 				return;
177 177
 			}
178 178
 
179
-			if ( $order->has_status( 'on-hold' ) && ! $is_pending_receiver ) {
179
+			if ($order->has_status('on-hold') && ! $is_pending_receiver) {
180 180
 				return;
181 181
 			}
182 182
 
@@ -184,94 +184,94 @@  discard block
 block discarded – undo
184 184
 			$response = null;
185 185
 
186 186
 			// This will throw exception if not valid.
187
-			$this->validate_minimum_order_amount( $order );
187
+			$this->validate_minimum_order_amount($order);
188 188
 
189
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
189
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
190 190
 
191 191
 			// Prep source object.
192 192
 			$source_object           = new stdClass();
193 193
 			$source_object->token_id = '';
194
-			$source_object->customer = $this->get_stripe_customer_id( $order );
194
+			$source_object->customer = $this->get_stripe_customer_id($order);
195 195
 			$source_object->source   = $source_id;
196 196
 
197 197
 			// Make the request.
198
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
198
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
199 199
 			$headers  = $response['headers'];
200 200
 			$response = $response['body'];
201 201
 
202
-			if ( ! empty( $response->error ) ) {
202
+			if ( ! empty($response->error)) {
203 203
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
204
-				if ( $this->is_no_such_customer_error( $response->error ) ) {
205
-					if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
206
-						delete_user_option( $order->customer_user, '_stripe_customer_id' );
207
-						delete_post_meta( $order_id, '_stripe_customer_id' );
204
+				if ($this->is_no_such_customer_error($response->error)) {
205
+					if (WC_Stripe_Helper::is_wc_lt('3.0')) {
206
+						delete_user_option($order->customer_user, '_stripe_customer_id');
207
+						delete_post_meta($order_id, '_stripe_customer_id');
208 208
 					} else {
209
-						delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
210
-						$order->delete_meta_data( '_stripe_customer_id' );
209
+						delete_user_option($order->get_customer_id(), '_stripe_customer_id');
210
+						$order->delete_meta_data('_stripe_customer_id');
211 211
 						$order->save();
212 212
 					}
213 213
 				}
214 214
 
215
-				if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
215
+				if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
216 216
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
217
-					$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
217
+					$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
218 218
 					$wc_token->delete();
219
-					$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
220
-					$order->add_order_note( $localized_message );
221
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
219
+					$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
220
+					$order->add_order_note($localized_message);
221
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
222 222
 				}
223 223
 
224 224
 				// We want to retry.
225
-				if ( $this->is_retryable_error( $response->error ) ) {
226
-					if ( $retry ) {
225
+				if ($this->is_retryable_error($response->error)) {
226
+					if ($retry) {
227 227
 						// Don't do anymore retries after this.
228
-						if ( 5 <= $this->retry_interval ) {
228
+						if (5 <= $this->retry_interval) {
229 229
 
230
-							return $this->process_webhook_payment( $notification, false );
230
+							return $this->process_webhook_payment($notification, false);
231 231
 						}
232 232
 
233
-						sleep( $this->retry_interval );
233
+						sleep($this->retry_interval);
234 234
 
235 235
 						$this->retry_interval++;
236
-						return $this->process_webhook_payment( $notification, true );
236
+						return $this->process_webhook_payment($notification, true);
237 237
 					} else {
238
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
239
-						$order->add_order_note( $localized_message );
240
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
238
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
239
+						$order->add_order_note($localized_message);
240
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
241 241
 					}
242 242
 				}
243 243
 
244 244
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
245 245
 
246
-				if ( 'card_error' === $response->error->type ) {
247
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
246
+				if ('card_error' === $response->error->type) {
247
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
248 248
 				} else {
249
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
249
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
250 250
 				}
251 251
 
252
-				$order->add_order_note( $localized_message );
252
+				$order->add_order_note($localized_message);
253 253
 
254
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
254
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
255 255
 			}
256 256
 
257 257
 			// To prevent double processing the order on WC side.
258
-			if ( ! $this->is_original_request( $headers ) ) {
258
+			if ( ! $this->is_original_request($headers)) {
259 259
 				return;
260 260
 			}
261 261
 
262
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
262
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
263 263
 
264
-			$this->process_response( $response, $order );
264
+			$this->process_response($response, $order);
265 265
 
266
-		} catch ( WC_Stripe_Exception $e ) {
267
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
266
+		} catch (WC_Stripe_Exception $e) {
267
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
268 268
 
269
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e );
269
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e);
270 270
 
271
-			$statuses = array( 'pending', 'failed' );
271
+			$statuses = array('pending', 'failed');
272 272
 
273
-			if ( $order->has_status( $statuses ) ) {
274
-				$this->send_failed_order_email( $order_id );
273
+			if ($order->has_status($statuses)) {
274
+				$this->send_failed_order_email($order_id);
275 275
 			}
276 276
 		}
277 277
 	}
@@ -284,21 +284,21 @@  discard block
 block discarded – undo
284 284
 	 * @since 4.0.0
285 285
 	 * @param object $notification
286 286
 	 */
287
-	public function process_webhook_dispute( $notification ) {
288
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
287
+	public function process_webhook_dispute($notification) {
288
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
289 289
 
290
-		if ( ! $order ) {
291
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
290
+		if ( ! $order) {
291
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
292 292
 			return;
293 293
 		}
294 294
 
295 295
 		/* translators: 1) The URL to the order. */
296
-		$order->update_status( 'on-hold', sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ) );
296
+		$order->update_status('on-hold', sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order)));
297 297
 
298
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
298
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
299 299
 
300
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
301
-		$this->send_failed_order_email( $order_id );
300
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
301
+		$this->send_failed_order_email($order_id);
302 302
 	}
303 303
 
304 304
 	/**
@@ -309,45 +309,45 @@  discard block
 block discarded – undo
309 309
 	 * @version 4.0.0
310 310
 	 * @param object $notification
311 311
 	 */
312
-	public function process_webhook_capture( $notification ) {
313
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
312
+	public function process_webhook_capture($notification) {
313
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
314 314
 
315
-		if ( ! $order ) {
316
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
315
+		if ( ! $order) {
316
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
317 317
 			return;
318 318
 		}
319 319
 
320
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
320
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
321 321
 
322
-		if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) {
323
-			$charge   = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
324
-			$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 );
322
+		if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) {
323
+			$charge   = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
324
+			$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);
325 325
 
326
-			if ( $charge && 'no' === $captured ) {
327
-				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' );
326
+			if ($charge && 'no' === $captured) {
327
+				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');
328 328
 
329 329
 				// Store other data such as fees
330
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
330
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
331 331
 
332
-				if ( isset( $notification->data->object->balance_transaction ) ) {
333
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
332
+				if (isset($notification->data->object->balance_transaction)) {
333
+					$this->update_fees($order, $notification->data->object->balance_transaction);
334 334
 				}
335 335
 
336 336
 				// Check and see if capture is partial.
337
-				if ( $this->is_partial_capture( $notification ) ) {
338
-					$partial_amount = $this->get_partial_amount_to_charge( $notification );
339
-					$order->set_total( $partial_amount );
340
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
337
+				if ($this->is_partial_capture($notification)) {
338
+					$partial_amount = $this->get_partial_amount_to_charge($notification);
339
+					$order->set_total($partial_amount);
340
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
341 341
 					/* translators: partial captured amount */
342
-					$order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) );
342
+					$order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount));
343 343
 				} else {
344
-					$order->payment_complete( $notification->data->object->id );
344
+					$order->payment_complete($notification->data->object->id);
345 345
 
346 346
 					/* translators: transaction id */
347
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
347
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
348 348
 				}
349 349
 
350
-				if ( is_callable( array( $order, 'save' ) ) ) {
350
+				if (is_callable(array($order, 'save'))) {
351 351
 					$order->save();
352 352
 				}
353 353
 			}
@@ -362,43 +362,43 @@  discard block
 block discarded – undo
362 362
 	 * @version 4.0.0
363 363
 	 * @param object $notification
364 364
 	 */
365
-	public function process_webhook_charge_succeeded( $notification ) {
365
+	public function process_webhook_charge_succeeded($notification) {
366 366
 		// Ignore the notification for charges, created through PaymentIntents.
367
-		if ( isset( $notification->data->object->payment_intent ) && $notification->data->object->payment_intent ) {
367
+		if (isset($notification->data->object->payment_intent) && $notification->data->object->payment_intent) {
368 368
 			return;
369 369
 		}
370 370
 
371 371
 		// The following payment methods are synchronous so does not need to be handle via webhook.
372
-		if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) {
372
+		if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) {
373 373
 			return;
374 374
 		}
375 375
 
376
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
376
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
377 377
 
378
-		if ( ! $order ) {
379
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
378
+		if ( ! $order) {
379
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
380 380
 			return;
381 381
 		}
382 382
 
383
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
383
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
384 384
 
385
-		if ( ! $order->has_status( 'on-hold' ) ) {
385
+		if ( ! $order->has_status('on-hold')) {
386 386
 			return;
387 387
 		}
388 388
 
389 389
 		// Store other data such as fees
390
-		WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
390
+		WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
391 391
 
392
-		if ( isset( $notification->data->object->balance_transaction ) ) {
393
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
392
+		if (isset($notification->data->object->balance_transaction)) {
393
+			$this->update_fees($order, $notification->data->object->balance_transaction);
394 394
 		}
395 395
 
396
-		$order->payment_complete( $notification->data->object->id );
396
+		$order->payment_complete($notification->data->object->id);
397 397
 
398 398
 		/* translators: transaction id */
399
-		$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
399
+		$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
400 400
 
401
-		if ( is_callable( array( $order, 'save' ) ) ) {
401
+		if (is_callable(array($order, 'save'))) {
402 402
 			$order->save();
403 403
 		}
404 404
 	}
@@ -410,24 +410,24 @@  discard block
 block discarded – undo
410 410
 	 * @since 4.1.5 Can handle any fail payments from any methods.
411 411
 	 * @param object $notification
412 412
 	 */
413
-	public function process_webhook_charge_failed( $notification ) {
414
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
413
+	public function process_webhook_charge_failed($notification) {
414
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
415 415
 
416
-		if ( ! $order ) {
417
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
416
+		if ( ! $order) {
417
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
418 418
 			return;
419 419
 		}
420 420
 
421
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
421
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
422 422
 
423 423
 		// If order status is already in failed status don't continue.
424
-		if ( $order->has_status( 'failed' ) ) {
424
+		if ($order->has_status('failed')) {
425 425
 			return;
426 426
 		}
427 427
 
428
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
428
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
429 429
 
430
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
430
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
431 431
 	}
432 432
 
433 433
 	/**
@@ -438,30 +438,30 @@  discard block
 block discarded – undo
438 438
 	 * @since 4.1.15 Add check to make sure order is processed by Stripe.
439 439
 	 * @param object $notification
440 440
 	 */
441
-	public function process_webhook_source_canceled( $notification ) {
442
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
441
+	public function process_webhook_source_canceled($notification) {
442
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
443 443
 
444 444
 		// If can't find order by charge ID, try source ID.
445
-		if ( ! $order ) {
446
-			$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
445
+		if ( ! $order) {
446
+			$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
447 447
 
448
-			if ( ! $order ) {
449
-				WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id );
448
+			if ( ! $order) {
449
+				WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id);
450 450
 				return;
451 451
 			}
452 452
 		}
453 453
 
454 454
 		// Don't proceed if payment method isn't Stripe.
455
-		if ( 'stripe' !== $order->get_payment_method() ) {
456
-			WC_Stripe_Logger::log( 'Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id() );
455
+		if ('stripe' !== $order->get_payment_method()) {
456
+			WC_Stripe_Logger::log('Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id());
457 457
 			return;
458 458
 		}
459 459
 
460
-		if ( ! $order->has_status( 'cancelled' ) ) {
461
-			$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
460
+		if ( ! $order->has_status('cancelled')) {
461
+			$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
462 462
 		}
463 463
 
464
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
464
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
465 465
 	}
466 466
 
467 467
 	/**
@@ -471,59 +471,59 @@  discard block
 block discarded – undo
471 471
 	 * @version 4.0.0
472 472
 	 * @param object $notification
473 473
 	 */
474
-	public function process_webhook_refund( $notification ) {
475
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
474
+	public function process_webhook_refund($notification) {
475
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
476 476
 
477
-		if ( ! $order ) {
478
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
477
+		if ( ! $order) {
478
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
479 479
 			return;
480 480
 		}
481 481
 
482
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
482
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
483 483
 
484
-		if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) {
485
-			$charge    = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
486
-			$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 );
487
-			$refund_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
484
+		if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) {
485
+			$charge    = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
486
+			$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);
487
+			$refund_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
488 488
 
489 489
 			// If the refund ID matches, don't continue to prevent double refunding.
490
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
490
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
491 491
 				return;
492 492
 			}
493 493
 
494 494
 			// Only refund captured charge.
495
-			if ( $charge ) {
496
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
495
+			if ($charge) {
496
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
497 497
 
498 498
 				// Create the refund.
499 499
 				$refund = wc_create_refund(
500 500
 					array(
501 501
 						'order_id' => $order_id,
502
-						'amount'   => $this->get_refund_amount( $notification ),
502
+						'amount'   => $this->get_refund_amount($notification),
503 503
 						'reason'   => $reason,
504 504
 					)
505 505
 				);
506 506
 
507
-				if ( is_wp_error( $refund ) ) {
508
-					WC_Stripe_Logger::log( $refund->get_error_message() );
507
+				if (is_wp_error($refund)) {
508
+					WC_Stripe_Logger::log($refund->get_error_message());
509 509
 				}
510 510
 
511
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ) : $order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id );
511
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id) : $order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id);
512 512
 
513
-				$amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 );
513
+				$amount = wc_price($notification->data->object->refunds->data[0]->amount / 100);
514 514
 
515
-				if ( in_array( strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
516
-					$amount = wc_price( $notification->data->object->refunds->data[0]->amount );
515
+				if (in_array(strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
516
+					$amount = wc_price($notification->data->object->refunds->data[0]->amount);
517 517
 				}
518 518
 
519
-				if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) {
520
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
519
+				if (isset($notification->data->object->refunds->data[0]->balance_transaction)) {
520
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
521 521
 				}
522 522
 
523 523
 				/* translators: 1) dollar amount 2) transaction id 3) refund message */
524
-				$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $notification->data->object->refunds->data[0]->id, $reason ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
524
+				$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe'), $amount, $notification->data->object->refunds->data[0]->id, $reason) : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
525 525
 
526
-				$order->add_order_note( $refund_message );
526
+				$order->add_order_note($refund_message);
527 527
 			}
528 528
 		}
529 529
 	}
@@ -534,30 +534,30 @@  discard block
 block discarded – undo
534 534
 	 * @since 4.0.6
535 535
 	 * @param object $notification
536 536
 	 */
537
-	public function process_review_opened( $notification ) {
538
-		if ( isset( $notification->data->object->payment_intent ) ) {
539
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
537
+	public function process_review_opened($notification) {
538
+		if (isset($notification->data->object->payment_intent)) {
539
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
540 540
 
541
-			if ( ! $order ) {
542
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
541
+			if ( ! $order) {
542
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
543 543
 				return;
544 544
 			}
545 545
 		} else {
546
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
546
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
547 547
 
548
-			if ( ! $order ) {
549
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge );
548
+			if ( ! $order) {
549
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge);
550 550
 				return;
551 551
 			}
552 552
 		}
553 553
 
554 554
 		/* translators: 1) The URL to the order. 2) The reason type. */
555
-		$message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason );
555
+		$message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason);
556 556
 
557
-		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
558
-			$order->update_status( 'on-hold', $message );
557
+		if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
558
+			$order->update_status('on-hold', $message);
559 559
 		} else {
560
-			$order->add_order_note( $message );
560
+			$order->add_order_note($message);
561 561
 		}
562 562
 	}
563 563
 
@@ -567,34 +567,34 @@  discard block
 block discarded – undo
567 567
 	 * @since 4.0.6
568 568
 	 * @param object $notification
569 569
 	 */
570
-	public function process_review_closed( $notification ) {
571
-		if ( isset( $notification->data->object->payment_intent ) ) {
572
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
570
+	public function process_review_closed($notification) {
571
+		if (isset($notification->data->object->payment_intent)) {
572
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
573 573
 
574
-			if ( ! $order ) {
575
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
574
+			if ( ! $order) {
575
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
576 576
 				return;
577 577
 			}
578 578
 		} else {
579
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
579
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
580 580
 
581
-			if ( ! $order ) {
582
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge );
581
+			if ( ! $order) {
582
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge);
583 583
 				return;
584 584
 			}
585 585
 		}
586 586
 
587 587
 		/* translators: 1) The reason type. */
588
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
588
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
589 589
 
590
-		if ( $order->has_status( 'on-hold' ) ) {
591
-			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
592
-				$order->update_status( 'processing', $message );
590
+		if ($order->has_status('on-hold')) {
591
+			if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
592
+				$order->update_status('processing', $message);
593 593
 			} else {
594
-				$order->add_order_note( $message );
594
+				$order->add_order_note($message);
595 595
 			}
596 596
 		} else {
597
-			$order->add_order_note( $message );
597
+			$order->add_order_note($message);
598 598
 		}
599 599
 	}
600 600
 
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 	 * @version 4.0.0
606 606
 	 * @param object $notification
607 607
 	 */
608
-	public function is_partial_capture( $notification ) {
608
+	public function is_partial_capture($notification) {
609 609
 		return 0 < $notification->data->object->amount_refunded;
610 610
 	}
611 611
 
@@ -616,11 +616,11 @@  discard block
 block discarded – undo
616 616
 	 * @version 4.0.0
617 617
 	 * @param object $notification
618 618
 	 */
619
-	public function get_refund_amount( $notification ) {
620
-		if ( $this->is_partial_capture( $notification ) ) {
619
+	public function get_refund_amount($notification) {
620
+		if ($this->is_partial_capture($notification)) {
621 621
 			$amount = $notification->data->object->refunds->data[0]->amount / 100;
622 622
 
623
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
623
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
624 624
 				$amount = $notification->data->object->refunds->data[0]->amount;
625 625
 			}
626 626
 
@@ -637,12 +637,12 @@  discard block
 block discarded – undo
637 637
 	 * @version 4.0.0
638 638
 	 * @param object $notification
639 639
 	 */
640
-	public function get_partial_amount_to_charge( $notification ) {
641
-		if ( $this->is_partial_capture( $notification ) ) {
642
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
640
+	public function get_partial_amount_to_charge($notification) {
641
+		if ($this->is_partial_capture($notification)) {
642
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
643 643
 
644
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
645
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
644
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
645
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
646 646
 			}
647 647
 
648 648
 			return $amount;
@@ -651,69 +651,69 @@  discard block
 block discarded – undo
651 651
 		return false;
652 652
 	}
653 653
 
654
-	public function process_payment_intent_success( $notification ) {
654
+	public function process_payment_intent_success($notification) {
655 655
 		$intent = $notification->data->object;
656
-		$order = WC_Stripe_Helper::get_order_by_intent_id( $intent->id );
656
+		$order = WC_Stripe_Helper::get_order_by_intent_id($intent->id);
657 657
 
658
-		if ( ! $order ) {
659
-			WC_Stripe_Logger::log( 'Could not find order via intent ID: ' . $intent->id );
658
+		if ( ! $order) {
659
+			WC_Stripe_Logger::log('Could not find order via intent ID: ' . $intent->id);
660 660
 			return;
661 661
 		}
662 662
 
663
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
663
+		if ( ! $order->has_status(array('pending', 'failed'))) {
664 664
 			return;
665 665
 		}
666 666
 
667
-		if ( $this->lock_order_payment( $order, $intent ) ) {
667
+		if ($this->lock_order_payment($order, $intent)) {
668 668
 			return;
669 669
 		}
670 670
 
671
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
672
-		if ( 'payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type ) {
673
-			$charge = end( $intent->charges->data );
674
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
671
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
672
+		if ('payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type) {
673
+			$charge = end($intent->charges->data);
674
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
675 675
 
676
-			do_action( 'wc_gateway_stripe_process_payment', $charge, $order );
676
+			do_action('wc_gateway_stripe_process_payment', $charge, $order);
677 677
 
678 678
 			// Process valid response.
679
-			$this->process_response( $charge, $order );
679
+			$this->process_response($charge, $order);
680 680
 
681 681
 		} else {
682 682
 			$error_message = $intent->last_payment_error ? $intent->last_payment_error->message : "";
683 683
 
684 684
 			/* translators: 1) The error message that was received from Stripe. */
685
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
685
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
686 686
 
687
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
687
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
688 688
 
689
-			$this->send_failed_order_email( $order_id );
689
+			$this->send_failed_order_email($order_id);
690 690
 		}
691 691
 
692
-		$this->unlock_order_payment( $order );
692
+		$this->unlock_order_payment($order);
693 693
 	}
694 694
 
695
-	public function process_setup_intent( $notification ) {
695
+	public function process_setup_intent($notification) {
696 696
 		$intent = $notification->data->object;
697
-		$order = WC_Stripe_Helper::get_order_by_setup_intent_id( $intent->id );
697
+		$order = WC_Stripe_Helper::get_order_by_setup_intent_id($intent->id);
698 698
 
699
-		if ( ! $order ) {
700
-			WC_Stripe_Logger::log( 'Could not find order via setup intent ID: ' . $intent->id );
699
+		if ( ! $order) {
700
+			WC_Stripe_Logger::log('Could not find order via setup intent ID: ' . $intent->id);
701 701
 			return;
702 702
 		}
703 703
 
704
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
704
+		if ( ! $order->has_status(array('pending', 'failed'))) {
705 705
 			return;
706 706
 		}
707 707
 
708
-		if ( $this->lock_order_payment( $order, $intent ) ) {
708
+		if ($this->lock_order_payment($order, $intent)) {
709 709
 			return;
710 710
 		}
711 711
 
712
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
713
-		if ( 'setup_intent.succeeded' === $notification->type ) {
714
-			WC_Stripe_Logger::log( "Stripe SetupIntent $intent->id succeeded for order $order_id" );
715
-			if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) {
716
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
712
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
713
+		if ('setup_intent.succeeded' === $notification->type) {
714
+			WC_Stripe_Logger::log("Stripe SetupIntent $intent->id succeeded for order $order_id");
715
+			if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) {
716
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
717 717
 			} else {
718 718
 				$order->payment_complete();
719 719
 			}
@@ -721,12 +721,12 @@  discard block
 block discarded – undo
721 721
 			$error_message = $intent->last_setup_error ? $intent->last_setup_error->message : "";
722 722
 
723 723
 			/* translators: 1) The error message that was received from Stripe. */
724
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
724
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
725 725
 
726
-			$this->send_failed_order_email( $order_id );
726
+			$this->send_failed_order_email($order_id);
727 727
 		}
728 728
 
729
-		$this->unlock_order_payment( $order );
729
+		$this->unlock_order_payment($order);
730 730
 	}
731 731
 
732 732
 	/**
@@ -736,55 +736,55 @@  discard block
 block discarded – undo
736 736
 	 * @version 4.0.0
737 737
 	 * @param string $request_body
738 738
 	 */
739
-	public function process_webhook( $request_body ) {
740
-		$notification = json_decode( $request_body );
739
+	public function process_webhook($request_body) {
740
+		$notification = json_decode($request_body);
741 741
 
742
-		switch ( $notification->type ) {
742
+		switch ($notification->type) {
743 743
 			case 'source.chargeable':
744
-				$this->process_webhook_payment( $notification );
744
+				$this->process_webhook_payment($notification);
745 745
 				break;
746 746
 
747 747
 			case 'source.canceled':
748
-				$this->process_webhook_source_canceled( $notification );
748
+				$this->process_webhook_source_canceled($notification);
749 749
 				break;
750 750
 
751 751
 			case 'charge.succeeded':
752
-				$this->process_webhook_charge_succeeded( $notification );
752
+				$this->process_webhook_charge_succeeded($notification);
753 753
 				break;
754 754
 
755 755
 			case 'charge.failed':
756
-				$this->process_webhook_charge_failed( $notification );
756
+				$this->process_webhook_charge_failed($notification);
757 757
 				break;
758 758
 
759 759
 			case 'charge.captured':
760
-				$this->process_webhook_capture( $notification );
760
+				$this->process_webhook_capture($notification);
761 761
 				break;
762 762
 
763 763
 			case 'charge.dispute.created':
764
-				$this->process_webhook_dispute( $notification );
764
+				$this->process_webhook_dispute($notification);
765 765
 				break;
766 766
 
767 767
 			case 'charge.refunded':
768
-				$this->process_webhook_refund( $notification );
768
+				$this->process_webhook_refund($notification);
769 769
 				break;
770 770
 
771 771
 			case 'review.opened':
772
-				$this->process_review_opened( $notification );
772
+				$this->process_review_opened($notification);
773 773
 				break;
774 774
 
775 775
 			case 'review.closed':
776
-				$this->process_review_closed( $notification );
776
+				$this->process_review_closed($notification);
777 777
 				break;
778 778
 
779 779
 			case 'payment_intent.succeeded':
780 780
 			case 'payment_intent.payment_failed':
781 781
 			case 'payment_intent.amount_capturable_updated':
782
-				$this->process_payment_intent_success( $notification );
782
+				$this->process_payment_intent_success($notification);
783 783
 				break;
784 784
 
785 785
 			case 'setup_intent.succeeded':
786 786
 			case 'setup_intent.setup_failed':
787
-				$this->process_setup_intent( $notification );
787
+				$this->process_setup_intent($notification);
788 788
 
789 789
 		}
790 790
 	}
Please login to merge, or discard this patch.
includes/admin/class-wc-stripe-privacy.php 1 patch
Spacing   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! class_exists( 'WC_Abstract_Privacy' ) ) {
2
+if ( ! class_exists('WC_Abstract_Privacy')) {
3 3
 	return;
4 4
 }
5 5
 
@@ -9,20 +9,20 @@  discard block
 block discarded – undo
9 9
 	 *
10 10
 	 */
11 11
 	public function __construct() {
12
-		parent::__construct( __( 'Stripe', 'woocommerce-gateway-stripe' ) );
12
+		parent::__construct(__('Stripe', 'woocommerce-gateway-stripe'));
13 13
 
14
-		$this->add_exporter( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe' ), array( $this, 'order_data_exporter' ) );
14
+		$this->add_exporter('woocommerce-gateway-stripe-order-data', __('WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe'), array($this, 'order_data_exporter'));
15 15
 
16
-		if ( function_exists( 'wcs_get_subscriptions' ) ) {
17
-			$this->add_exporter( 'woocommerce-gateway-stripe-subscriptions-data', __( 'WooCommerce Stripe Subscriptions Data', 'woocommerce-gateway-stripe' ), array( $this, 'subscriptions_data_exporter' ) );
16
+		if (function_exists('wcs_get_subscriptions')) {
17
+			$this->add_exporter('woocommerce-gateway-stripe-subscriptions-data', __('WooCommerce Stripe Subscriptions Data', 'woocommerce-gateway-stripe'), array($this, 'subscriptions_data_exporter'));
18 18
 		}
19 19
 
20
-		$this->add_exporter( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), array( $this, 'customer_data_exporter' ) );
20
+		$this->add_exporter('woocommerce-gateway-stripe-customer-data', __('WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe'), array($this, 'customer_data_exporter'));
21 21
 
22
-		$this->add_eraser( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), array( $this, 'customer_data_eraser' ) );
23
-		$this->add_eraser( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Data', 'woocommerce-gateway-stripe' ), array( $this, 'order_data_eraser' ) );
22
+		$this->add_eraser('woocommerce-gateway-stripe-customer-data', __('WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe'), array($this, 'customer_data_eraser'));
23
+		$this->add_eraser('woocommerce-gateway-stripe-order-data', __('WooCommerce Stripe Data', 'woocommerce-gateway-stripe'), array($this, 'order_data_eraser'));
24 24
 
25
-		add_filter( 'woocommerce_get_settings_account', array( $this, 'account_settings' ) );
25
+		add_filter('woocommerce_get_settings_account', array($this, 'account_settings'));
26 26
 	}
27 27
 
28 28
 	/**
@@ -31,14 +31,14 @@  discard block
 block discarded – undo
31 31
 	 * @param array $settings
32 32
 	 * @return array $settings Updated
33 33
 	 */
34
-	public function account_settings( $settings ) {
34
+	public function account_settings($settings) {
35 35
 		$insert_setting = array(
36 36
 			array(
37
-				'title'       => __( 'Retain Stripe Data', 'woocommerce-gateway-stripe' ),
38
-				'desc_tip'    => __( 'Retains any Stripe data such as Stripe customer ID, source ID.', 'woocommerce-gateway-stripe' ),
37
+				'title'       => __('Retain Stripe Data', 'woocommerce-gateway-stripe'),
38
+				'desc_tip'    => __('Retains any Stripe data such as Stripe customer ID, source ID.', 'woocommerce-gateway-stripe'),
39 39
 				'id'          => 'woocommerce_gateway_stripe_retention',
40 40
 				'type'        => 'relative_date_selector',
41
-				'placeholder' => __( 'N/A', 'woocommerce-gateway-stripe' ),
41
+				'placeholder' => __('N/A', 'woocommerce-gateway-stripe'),
42 42
 				'default'     => '',
43 43
 				'autoload'    => false,
44 44
 			),
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 
47 47
 		$index = null;
48 48
 
49
-		foreach ( $settings as $key => $value) {
50
-			if ( 'sectionend' === $value[ 'type' ] && 'personal_data_retention' === $value[ 'id' ] ) {
49
+		foreach ($settings as $key => $value) {
50
+			if ('sectionend' === $value['type'] && 'personal_data_retention' === $value['id']) {
51 51
 				$index = $key;
52 52
 				break;
53 53
 			}
54 54
 		}
55 55
 
56
-		if ( ! is_null( $index ) ) {
57
-			array_splice( $settings, $index, 0, $insert_setting );
56
+		if ( ! is_null($index)) {
57
+			array_splice($settings, $index, 0, $insert_setting);
58 58
 		}
59 59
 
60 60
 		return $settings;
@@ -68,22 +68,22 @@  discard block
 block discarded – undo
68 68
 	 *
69 69
 	 * @return array WP_Post
70 70
 	 */
71
-	protected function get_stripe_orders( $email_address, $page ) {
72
-		$user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
71
+	protected function get_stripe_orders($email_address, $page) {
72
+		$user = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data.
73 73
 
74 74
 		$order_query = array(
75
-			'payment_method' => array( 'stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort' ),
75
+			'payment_method' => array('stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort'),
76 76
 			'limit'          => 10,
77 77
 			'page'           => $page,
78 78
 		);
79 79
 
80
-		if ( $user instanceof WP_User ) {
80
+		if ($user instanceof WP_User) {
81 81
 			$order_query['customer_id'] = (int) $user->ID;
82 82
 		} else {
83 83
 			$order_query['billing_email'] = $email_address;
84 84
 		}
85 85
 
86
-		return wc_get_orders( $order_query );
86
+		return wc_get_orders($order_query);
87 87
 	}
88 88
 
89 89
 	/**
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	public function get_privacy_message() {
94 94
 		/* translators: %s URL to docs */
95
-		return wpautop( sprintf( __( 'By using this extension, you may be storing personal data or sharing data with an external service. <a href="%s" target="_blank">Learn more about how this works, including what you may want to include in your privacy policy.</a>', 'woocommerce-gateway-stripe' ), 'https://docs.woocommerce.com/document/privacy-payments/#woocommerce-gateway-stripe' ) );
95
+		return wpautop(sprintf(__('By using this extension, you may be storing personal data or sharing data with an external service. <a href="%s" target="_blank">Learn more about how this works, including what you may want to include in your privacy policy.</a>', 'woocommerce-gateway-stripe'), 'https://docs.woocommerce.com/document/privacy-payments/#woocommerce-gateway-stripe'));
96 96
 	}
97 97
 
98 98
 	/**
@@ -103,34 +103,34 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @return array
105 105
 	 */
106
-	public function order_data_exporter( $email_address, $page = 1 ) {
106
+	public function order_data_exporter($email_address, $page = 1) {
107 107
 		$done           = false;
108 108
 		$data_to_export = array();
109 109
 
110
-		$orders = $this->get_stripe_orders( $email_address, (int) $page );
110
+		$orders = $this->get_stripe_orders($email_address, (int) $page);
111 111
 
112 112
 		$done = true;
113 113
 
114
-		if ( 0 < count( $orders ) ) {
115
-			foreach ( $orders as $order ) {
114
+		if (0 < count($orders)) {
115
+			foreach ($orders as $order) {
116 116
 				$data_to_export[] = array(
117 117
 					'group_id'    => 'woocommerce_orders',
118
-					'group_label' => __( 'Orders', 'woocommerce-gateway-stripe' ),
118
+					'group_label' => __('Orders', 'woocommerce-gateway-stripe'),
119 119
 					'item_id'     => 'order-' . $order->get_id(),
120 120
 					'data'        => array(
121 121
 						array(
122
-							'name'  => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ),
123
-							'value' => get_post_meta( $order->get_id(), '_stripe_source_id', true ),
122
+							'name'  => __('Stripe payment id', 'woocommerce-gateway-stripe'),
123
+							'value' => get_post_meta($order->get_id(), '_stripe_source_id', true),
124 124
 						),
125 125
 						array(
126
-							'name'  => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ),
127
-							'value' => get_post_meta( $order->get_id(), '_stripe_customer_id', true ),
126
+							'name'  => __('Stripe customer id', 'woocommerce-gateway-stripe'),
127
+							'value' => get_post_meta($order->get_id(), '_stripe_customer_id', true),
128 128
 						),
129 129
 					),
130 130
 				);
131 131
 			}
132 132
 
133
-			$done = 10 > count( $orders );
133
+			$done = 10 > count($orders);
134 134
 		}
135 135
 
136 136
 		return array(
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 *
148 148
 	 * @return array
149 149
 	 */
150
-	public function subscriptions_data_exporter( $email_address, $page = 1 ) {
150
+	public function subscriptions_data_exporter($email_address, $page = 1) {
151 151
 		$done           = false;
152 152
 		$page           = (int) $page;
153 153
 		$data_to_export = array();
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 			'relation' => 'AND',
157 157
 			array(
158 158
 				'key'     => '_payment_method',
159
-				'value'   => array( 'stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort' ),
159
+				'value'   => array('stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort'),
160 160
 				'compare' => 'IN',
161 161
 			),
162 162
 			array(
@@ -172,30 +172,30 @@  discard block
 block discarded – undo
172 172
 			'meta_query'     => $meta_query,
173 173
 		);
174 174
 
175
-		$subscriptions = wcs_get_subscriptions( $subscription_query );
175
+		$subscriptions = wcs_get_subscriptions($subscription_query);
176 176
 
177 177
 		$done = true;
178 178
 
179
-		if ( 0 < count( $subscriptions ) ) {
180
-			foreach ( $subscriptions as $subscription ) {
179
+		if (0 < count($subscriptions)) {
180
+			foreach ($subscriptions as $subscription) {
181 181
 				$data_to_export[] = array(
182 182
 					'group_id'    => 'woocommerce_subscriptions',
183
-					'group_label' => __( 'Subscriptions', 'woocommerce-gateway-stripe' ),
183
+					'group_label' => __('Subscriptions', 'woocommerce-gateway-stripe'),
184 184
 					'item_id'     => 'subscription-' . $subscription->get_id(),
185 185
 					'data'        => array(
186 186
 						array(
187
-							'name'  => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ),
188
-							'value' => get_post_meta( $subscription->get_id(), '_stripe_source_id', true ),
187
+							'name'  => __('Stripe payment id', 'woocommerce-gateway-stripe'),
188
+							'value' => get_post_meta($subscription->get_id(), '_stripe_source_id', true),
189 189
 						),
190 190
 						array(
191
-							'name'  => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ),
192
-							'value' => get_post_meta( $subscription->get_id(), '_stripe_customer_id', true ),
191
+							'name'  => __('Stripe customer id', 'woocommerce-gateway-stripe'),
192
+							'value' => get_post_meta($subscription->get_id(), '_stripe_customer_id', true),
193 193
 						),
194 194
 					),
195 195
 				);
196 196
 			}
197 197
 
198
-			$done = 10 > count( $subscriptions );
198
+			$done = 10 > count($subscriptions);
199 199
 		}
200 200
 
201 201
 		return array(
@@ -211,24 +211,24 @@  discard block
 block discarded – undo
211 211
 	 * @param int    $page  Page.
212 212
 	 * @return array An array of personal data in name value pairs
213 213
 	 */
214
-	public function customer_data_exporter( $email_address, $page ) {
215
-		$user           = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
214
+	public function customer_data_exporter($email_address, $page) {
215
+		$user           = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data.
216 216
 		$data_to_export = array();
217 217
 
218
-		if ( $user instanceof WP_User ) {
219
-			$stripe_user = new WC_Stripe_Customer( $user->ID );
218
+		if ($user instanceof WP_User) {
219
+			$stripe_user = new WC_Stripe_Customer($user->ID);
220 220
 
221 221
 			$data_to_export[] = array(
222 222
 				'group_id'    => 'woocommerce_customer',
223
-				'group_label' => __( 'Customer Data', 'woocommerce-gateway-stripe' ),
223
+				'group_label' => __('Customer Data', 'woocommerce-gateway-stripe'),
224 224
 				'item_id'     => 'user',
225 225
 				'data'        => array(
226 226
 					array(
227
-						'name'  => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ),
228
-						'value' => get_user_option( '_stripe_source_id', $user->ID ),
227
+						'name'  => __('Stripe payment id', 'woocommerce-gateway-stripe'),
228
+						'value' => get_user_option('_stripe_source_id', $user->ID),
229 229
 					),
230 230
 					array(
231
-						'name'  => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ),
231
+						'name'  => __('Stripe customer id', 'woocommerce-gateway-stripe'),
232 232
 						'value' => $stripe_user->get_id(),
233 233
 					),
234 234
 				),
@@ -248,25 +248,25 @@  discard block
 block discarded – undo
248 248
 	 * @param int    $page  Page.
249 249
 	 * @return array An array of personal data in name value pairs
250 250
 	 */
251
-	public function customer_data_eraser( $email_address, $page ) {
251
+	public function customer_data_eraser($email_address, $page) {
252 252
 		$page               = (int) $page;
253
-		$user               = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
253
+		$user               = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data.
254 254
 		$stripe_customer_id = '';
255 255
 		$stripe_source_id   = '';
256 256
 
257
-		if ( $user instanceof WP_User ) {
258
-			$stripe_customer_id = get_user_option( '_stripe_customer_id', $user->ID );
259
-			$stripe_source_id   = get_user_option( '_stripe_source_id', $user->ID );
257
+		if ($user instanceof WP_User) {
258
+			$stripe_customer_id = get_user_option('_stripe_customer_id', $user->ID);
259
+			$stripe_source_id   = get_user_option('_stripe_source_id', $user->ID);
260 260
 		}
261 261
 
262 262
 		$items_removed = false;
263 263
 		$messages      = array();
264 264
 
265
-		if ( ! empty( $stripe_customer_id ) || ! empty( $stripe_source_id ) ) {
265
+		if ( ! empty($stripe_customer_id) || ! empty($stripe_source_id)) {
266 266
 			$items_removed = true;
267
-			delete_user_option( $user->ID, '_stripe_customer_id' );
268
-			delete_user_option( $user->ID, '_stripe_source_id' );
269
-			$messages[] = __( 'Stripe User Data Erased.', 'woocommerce-gateway-stripe' );
267
+			delete_user_option($user->ID, '_stripe_customer_id');
268
+			delete_user_option($user->ID, '_stripe_source_id');
269
+			$messages[] = __('Stripe User Data Erased.', 'woocommerce-gateway-stripe');
270 270
 		}
271 271
 
272 272
 		return array(
@@ -284,29 +284,29 @@  discard block
 block discarded – undo
284 284
 	 * @param int    $page  Page.
285 285
 	 * @return array An array of personal data in name value pairs
286 286
 	 */
287
-	public function order_data_eraser( $email_address, $page ) {
288
-		$orders = $this->get_stripe_orders( $email_address, (int) $page );
287
+	public function order_data_eraser($email_address, $page) {
288
+		$orders = $this->get_stripe_orders($email_address, (int) $page);
289 289
 
290 290
 		$items_removed  = false;
291 291
 		$items_retained = false;
292 292
 		$messages       = array();
293 293
 
294
-		foreach ( (array) $orders as $order ) {
295
-			$order = wc_get_order( $order->get_id() );
294
+		foreach ((array) $orders as $order) {
295
+			$order = wc_get_order($order->get_id());
296 296
 
297
-			list( $removed, $retained, $msgs ) = $this->maybe_handle_order( $order );
297
+			list($removed, $retained, $msgs) = $this->maybe_handle_order($order);
298 298
 			$items_removed                    |= $removed;
299 299
 			$items_retained                   |= $retained;
300
-			$messages                          = array_merge( $messages, $msgs );
300
+			$messages                          = array_merge($messages, $msgs);
301 301
 
302
-			list( $removed, $retained, $msgs ) = $this->maybe_handle_subscription( $order );
302
+			list($removed, $retained, $msgs) = $this->maybe_handle_subscription($order);
303 303
 			$items_removed                    |= $removed;
304 304
 			$items_retained                   |= $retained;
305
-			$messages                          = array_merge( $messages, $msgs );
305
+			$messages                          = array_merge($messages, $msgs);
306 306
 		}
307 307
 
308 308
 		// Tell core if we have more orders to work on still
309
-		$done = count( $orders ) < 10;
309
+		$done = count($orders) < 10;
310 310
 
311 311
 		return array(
312 312
 			'items_removed'  => $items_removed,
@@ -322,47 +322,47 @@  discard block
 block discarded – undo
322 322
 	 * @param WC_Order $order
323 323
 	 * @return array
324 324
 	 */
325
-	protected function maybe_handle_subscription( $order ) {
326
-		if ( ! class_exists( 'WC_Subscriptions' ) ) {
327
-			return array( false, false, array() );
325
+	protected function maybe_handle_subscription($order) {
326
+		if ( ! class_exists('WC_Subscriptions')) {
327
+			return array(false, false, array());
328 328
 		}
329 329
 
330
-		if ( ! wcs_order_contains_subscription( $order ) ) {
331
-			return array( false, false, array() );
330
+		if ( ! wcs_order_contains_subscription($order)) {
331
+			return array(false, false, array());
332 332
 		}
333 333
 
334
-		$subscription    = current( wcs_get_subscriptions_for_order( $order->get_id() ) );
334
+		$subscription    = current(wcs_get_subscriptions_for_order($order->get_id()));
335 335
 		$subscription_id = $subscription->get_id();
336 336
 
337
-		$stripe_source_id = get_post_meta( $subscription_id, '_stripe_source_id', true );
337
+		$stripe_source_id = get_post_meta($subscription_id, '_stripe_source_id', true);
338 338
 
339
-		if ( empty( $stripe_source_id ) ) {
340
-			return array( false, false, array() );
339
+		if (empty($stripe_source_id)) {
340
+			return array(false, false, array());
341 341
 		}
342 342
 
343
-		if ( ! $this->is_retention_expired( $order->get_date_created()->getTimestamp() ) ) {
343
+		if ( ! $this->is_retention_expired($order->get_date_created()->getTimestamp())) {
344 344
 			/* translators: %d Order ID */
345
-			return array( false, true, array( sprintf( __( 'Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe' ), $order->get_id() ) ) );
345
+			return array(false, true, array(sprintf(__('Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe'), $order->get_id())));
346 346
 		}
347 347
 
348
-		if ( $subscription->has_status( apply_filters( 'wc_stripe_privacy_eraser_subs_statuses', array( 'on-hold', 'active' ) ) ) ) {
348
+		if ($subscription->has_status(apply_filters('wc_stripe_privacy_eraser_subs_statuses', array('on-hold', 'active')))) {
349 349
 			/* translators: %d Order ID */
350
-			return array( false, true, array( sprintf( __( 'Order ID %d contains an active Subscription. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe' ), $order->get_id() ) ) );
350
+			return array(false, true, array(sprintf(__('Order ID %d contains an active Subscription. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe'), $order->get_id())));
351 351
 		}
352 352
 
353
-		$renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders( $order->get_id() );
353
+		$renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders($order->get_id());
354 354
 
355
-		foreach ( $renewal_orders as $renewal_order_id ) {
356
-			delete_post_meta( $renewal_order_id, '_stripe_source_id' );
357
-			delete_post_meta( $renewal_order_id, '_stripe_refund_id' );
358
-			delete_post_meta( $renewal_order_id, '_stripe_customer_id' );
355
+		foreach ($renewal_orders as $renewal_order_id) {
356
+			delete_post_meta($renewal_order_id, '_stripe_source_id');
357
+			delete_post_meta($renewal_order_id, '_stripe_refund_id');
358
+			delete_post_meta($renewal_order_id, '_stripe_customer_id');
359 359
 		}
360 360
 
361
-		delete_post_meta( $subscription_id, '_stripe_source_id' );
362
-		delete_post_meta( $subscription_id, '_stripe_refund_id' );
363
-		delete_post_meta( $subscription_id, '_stripe_customer_id' );
361
+		delete_post_meta($subscription_id, '_stripe_source_id');
362
+		delete_post_meta($subscription_id, '_stripe_refund_id');
363
+		delete_post_meta($subscription_id, '_stripe_customer_id');
364 364
 
365
-		return array( true, false, array( __( 'Stripe Subscription Data Erased.', 'woocommerce-gateway-stripe' ) ) );
365
+		return array(true, false, array(__('Stripe Subscription Data Erased.', 'woocommerce-gateway-stripe')));
366 366
 	}
367 367
 
368 368
 	/**
@@ -371,61 +371,61 @@  discard block
 block discarded – undo
371 371
 	 * @param WC_Order $order
372 372
 	 * @return array
373 373
 	 */
374
-	protected function maybe_handle_order( $order ) {
374
+	protected function maybe_handle_order($order) {
375 375
 		$order_id           = $order->get_id();
376
-		$stripe_source_id   = get_post_meta( $order_id, '_stripe_source_id', true );
377
-		$stripe_refund_id   = get_post_meta( $order_id, '_stripe_refund_id', true );
378
-		$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
376
+		$stripe_source_id   = get_post_meta($order_id, '_stripe_source_id', true);
377
+		$stripe_refund_id   = get_post_meta($order_id, '_stripe_refund_id', true);
378
+		$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
379 379
 
380
-		if ( ! $this->is_retention_expired( $order->get_date_created()->getTimestamp() ) ) {
380
+		if ( ! $this->is_retention_expired($order->get_date_created()->getTimestamp())) {
381 381
 			/* translators: %d Order ID */
382
-			return array( false, true, array( sprintf( __( 'Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe' ), $order->get_id() ) ) );
382
+			return array(false, true, array(sprintf(__('Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe'), $order->get_id())));
383 383
 		}
384 384
 
385
-		if ( empty( $stripe_source_id ) && empty( $stripe_refund_id ) && empty( $stripe_customer_id ) ) {
386
-			return array( false, false, array() );
385
+		if (empty($stripe_source_id) && empty($stripe_refund_id) && empty($stripe_customer_id)) {
386
+			return array(false, false, array());
387 387
 		}
388 388
 
389
-		delete_post_meta( $order_id, '_stripe_source_id' );
390
-		delete_post_meta( $order_id, '_stripe_refund_id' );
391
-		delete_post_meta( $order_id, '_stripe_customer_id' );
389
+		delete_post_meta($order_id, '_stripe_source_id');
390
+		delete_post_meta($order_id, '_stripe_refund_id');
391
+		delete_post_meta($order_id, '_stripe_customer_id');
392 392
 
393
-		return array( true, false, array( __( 'Stripe personal data erased.', 'woocommerce-gateway-stripe' ) ) );
393
+		return array(true, false, array(__('Stripe personal data erased.', 'woocommerce-gateway-stripe')));
394 394
 	}
395 395
 
396 396
 	/**
397 397
 	 * Checks if create date is passed retention duration.
398 398
 	 *
399 399
 	 */
400
-	public function is_retention_expired( $created_date ) {
401
-		$retention  = wc_parse_relative_date_option( get_option( 'woocommerce_gateway_stripe_retention' ) );
400
+	public function is_retention_expired($created_date) {
401
+		$retention  = wc_parse_relative_date_option(get_option('woocommerce_gateway_stripe_retention'));
402 402
 		$is_expired = false;
403
-		$time_span  = time() - strtotime( $created_date );
404
-		if ( empty( $retention ) || empty( $created_date ) ) {
403
+		$time_span  = time() - strtotime($created_date);
404
+		if (empty($retention) || empty($created_date)) {
405 405
 			return false;
406 406
 		}
407
-		switch ( $retention['unit'] ) {
407
+		switch ($retention['unit']) {
408 408
 			case 'days':
409 409
 				$retention = $retention['number'] * DAY_IN_SECONDS;
410
-				if ( $time_span > $retention ) {
410
+				if ($time_span > $retention) {
411 411
 					$is_expired = true;
412 412
 				}
413 413
 				break;
414 414
 			case 'weeks':
415 415
 				$retention = $retention['number'] * WEEK_IN_SECONDS;
416
-				if ( $time_span > $retention ) {
416
+				if ($time_span > $retention) {
417 417
 					$is_expired = true;
418 418
 				}
419 419
 				break;
420 420
 			case 'months':
421 421
 				$retention = $retention['number'] * MONTH_IN_SECONDS;
422
-				if ( $time_span > $retention ) {
422
+				if ($time_span > $retention) {
423 423
 					$is_expired = true;
424 424
 				}
425 425
 				break;
426 426
 			case 'years':
427 427
 				$retention = $retention['number'] * YEAR_IN_SECONDS;
428
-				if ( $time_span > $retention ) {
428
+				if ($time_span > $retention) {
429 429
 					$is_expired = true;
430 430
 				}
431 431
 				break;
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
@@ -246,45 +246,45 @@  discard block
 block discarded – undo
246 246
 	 */
247 247
 	public function payment_fields() {
248 248
 		$total                = WC()->cart->total;
249
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
249
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
250 250
 		$description          = $this->get_description();
251
-		$description          = ! empty( $description ) ? $description : '';
251
+		$description          = ! empty($description) ? $description : '';
252 252
 
253 253
 		// If paying from order, we need to get total from order not cart.
254
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
255
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
254
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
255
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
256 256
 			$total = $order->get_total();
257 257
 		}
258 258
 
259
-		if ( is_add_payment_method_page() ) {
259
+		if (is_add_payment_method_page()) {
260 260
 			$total = '';
261 261
 		}
262 262
 
263 263
 		echo '<div
264 264
 			id="stripe-sepa_debit-payment-data"
265
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
266
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
265
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
266
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
267 267
 
268
-		if ( $this->testmode ) {
269
-			$description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
268
+		if ($this->testmode) {
269
+			$description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
270 270
 		}
271 271
 
272
-		$description = trim( $description );
272
+		$description = trim($description);
273 273
 
274
-		echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
274
+		echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
275 275
 
276
-		if ( $display_tokenization ) {
276
+		if ($display_tokenization) {
277 277
 			$this->tokenization_script();
278 278
 			$this->saved_payment_methods();
279 279
 		}
280 280
 
281 281
 		$this->form();
282 282
 
283
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
283
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
284 284
 			$this->save_payment_method_checkbox();
285 285
 		}
286 286
 
287
-		do_action( 'wc_stripe_sepa_payment_fields', $this->id );
287
+		do_action('wc_stripe_sepa_payment_fields', $this->id);
288 288
 
289 289
 		echo '</div>';
290 290
 	}
@@ -300,99 +300,99 @@  discard block
 block discarded – undo
300 300
 	 *
301 301
 	 * @return array|void
302 302
 	 */
303
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
303
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
304 304
 		try {
305
-			$order = wc_get_order( $order_id );
305
+			$order = wc_get_order($order_id);
306 306
 
307
-			if ( $this->maybe_process_pre_orders( $order_id ) ) {
308
-				return $this->pre_orders->process_pre_order( $order_id );
307
+			if ($this->maybe_process_pre_orders($order_id)) {
308
+				return $this->pre_orders->process_pre_order($order_id);
309 309
 			}
310 310
 
311 311
 			// This comes from the create account checkbox in the checkout page.
312
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
312
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
313 313
 
314
-			if ( $create_account ) {
315
-				$new_customer_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id();
316
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
314
+			if ($create_account) {
315
+				$new_customer_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id();
316
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
317 317
 				$new_stripe_customer->create_customer();
318 318
 			}
319 319
 
320
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
320
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
321 321
 
322
-			$this->save_source_to_order( $order, $prepared_source );
322
+			$this->save_source_to_order($order, $prepared_source);
323 323
 
324 324
 			// Result from Stripe API request.
325 325
 			$response = null;
326 326
 
327
-			if ( $order->get_total() > 0 ) {
327
+			if ($order->get_total() > 0) {
328 328
 				// This will throw exception if not valid.
329
-				$this->validate_minimum_order_amount( $order );
329
+				$this->validate_minimum_order_amount($order);
330 330
 
331
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
331
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
332 332
 
333 333
 				// Make the request.
334
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
334
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
335 335
 
336
-				if ( ! empty( $response->error ) ) {
336
+				if ( ! empty($response->error)) {
337 337
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
338
-					if ( $this->is_no_such_customer_error( $response->error ) ) {
339
-						if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
340
-							delete_user_option( $order->customer_user, '_stripe_customer_id' );
341
-							delete_post_meta( $order_id, '_stripe_customer_id' );
338
+					if ($this->is_no_such_customer_error($response->error)) {
339
+						if (WC_Stripe_Helper::is_wc_lt('3.0')) {
340
+							delete_user_option($order->customer_user, '_stripe_customer_id');
341
+							delete_post_meta($order_id, '_stripe_customer_id');
342 342
 						} else {
343
-							delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
344
-							$order->delete_meta_data( '_stripe_customer_id' );
343
+							delete_user_option($order->get_customer_id(), '_stripe_customer_id');
344
+							$order->delete_meta_data('_stripe_customer_id');
345 345
 							$order->save();
346 346
 						}
347 347
 					}
348 348
 
349
-					if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
349
+					if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
350 350
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
351
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
351
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
352 352
 						$wc_token->delete();
353
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
354
-						$order->add_order_note( $localized_message );
355
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
353
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
354
+						$order->add_order_note($localized_message);
355
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
356 356
 					}
357 357
 
358 358
 					// We want to retry.
359
-					if ( $this->is_retryable_error( $response->error ) ) {
360
-						if ( $retry ) {
359
+					if ($this->is_retryable_error($response->error)) {
360
+						if ($retry) {
361 361
 							// Don't do anymore retries after this.
362
-							if ( 5 <= $this->retry_interval ) {
362
+							if (5 <= $this->retry_interval) {
363 363
 
364
-								return $this->process_payment( $order_id, false, $force_save_source );
364
+								return $this->process_payment($order_id, false, $force_save_source);
365 365
 							}
366 366
 
367
-							sleep( $this->retry_interval );
367
+							sleep($this->retry_interval);
368 368
 
369 369
 							$this->retry_interval++;
370 370
 
371
-							return $this->process_payment( $order_id, true, $force_save_source );
371
+							return $this->process_payment($order_id, true, $force_save_source);
372 372
 						} else {
373
-							$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
374
-							$order->add_order_note( $localized_message );
375
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
373
+							$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
374
+							$order->add_order_note($localized_message);
375
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
376 376
 						}
377 377
 					}
378 378
 
379 379
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
380 380
 
381
-					if ( 'card_error' === $response->error->type ) {
382
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
381
+					if ('card_error' === $response->error->type) {
382
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
383 383
 					} else {
384
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
384
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
385 385
 					}
386 386
 
387
-					$order->add_order_note( $localized_message );
387
+					$order->add_order_note($localized_message);
388 388
 
389
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
389
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
390 390
 				}
391 391
 
392
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
392
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
393 393
 
394 394
 				// Process valid response.
395
-				$this->process_response( $response, $order );
395
+				$this->process_response($response, $order);
396 396
 			} else {
397 397
 				$order->payment_complete();
398 398
 			}
@@ -403,17 +403,17 @@  discard block
 block discarded – undo
403 403
 			// Return thank you page redirect.
404 404
 			return array(
405 405
 				'result'   => 'success',
406
-				'redirect' => $this->get_return_url( $order ),
406
+				'redirect' => $this->get_return_url($order),
407 407
 			);
408 408
 
409
-		} catch ( WC_Stripe_Exception $e ) {
410
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
411
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
409
+		} catch (WC_Stripe_Exception $e) {
410
+			wc_add_notice($e->getLocalizedMessage(), 'error');
411
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
412 412
 
413
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
413
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
414 414
 
415
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
416
-				$this->send_failed_order_email( $order_id );
415
+			if ($order->has_status(array('pending', 'failed'))) {
416
+				$this->send_failed_order_email($order_id);
417 417
 			}
418 418
 
419 419
 			return array(
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-subs-compat.php 1 patch
Spacing   +160 added lines, -160 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,86 +215,86 @@  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
-				return new WP_Error( 'stripe_error', 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
+				return new WP_Error('stripe_error', 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
 			}
224 224
 
225
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
225
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
226 226
 
227 227
 			// Get source from order
228
-			$prepared_source = $this->prepare_order_source( $renewal_order );
228
+			$prepared_source = $this->prepare_order_source($renewal_order);
229 229
 			$source_object   = $prepared_source->source_object;
230 230
 
231
-			if ( ! $prepared_source->customer ) {
232
-				return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
231
+			if ( ! $prepared_source->customer) {
232
+				return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
233 233
 			}
234 234
 
235
-			WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
235
+			WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
236 236
 
237 237
 			/* If we're doing a retry and source is chargeable, we need to pass
238 238
 			 * a different idempotency key and retry for success.
239 239
 			 */
240
-			if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
241
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
240
+			if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) {
241
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
242 242
 			}
243 243
 
244
-			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 ) ) {
244
+			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)) {
245 245
 				// Passing empty source will charge customer default.
246 246
 				$prepared_source->source = '';
247 247
 			}
248 248
 
249
-			$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
249
+			$request            = $this->generate_payment_request($renewal_order, $prepared_source);
250 250
 			$request['capture'] = 'true';
251
-			$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
252
-			$response           = WC_Stripe_API::request( $request );
251
+			$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
252
+			$response           = WC_Stripe_API::request($request);
253 253
 
254
-			if ( ! empty( $response->error ) ) {
254
+			if ( ! empty($response->error)) {
255 255
 				// We want to retry.
256
-				if ( $this->is_retryable_error( $response->error ) ) {
257
-					if ( $retry ) {
256
+				if ($this->is_retryable_error($response->error)) {
257
+					if ($retry) {
258 258
 						// Don't do anymore retries after this.
259
-						if ( 5 <= $this->retry_interval ) {
260
-							return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error );
259
+						if (5 <= $this->retry_interval) {
260
+							return $this->process_subscription_payment($amount, $renewal_order, false, $response->error);
261 261
 						}
262 262
 
263
-						sleep( $this->retry_interval );
263
+						sleep($this->retry_interval);
264 264
 
265 265
 						$this->retry_interval++;
266 266
 
267
-						return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error );
267
+						return $this->process_subscription_payment($amount, $renewal_order, true, $response->error);
268 268
 					} else {
269
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
270
-						$renewal_order->add_order_note( $localized_message );
271
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
269
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
270
+						$renewal_order->add_order_note($localized_message);
271
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
272 272
 					}
273 273
 				}
274 274
 
275 275
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
276 276
 
277
-				if ( 'card_error' === $response->error->type ) {
278
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
277
+				if ('card_error' === $response->error->type) {
278
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
279 279
 				} else {
280
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
280
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
281 281
 				}
282 282
 
283
-				$renewal_order->add_order_note( $localized_message );
283
+				$renewal_order->add_order_note($localized_message);
284 284
 
285
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
285
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
286 286
 			}
287 287
 
288
-			do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order );
288
+			do_action('wc_gateway_stripe_process_payment', $response, $renewal_order);
289 289
 
290
-			$this->process_response( $response, $renewal_order );
291
-		} catch ( WC_Stripe_Exception $e ) {
292
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
290
+			$this->process_response($response, $renewal_order);
291
+		} catch (WC_Stripe_Exception $e) {
292
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
293 293
 
294
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order );
294
+			do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order);
295 295
 
296 296
 			/* translators: error message */
297
-			$renewal_order->update_status( 'failed' );
297
+			$renewal_order->update_status('failed');
298 298
 		}
299 299
 	}
300 300
 
@@ -302,21 +302,21 @@  discard block
 block discarded – undo
302 302
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
303 303
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
304 304
 	 */
305
-	public function delete_resubscribe_meta( $resubscribe_order ) {
306
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
307
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
305
+	public function delete_resubscribe_meta($resubscribe_order) {
306
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
307
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
308 308
 		// For BW compat will remove in future
309
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
310
-		$this->delete_renewal_meta( $resubscribe_order );
309
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
310
+		$this->delete_renewal_meta($resubscribe_order);
311 311
 	}
312 312
 
313 313
 	/**
314 314
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
315 315
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
316 316
 	 */
317
-	public function delete_renewal_meta( $renewal_order ) {
318
-		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
319
-		WC_Stripe_Helper::delete_stripe_net( $renewal_order );
317
+	public function delete_renewal_meta($renewal_order) {
318
+		WC_Stripe_Helper::delete_stripe_fee($renewal_order);
319
+		WC_Stripe_Helper::delete_stripe_net($renewal_order);
320 320
 
321 321
 		return $renewal_order;
322 322
 	}
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
331 331
 	 * @return void
332 332
 	 */
333
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
334
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
335
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
336
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
333
+	public function update_failing_payment_method($subscription, $renewal_order) {
334
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
335
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
336
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
337 337
 
338 338
 		} else {
339
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
340
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
339
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
340
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
341 341
 		}
342 342
 	}
343 343
 
@@ -350,21 +350,21 @@  discard block
 block discarded – undo
350 350
 	 * @param WC_Subscription $subscription An instance of a subscription object
351 351
 	 * @return array
352 352
 	 */
353
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
354
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
353
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
354
+		$source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
355 355
 
356 356
 		// For BW compat will remove in future.
357
-		if ( empty( $source_id ) ) {
358
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
357
+		if (empty($source_id)) {
358
+			$source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
359 359
 
360 360
 			// Take this opportunity to update the key name.
361
-			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 );
361
+			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);
362 362
 		}
363 363
 
364
-		$payment_meta[ $this->id ] = array(
364
+		$payment_meta[$this->id] = array(
365 365
 			'post_meta' => array(
366 366
 				'_stripe_customer_id' => array(
367
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
367
+					'value' => get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
368 368
 					'label' => 'Stripe Customer ID',
369 369
 				),
370 370
 				'_stripe_source_id'   => array(
@@ -385,22 +385,22 @@  discard block
 block discarded – undo
385 385
 	 * @param array $payment_meta associative array of meta data required for automatic payments
386 386
 	 * @return array
387 387
 	 */
388
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
389
-		if ( $this->id === $payment_method_id ) {
388
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
389
+		if ($this->id === $payment_method_id) {
390 390
 
391
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
392
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
393
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
394
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
391
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
392
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
393
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
394
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
395 395
 			}
396 396
 
397 397
 			if (
398
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
399
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
400
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
401
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
398
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
399
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
400
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
401
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
402 402
 
403
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
403
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
404 404
 			}
405 405
 		}
406 406
 	}
@@ -413,67 +413,67 @@  discard block
 block discarded – undo
413 413
 	 * @param WC_Subscription $subscription the subscription details
414 414
 	 * @return string the subscription payment method
415 415
 	 */
416
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
417
-		$customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id();
416
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
417
+		$customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id();
418 418
 
419 419
 		// bail for other payment methods
420
-		if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
420
+		if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
421 421
 			return $payment_method_to_display;
422 422
 		}
423 423
 
424
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
424
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
425 425
 
426 426
 		// For BW compat will remove in future.
427
-		if ( empty( $stripe_source_id ) ) {
428
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
427
+		if (empty($stripe_source_id)) {
428
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
429 429
 
430 430
 			// Take this opportunity to update the key name.
431
-			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 );
431
+			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);
432 432
 		}
433 433
 
434 434
 		$stripe_customer    = new WC_Stripe_Customer();
435
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
435
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
436 436
 
437 437
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
438
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
438
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
439 439
 			$user_id            = $customer_user;
440
-			$stripe_customer_id = get_user_option( '_stripe_customer_id', $user_id );
441
-			$stripe_source_id   = get_user_option( '_stripe_source_id', $user_id );
440
+			$stripe_customer_id = get_user_option('_stripe_customer_id', $user_id);
441
+			$stripe_source_id   = get_user_option('_stripe_source_id', $user_id);
442 442
 
443 443
 			// For BW compat will remove in future.
444
-			if ( empty( $stripe_source_id ) ) {
445
-				$stripe_source_id = get_user_option( '_stripe_card_id', $user_id );
444
+			if (empty($stripe_source_id)) {
445
+				$stripe_source_id = get_user_option('_stripe_card_id', $user_id);
446 446
 
447 447
 				// Take this opportunity to update the key name.
448
-				update_user_option( $user_id, '_stripe_source_id', $stripe_source_id, false );
448
+				update_user_option($user_id, '_stripe_source_id', $stripe_source_id, false);
449 449
 			}
450 450
 		}
451 451
 
452 452
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
453
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
454
-			$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 );
455
-			$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 );
453
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
454
+			$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);
455
+			$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);
456 456
 
457 457
 			// For BW compat will remove in future.
458
-			if ( empty( $stripe_source_id ) ) {
459
-				$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 );
458
+			if (empty($stripe_source_id)) {
459
+				$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);
460 460
 
461 461
 				// Take this opportunity to update the key name.
462
-				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 );
462
+				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);
463 463
 			}
464 464
 		}
465 465
 
466
-		$stripe_customer->set_id( $stripe_customer_id );
466
+		$stripe_customer->set_id($stripe_customer_id);
467 467
 
468 468
 		$sources                   = $stripe_customer->get_sources();
469
-		$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
469
+		$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
470 470
 
471
-		if ( $sources ) {
472
-			foreach ( $sources as $source ) {
473
-				if ( $source->id === $stripe_source_id ) {
474
-					if ( $source->sepa_debit ) {
471
+		if ($sources) {
472
+			foreach ($sources as $source) {
473
+				if ($source->id === $stripe_source_id) {
474
+					if ($source->sepa_debit) {
475 475
 						/* translators: 1) last 4 digits of SEPA Direct Debit */
476
-						$payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 );
476
+						$payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4);
477 477
 					}
478 478
 
479 479
 					break;
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-subs-compat.php 1 patch
Spacing   +210 added lines, -210 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,146 +217,146 @@  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
-				return new WP_Error( 'stripe_error', 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
+				return new WP_Error('stripe_error', 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
 			}
226 226
 
227
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
227
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
228 228
 
229 229
 
230 230
 			// Unlike regular off-session subscription payments, early renewals are treated as on-session payments, involving the customer.
231
-			if ( isset( $_REQUEST['process_early_renewal'] ) ) { // wpcs: csrf ok.
232
-				$response = parent::process_payment( $order_id, true, false, $previous_error, true );
231
+			if (isset($_REQUEST['process_early_renewal'])) { // wpcs: csrf ok.
232
+				$response = parent::process_payment($order_id, true, false, $previous_error, true);
233 233
 
234
-				if( 'success' === $response['result'] && isset( $response['payment_intent_secret'] ) ) {
234
+				if ('success' === $response['result'] && isset($response['payment_intent_secret'])) {
235 235
 					$verification_url = add_query_arg(
236 236
 						array(
237 237
 							'order'         => $order_id,
238
-							'nonce'         => wp_create_nonce( 'wc_stripe_confirm_pi' ),
239
-							'redirect_to'   => remove_query_arg( array( 'process_early_renewal', 'subscription_id', 'wcs_nonce' ) ),
238
+							'nonce'         => wp_create_nonce('wc_stripe_confirm_pi'),
239
+							'redirect_to'   => remove_query_arg(array('process_early_renewal', 'subscription_id', 'wcs_nonce')),
240 240
 							'early_renewal' => true,
241 241
 						),
242
-						WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' )
242
+						WC_AJAX::get_endpoint('wc_stripe_verify_intent')
243 243
 					);
244 244
 
245
-					echo wp_json_encode( array(
245
+					echo wp_json_encode(array(
246 246
 						'stripe_sca_required' => true,
247 247
 						'intent_secret'       => $response['payment_intent_secret'],
248 248
 						'redirect_url'        => $verification_url,
249
-					) );
249
+					));
250 250
 
251 251
 					exit;
252 252
 				}
253 253
 
254 254
 				// Hijack all other redirects in order to do the redirection in JavaScript.
255
-				add_action( 'wp_redirect', array( $this, 'redirect_after_early_renewal' ), 100 );
255
+				add_action('wp_redirect', array($this, 'redirect_after_early_renewal'), 100);
256 256
 
257 257
 				return;
258 258
 			}
259 259
 
260 260
 			// Check for an existing intent, which is associated with the order.
261
-			if ( $this->has_authentication_already_failed( $renewal_order ) ) {
261
+			if ($this->has_authentication_already_failed($renewal_order)) {
262 262
 				return;
263 263
 			}
264 264
 
265 265
 			// Get source from order
266
-			$prepared_source = $this->prepare_order_source( $renewal_order );
266
+			$prepared_source = $this->prepare_order_source($renewal_order);
267 267
 			$source_object   = $prepared_source->source_object;
268 268
 
269
-			if ( ! $prepared_source->customer ) {
270
-				return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
269
+			if ( ! $prepared_source->customer) {
270
+				return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
271 271
 			}
272 272
 
273
-			WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
273
+			WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
274 274
 
275 275
 			/* If we're doing a retry and source is chargeable, we need to pass
276 276
 			 * a different idempotency key and retry for success.
277 277
 			 */
278
-			if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
279
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
278
+			if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) {
279
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
280 280
 			}
281 281
 
282
-			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 ) ) {
282
+			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)) {
283 283
 				// Passing empty source will charge customer default.
284 284
 				$prepared_source->source = '';
285 285
 			}
286 286
 
287
-			$this->lock_order_payment( $renewal_order );
287
+			$this->lock_order_payment($renewal_order);
288 288
 
289
-			$response                   = $this->create_and_confirm_intent_for_off_session( $renewal_order, $prepared_source, $amount );
290
-			$is_authentication_required = $this->is_authentication_required_for_payment( $response );
289
+			$response                   = $this->create_and_confirm_intent_for_off_session($renewal_order, $prepared_source, $amount);
290
+			$is_authentication_required = $this->is_authentication_required_for_payment($response);
291 291
 
292 292
 			// It's only a failed payment if it's an error and it's not of the type 'authentication_required'.
293 293
 			// If it's 'authentication_required', then we should email the user and ask them to authenticate.
294
-			if ( ! empty( $response->error ) && ! $is_authentication_required ) {
294
+			if ( ! empty($response->error) && ! $is_authentication_required) {
295 295
 				// We want to retry.
296
-				if ( $this->is_retryable_error( $response->error ) ) {
297
-					if ( $retry ) {
296
+				if ($this->is_retryable_error($response->error)) {
297
+					if ($retry) {
298 298
 						// Don't do anymore retries after this.
299
-						if ( 5 <= $this->retry_interval ) {
300
-							return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error );
299
+						if (5 <= $this->retry_interval) {
300
+							return $this->process_subscription_payment($amount, $renewal_order, false, $response->error);
301 301
 						}
302 302
 
303
-						sleep( $this->retry_interval );
303
+						sleep($this->retry_interval);
304 304
 
305 305
 						$this->retry_interval++;
306 306
 
307
-						return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error );
307
+						return $this->process_subscription_payment($amount, $renewal_order, true, $response->error);
308 308
 					} else {
309
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
310
-						$renewal_order->add_order_note( $localized_message );
311
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
309
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
310
+						$renewal_order->add_order_note($localized_message);
311
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
312 312
 					}
313 313
 				}
314 314
 
315 315
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
316 316
 
317
-				if ( 'card_error' === $response->error->type ) {
318
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
317
+				if ('card_error' === $response->error->type) {
318
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
319 319
 				} else {
320
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
320
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
321 321
 				}
322 322
 
323
-				$renewal_order->add_order_note( $localized_message );
323
+				$renewal_order->add_order_note($localized_message);
324 324
 
325
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
325
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
326 326
 			}
327 327
 
328 328
 			// Either the charge was successfully captured, or it requires further authentication.
329 329
 
330
-			if ( $is_authentication_required ) {
331
-				do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response );
330
+			if ($is_authentication_required) {
331
+				do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response);
332 332
 
333
-				$error_message = __( 'This transaction requires authentication.', 'woocommerce-gateway-stripe' );
334
-				$renewal_order->add_order_note( $error_message );
333
+				$error_message = __('This transaction requires authentication.', 'woocommerce-gateway-stripe');
334
+				$renewal_order->add_order_note($error_message);
335 335
 
336
-				$charge = end( $response->error->payment_intent->charges->data );
336
+				$charge = end($response->error->payment_intent->charges->data);
337 337
 				$id = $charge->id;
338
-				$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
338
+				$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
339 339
 
340
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $id ) : $renewal_order->set_transaction_id( $id );
341
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $id ) );
342
-				if ( is_callable( array( $renewal_order, 'save' ) ) ) {
340
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $id) : $renewal_order->set_transaction_id($id);
341
+				$renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $id));
342
+				if (is_callable(array($renewal_order, 'save'))) {
343 343
 					$renewal_order->save();
344 344
 				}
345 345
 			} else {
346 346
 				// The charge was successfully captured
347
-				do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order );
347
+				do_action('wc_gateway_stripe_process_payment', $response, $renewal_order);
348 348
 
349
-				$this->process_response( end( $response->charges->data ), $renewal_order );
349
+				$this->process_response(end($response->charges->data), $renewal_order);
350 350
 			}
351 351
 
352
-			$this->unlock_order_payment( $renewal_order );
353
-		} catch ( WC_Stripe_Exception $e ) {
354
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
352
+			$this->unlock_order_payment($renewal_order);
353
+		} catch (WC_Stripe_Exception $e) {
354
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
355 355
 
356
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order );
356
+			do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order);
357 357
 
358 358
 			/* translators: error message */
359
-			$renewal_order->update_status( 'failed' );
359
+			$renewal_order->update_status('failed');
360 360
 		}
361 361
 	}
362 362
 
@@ -366,24 +366,24 @@  discard block
 block discarded – undo
366 366
 	 * @since 3.1.0
367 367
 	 * @version 4.0.0
368 368
 	 */
369
-	public function save_source_to_order( $order, $source ) {
370
-		parent::save_source_to_order( $order, $source );
369
+	public function save_source_to_order($order, $source) {
370
+		parent::save_source_to_order($order, $source);
371 371
 
372
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
372
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
373 373
 
374 374
 		// Also store it on the subscriptions being purchased or paid for in the order
375
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
376
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
377
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
378
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
375
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
376
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
377
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
378
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
379 379
 		} else {
380 380
 			$subscriptions = array();
381 381
 		}
382 382
 
383
-		foreach ( $subscriptions as $subscription ) {
384
-			$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
385
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
386
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
383
+		foreach ($subscriptions as $subscription) {
384
+			$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
385
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
386
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
387 387
 		}
388 388
 	}
389 389
 
@@ -391,26 +391,26 @@  discard block
 block discarded – undo
391 391
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
392 392
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
393 393
 	 */
394
-	public function delete_resubscribe_meta( $resubscribe_order ) {
395
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
396
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
394
+	public function delete_resubscribe_meta($resubscribe_order) {
395
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
396
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
397 397
 		// For BW compat will remove in future
398
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
398
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
399 399
 		// delete payment intent ID
400
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_intent_id' );
401
-		$this->delete_renewal_meta( $resubscribe_order );
400
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_intent_id');
401
+		$this->delete_renewal_meta($resubscribe_order);
402 402
 	}
403 403
 
404 404
 	/**
405 405
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
406 406
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
407 407
 	 */
408
-	public function delete_renewal_meta( $renewal_order ) {
409
-		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
410
-		WC_Stripe_Helper::delete_stripe_net( $renewal_order );
408
+	public function delete_renewal_meta($renewal_order) {
409
+		WC_Stripe_Helper::delete_stripe_fee($renewal_order);
410
+		WC_Stripe_Helper::delete_stripe_net($renewal_order);
411 411
 
412 412
 		// delete payment intent ID
413
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id() ), '_stripe_intent_id' );
413
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id()), '_stripe_intent_id');
414 414
 
415 415
 		return $renewal_order;
416 416
 	}
@@ -424,14 +424,14 @@  discard block
 block discarded – undo
424 424
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
425 425
 	 * @return void
426 426
 	 */
427
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
428
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
429
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
430
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
427
+	public function update_failing_payment_method($subscription, $renewal_order) {
428
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
429
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
430
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
431 431
 
432 432
 		} else {
433
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
434
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
433
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
434
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
435 435
 		}
436 436
 	}
437 437
 
@@ -444,23 +444,23 @@  discard block
 block discarded – undo
444 444
 	 * @param WC_Subscription $subscription An instance of a subscription object
445 445
 	 * @return array
446 446
 	 */
447
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
448
-		$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
449
-		$source_id       = get_post_meta( $subscription_id, '_stripe_source_id', true );
447
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
448
+		$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
449
+		$source_id       = get_post_meta($subscription_id, '_stripe_source_id', true);
450 450
 
451 451
 		// For BW compat will remove in future.
452
-		if ( empty( $source_id ) ) {
453
-			$source_id = get_post_meta( $subscription_id, '_stripe_card_id', true );
452
+		if (empty($source_id)) {
453
+			$source_id = get_post_meta($subscription_id, '_stripe_card_id', true);
454 454
 
455 455
 			// Take this opportunity to update the key name.
456
-			update_post_meta( $subscription_id, '_stripe_source_id', $source_id );
457
-			delete_post_meta( $subscription_id, '_stripe_card_id', $source_id );
456
+			update_post_meta($subscription_id, '_stripe_source_id', $source_id);
457
+			delete_post_meta($subscription_id, '_stripe_card_id', $source_id);
458 458
 		}
459 459
 
460
-		$payment_meta[ $this->id ] = array(
460
+		$payment_meta[$this->id] = array(
461 461
 			'post_meta' => array(
462 462
 				'_stripe_customer_id' => array(
463
-					'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ),
463
+					'value' => get_post_meta($subscription_id, '_stripe_customer_id', true),
464 464
 					'label' => 'Stripe Customer ID',
465 465
 				),
466 466
 				'_stripe_source_id'   => array(
@@ -483,22 +483,22 @@  discard block
 block discarded – undo
483 483
 	 * @param array $payment_meta associative array of meta data required for automatic payments
484 484
 	 * @return array
485 485
 	 */
486
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
487
-		if ( $this->id === $payment_method_id ) {
486
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
487
+		if ($this->id === $payment_method_id) {
488 488
 
489
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
490
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
491
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
492
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
489
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
490
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
491
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
492
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
493 493
 			}
494 494
 
495 495
 			if (
496
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
497
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
498
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
499
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
496
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
497
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
498
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
499
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
500 500
 
501
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
501
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
502 502
 			}
503 503
 		}
504 504
 	}
@@ -511,75 +511,75 @@  discard block
 block discarded – undo
511 511
 	 * @param WC_Subscription $subscription the subscription details
512 512
 	 * @return string the subscription payment method
513 513
 	 */
514
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
515
-		$customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id();
514
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
515
+		$customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id();
516 516
 
517 517
 		// bail for other payment methods
518
-		if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
518
+		if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
519 519
 			return $payment_method_to_display;
520 520
 		}
521 521
 
522
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
522
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
523 523
 
524 524
 		// For BW compat will remove in future.
525
-		if ( empty( $stripe_source_id ) ) {
526
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
525
+		if (empty($stripe_source_id)) {
526
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
527 527
 
528 528
 			// Take this opportunity to update the key name.
529
-			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 );
529
+			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);
530 530
 		}
531 531
 
532 532
 		$stripe_customer    = new WC_Stripe_Customer();
533
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
533
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
534 534
 
535 535
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
536
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
536
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
537 537
 			$user_id            = $customer_user;
538
-			$stripe_customer_id = get_user_option( '_stripe_customer_id', $user_id );
539
-			$stripe_source_id   = get_user_option( '_stripe_source_id', $user_id );
538
+			$stripe_customer_id = get_user_option('_stripe_customer_id', $user_id);
539
+			$stripe_source_id   = get_user_option('_stripe_source_id', $user_id);
540 540
 
541 541
 			// For BW compat will remove in future.
542
-			if ( empty( $stripe_source_id ) ) {
543
-				$stripe_source_id = get_user_option( '_stripe_card_id', $user_id );
542
+			if (empty($stripe_source_id)) {
543
+				$stripe_source_id = get_user_option('_stripe_card_id', $user_id);
544 544
 
545 545
 				// Take this opportunity to update the key name.
546
-				update_user_option( $user_id, '_stripe_source_id', $stripe_source_id, false );
546
+				update_user_option($user_id, '_stripe_source_id', $stripe_source_id, false);
547 547
 			}
548 548
 		}
549 549
 
550 550
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
551
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
552
-			$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 );
553
-			$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 );
551
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
552
+			$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);
553
+			$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);
554 554
 
555 555
 			// For BW compat will remove in future.
556
-			if ( empty( $stripe_source_id ) ) {
557
-				$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 );
556
+			if (empty($stripe_source_id)) {
557
+				$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);
558 558
 
559 559
 				// Take this opportunity to update the key name.
560
-				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 );
560
+				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);
561 561
 			}
562 562
 		}
563 563
 
564
-		$stripe_customer->set_id( $stripe_customer_id );
564
+		$stripe_customer->set_id($stripe_customer_id);
565 565
 
566 566
 		$sources                   = $stripe_customer->get_sources();
567
-		$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
567
+		$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
568 568
 
569
-		if ( $sources ) {
569
+		if ($sources) {
570 570
 			$card = false;
571 571
 
572
-			foreach ( $sources as $source ) {
573
-				if ( isset( $source->type ) && 'card' === $source->type ) {
572
+			foreach ($sources as $source) {
573
+				if (isset($source->type) && 'card' === $source->type) {
574 574
 					$card = $source->card;
575
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
575
+				} elseif (isset($source->object) && 'card' === $source->object) {
576 576
 					$card = $source;
577 577
 				}
578 578
 
579
-				if ( $source->id === $stripe_source_id ) {
580
-					if ( $card ) {
579
+				if ($source->id === $stripe_source_id) {
580
+					if ($card) {
581 581
 						/* translators: 1) card brand 2) last 4 digits */
582
-						$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 );
582
+						$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);
583 583
 					}
584 584
 
585 585
 					break;
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 	 */
597 597
 	public function remove_order_pay_var() {
598 598
 		global $wp;
599
-		if ( isset( $_GET['wc-stripe-confirmation'] ) ) {
599
+		if (isset($_GET['wc-stripe-confirmation'])) {
600 600
 			$this->order_pay_var = $wp->query_vars['order-pay'];
601 601
 			$wp->query_vars['order-pay'] = null;
602 602
 		}
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 	 */
608 608
 	public function restore_order_pay_var() {
609 609
 		global $wp;
610
-		if ( isset( $this->order_pay_var ) ) {
610
+		if (isset($this->order_pay_var)) {
611 611
 			$wp->query_vars['order-pay'] = $this->order_pay_var;
612 612
 		}
613 613
 	}
@@ -618,13 +618,13 @@  discard block
 block discarded – undo
618 618
 	 * @param WC_Order $renewal_order The renewal order.
619 619
 	 * @return boolean
620 620
 	 */
621
-	public function has_authentication_already_failed( $renewal_order ) {
622
-		$existing_intent = $this->get_intent_from_order( $renewal_order );
621
+	public function has_authentication_already_failed($renewal_order) {
622
+		$existing_intent = $this->get_intent_from_order($renewal_order);
623 623
 
624 624
 		if (
625 625
 			! $existing_intent
626 626
 			|| 'requires_payment_method' !== $existing_intent->status
627
-			|| empty( $existing_intent->last_payment_error )
627
+			|| empty($existing_intent->last_payment_error)
628 628
 			|| 'authentication_required' !== $existing_intent->last_payment_error->code
629 629
 		) {
630 630
 			return false;
@@ -638,12 +638,12 @@  discard block
 block discarded – undo
638 638
 		 *
639 639
 		 * @param WC_Order $renewal_order The order that is being renewed.
640 640
 		 */
641
-		do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order );
641
+		do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order);
642 642
 
643 643
 		// Fail the payment attempt (order would be currently pending because of retry rules).
644
-		$charge    = end( $existing_intent->charges->data );
644
+		$charge    = end($existing_intent->charges->data);
645 645
 		$charge_id = $charge->id;
646
-		$renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $charge_id ) );
646
+		$renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $charge_id));
647 647
 
648 648
 		return true;
649 649
 	}
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	 * @param string $url The URL that Subscriptions attempts a redirect to.
655 655
 	 * @return void
656 656
 	 */
657
-	public function redirect_after_early_renewal( $url ) {
657
+	public function redirect_after_early_renewal($url) {
658 658
 		echo wp_json_encode(
659 659
 			array(
660 660
 				'stripe_sca_required' => false,
@@ -671,12 +671,12 @@  discard block
 block discarded – undo
671 671
 	 * @param WC_Order $order The renewal order.
672 672
 	 * @param stdClass $intent The Payment Intent object.
673 673
 	 */
674
-	protected function handle_intent_verification_success( $order, $intent ) {
675
-		parent::handle_intent_verification_success( $order, $intent );
674
+	protected function handle_intent_verification_success($order, $intent) {
675
+		parent::handle_intent_verification_success($order, $intent);
676 676
 
677
-		if ( isset( $_GET['early_renewal'] ) ) { // wpcs: csrf ok.
678
-			wcs_update_dates_after_early_renewal( wcs_get_subscription( $order->get_meta( '_subscription_renewal' ) ), $order );
679
-			wc_add_notice( __( 'Your early renewal order was successful.', 'woocommerce-gateway-stripe' ), 'success' );
677
+		if (isset($_GET['early_renewal'])) { // wpcs: csrf ok.
678
+			wcs_update_dates_after_early_renewal(wcs_get_subscription($order->get_meta('_subscription_renewal')), $order);
679
+			wc_add_notice(__('Your early renewal order was successful.', 'woocommerce-gateway-stripe'), 'success');
680 680
 		}
681 681
 	}
682 682
 
@@ -686,12 +686,12 @@  discard block
 block discarded – undo
686 686
 	 * @param WC_Order $order The renewal order.
687 687
 	 * @param stdClass $intent The Payment Intent object (unused).
688 688
 	 */
689
-	protected function handle_intent_verification_failure( $order, $intent ) {
690
-		if ( isset( $_GET['early_renewal'] ) ) {
691
-			$order->delete( true );
692
-			wc_add_notice( __( 'Payment authorization for the renewal order was unsuccessful, please try again.', 'woocommerce-gateway-stripe' ), 'error' );
693
-			$renewal_url = wcs_get_early_renewal_url( wcs_get_subscription( $order->get_meta( '_subscription_renewal' ) ) );
694
-			wp_redirect( $renewal_url ); exit;
689
+	protected function handle_intent_verification_failure($order, $intent) {
690
+		if (isset($_GET['early_renewal'])) {
691
+			$order->delete(true);
692
+			wc_add_notice(__('Payment authorization for the renewal order was unsuccessful, please try again.', 'woocommerce-gateway-stripe'), 'error');
693
+			$renewal_url = wcs_get_early_renewal_url(wcs_get_subscription($order->get_meta('_subscription_renewal')));
694
+			wp_redirect($renewal_url); exit;
695 695
 		}
696 696
 	}
697 697
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +107 added lines, -107 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_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_refunded', array( $this, 'cancel_payment' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_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 ( $order->has_status( array( 'processing', 'completed', 'on-hold' ) ) ) {
72
+			if ($order->has_status(array('processing', 'completed', 'on-hold'))) {
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_option( $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_option($order->customer_user, '_stripe_customer_id');
132
+						delete_post_meta($order_id, '_stripe_customer_id');
133 133
 					} else {
134
-						delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
135
-						$order->delete_meta_data( '_stripe_customer_id' );
134
+						delete_user_option($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,32 +222,32 @@  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
-				$intent = $this->get_intent_from_order( $order );
241
-				if ( $intent ) {
240
+				$intent = $this->get_intent_from_order($order);
241
+				if ($intent) {
242 242
 					// If the order has a Payment Intent, then the Intent itself must be captured, not the Charge
243
-					if ( ! empty( $intent->error ) ) {
243
+					if ( ! empty($intent->error)) {
244 244
 						/* translators: error message */
245
-						$order->add_order_note( sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $intent->error->message ) );
246
-					} elseif ( 'requires_capture' === $intent->status ) {
247
-						$level3_data = $this->get_level3_data_from_order( $order );
245
+						$order->add_order_note(sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $intent->error->message));
246
+					} elseif ('requires_capture' === $intent->status) {
247
+						$level3_data = $this->get_level3_data_from_order($order);
248 248
 						$result = WC_Stripe_API::request_with_level3_data(
249 249
 							array(
250
-								'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
250
+								'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
251 251
 								'expand[]' => 'charges.data.balance_transaction',
252 252
 							),
253 253
 							'payment_intents/' . $intent->id . '/capture',
@@ -255,30 +255,30 @@  discard block
 block discarded – undo
255 255
 							$order
256 256
 						);
257 257
 
258
-						if ( ! empty( $result->error ) ) {
258
+						if ( ! empty($result->error)) {
259 259
 							/* translators: error message */
260
-							$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
260
+							$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
261 261
 						} else {
262 262
 							$is_stripe_captured = true;
263
-							$result = end( $result->charges->data );
263
+							$result = end($result->charges->data);
264 264
 						}
265
-					} elseif ( 'succeeded' === $intent->status ) {
265
+					} elseif ('succeeded' === $intent->status) {
266 266
 						$is_stripe_captured = true;
267 267
 					}
268 268
 				} else {
269 269
 					// The order doesn't have a Payment Intent, fall back to capturing the Charge directly
270 270
 
271 271
 					// First retrieve charge to see if it has been captured.
272
-					$result = WC_Stripe_API::retrieve( 'charges/' . $charge );
272
+					$result = WC_Stripe_API::retrieve('charges/' . $charge);
273 273
 
274
-					if ( ! empty( $result->error ) ) {
274
+					if ( ! empty($result->error)) {
275 275
 						/* translators: error message */
276
-						$order->add_order_note( sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
277
-					} elseif ( false === $result->captured ) {
278
-						$level3_data = $this->get_level3_data_from_order( $order );
276
+						$order->add_order_note(sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
277
+					} elseif (false === $result->captured) {
278
+						$level3_data = $this->get_level3_data_from_order($order);
279 279
 						$result = WC_Stripe_API::request_with_level3_data(
280 280
 							array(
281
-								'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
281
+								'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
282 282
 								'expand[]' => 'balance_transaction',
283 283
 							),
284 284
 							'charges/' . $charge . '/capture',
@@ -286,34 +286,34 @@  discard block
 block discarded – undo
286 286
 							$order
287 287
 						);
288 288
 
289
-						if ( ! empty( $result->error ) ) {
289
+						if ( ! empty($result->error)) {
290 290
 							/* translators: error message */
291
-							$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
291
+							$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
292 292
 						} else {
293 293
 							$is_stripe_captured = true;
294 294
 						}
295
-					} elseif ( true === $result->captured ) {
295
+					} elseif (true === $result->captured) {
296 296
 						$is_stripe_captured = true;
297 297
 					}
298 298
 				}
299 299
 
300
-				if ( $is_stripe_captured ) {
300
+				if ($is_stripe_captured) {
301 301
 					/* translators: transaction id */
302
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
303
-					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' );
302
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
303
+					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');
304 304
 
305 305
 					// Store other data such as fees
306
-					WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
306
+					WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
307 307
 
308
-					if ( is_callable( array( $order, 'save' ) ) ) {
308
+					if (is_callable(array($order, 'save'))) {
309 309
 						$order->save();
310 310
 					}
311 311
 
312
-					$this->update_fees( $order, $result->balance_transaction->id );
312
+					$this->update_fees($order, $result->balance_transaction->id);
313 313
 				}
314 314
 
315 315
 				// This hook fires when admin manually changes order status to processing or completed.
316
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
316
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
317 317
 			}
318 318
 		}
319 319
 	}
@@ -325,19 +325,19 @@  discard block
 block discarded – undo
325 325
 	 * @version 4.2.2
326 326
 	 * @param  int $order_id
327 327
 	 */
328
-	public function cancel_payment( $order_id ) {
329
-		$order = wc_get_order( $order_id );
330
-
331
-		if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) {
332
-			$captured = WC_Stripe_Helper::is_wc_lt( '3.0' )
333
-				? get_post_meta( $order_id, '_stripe_charge_captured', true )
334
-				: $order->get_meta( '_stripe_charge_captured', true );
335
-			if ( 'no' === $captured ) {
336
-				$this->process_refund( $order_id );
328
+	public function cancel_payment($order_id) {
329
+		$order = wc_get_order($order_id);
330
+
331
+		if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) {
332
+			$captured = WC_Stripe_Helper::is_wc_lt('3.0')
333
+				? get_post_meta($order_id, '_stripe_charge_captured', true)
334
+				: $order->get_meta('_stripe_charge_captured', true);
335
+			if ('no' === $captured) {
336
+				$this->process_refund($order_id);
337 337
 			}
338 338
 
339 339
 			// This hook fires when admin manually changes order status to cancel.
340
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
340
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
341 341
 		}
342 342
 	}
343 343
 }
Please login to merge, or discard this patch.
tests/phpunit/test-wc-stripe-level-3-data.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -7,26 +7,26 @@  discard block
 block discarded – undo
7 7
 class WC_Stripe_level3_Data_Test extends WP_UnitTestCase {
8 8
 	public function test_data_for_mutli_item_order() {
9 9
 		// Skip this test because of the complexity of creating products in WC pre-3.0.
10
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
10
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
11 11
 			// Dummy assertion.
12
-			$this->assertEquals( WC_Stripe_Helper::is_wc_lt( '3.0' ), true );
12
+			$this->assertEquals(WC_Stripe_Helper::is_wc_lt('3.0'), true);
13 13
 			return;
14 14
 		}
15 15
 
16 16
 		$store_postcode = '90210';
17
-		update_option( 'woocommerce_store_postcode', $store_postcode );
17
+		update_option('woocommerce_store_postcode', $store_postcode);
18 18
 
19 19
 		// Arrange: Create a couple of products to use.
20 20
 		$variation_product = WC_Helper_Product::create_variation_product();
21 21
 		$variation_ids     = $variation_product->get_children();
22 22
 
23
-		$product_1 = wc_get_product ( $variation_ids[0] );
24
-		$product_1->set_regular_price( 19.19 );
25
-		$product_1->set_sale_price( 11.83 );
23
+		$product_1 = wc_get_product($variation_ids[0]);
24
+		$product_1->set_regular_price(19.19);
25
+		$product_1->set_sale_price(11.83);
26 26
 		$product_1->save();
27 27
 
28
-		$product_2 = wc_get_product( $variation_ids[1] );
29
-		$product_2->set_regular_price( 20.05 );
28
+		$product_2 = wc_get_product($variation_ids[1]);
29
+		$product_2->set_regular_price(20.05);
30 30
 		$product_2->save();
31 31
 
32 32
 		// Arrange: Set up an order with:
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
 		// 2) The same product added several times.
35 35
 		// 3) A valid US ZIP code
36 36
 		$order = new WC_Order();
37
-		$order->set_shipping_postcode( '90210' );
38
-		$order->add_product( $product_1, 1 ); // Add one item of the first product variation
39
-		$order->add_product( $product_2, 2 ); // Add two items of the second product variation
37
+		$order->set_shipping_postcode('90210');
38
+		$order->add_product($product_1, 1); // Add one item of the first product variation
39
+		$order->add_product($product_2, 2); // Add two items of the second product variation
40 40
 
41 41
 		$order->save();
42 42
 		$order->calculate_totals();
43 43
 
44 44
 		// Act: Call get_level3_data_from_order().
45 45
 		$gateway = new WC_Gateway_Stripe();
46
-		$result = $gateway->get_level3_data_from_order( $order );
46
+		$result = $gateway->get_level3_data_from_order($order);
47 47
 
48 48
 		// Assert.
49 49
 		$this->assertEquals(
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 				'line_items' => array(
56 56
 					(object) array(
57 57
 						'product_code'        => (string) $product_1->get_id(),
58
-						'product_description' => substr( $product_1->get_name(), 0, 26 ),
58
+						'product_description' => substr($product_1->get_name(), 0, 26),
59 59
 						'unit_cost'           => 1183,
60 60
 						'quantity'            => 1,
61 61
 						'tax_amount'          => 0,
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 					),
64 64
 					(object) array(
65 65
 						'product_code'        => (string) $product_2->get_id(),
66
-						'product_description' => substr( $product_2->get_name(), 0, 26 ),
66
+						'product_description' => substr($product_2->get_name(), 0, 26),
67 67
 						'unit_cost'           => 2005,
68 68
 						'quantity'            => 2,
69 69
 						'tax_amount'          => 0,
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
 		);
76 76
 
77 77
 		// Assert: Check that Stripe's total charge check passes.
78
-		$total_charged = WC_Stripe_Helper::get_stripe_amount( $order->get_total() );
79
-		$sum_of_unit_costs = array_reduce( $result['line_items'], function( $sum, $item ) {
78
+		$total_charged = WC_Stripe_Helper::get_stripe_amount($order->get_total());
79
+		$sum_of_unit_costs = array_reduce($result['line_items'], function($sum, $item) {
80 80
 			return $sum + $item->quantity * $item->unit_cost;
81 81
 		}  );
82
-		$sum_of_taxes = array_reduce( $result['line_items'], function( $sum, $item ) {
82
+		$sum_of_taxes = array_reduce($result['line_items'], function($sum, $item) {
83 83
 			return $sum + $item->tax_amount;
84 84
 		}  );
85
-		$sum_of_discounts = array_reduce( $result['line_items'], function( $sum, $item ) {
85
+		$sum_of_discounts = array_reduce($result['line_items'], function($sum, $item) {
86 86
 			return $sum + $item->discount_amount;
87 87
 		}  );
88 88
 		$shipping_amount = $result['shipping_amount'];
@@ -94,31 +94,31 @@  discard block
 block discarded – undo
94 94
 
95 95
 	public function test_non_us_shipping_zip_codes() {
96 96
 		// Skip this test because of the complexity of creating products in WC pre-3.0.
97
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
97
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
98 98
 			// Dummy assertion.
99
-			$this->assertEquals( WC_Stripe_Helper::is_wc_lt( '3.0' ), true );
99
+			$this->assertEquals(WC_Stripe_Helper::is_wc_lt('3.0'), true);
100 100
 			return;
101 101
 		}
102 102
 
103 103
 		// Update the store with the right post code.
104
-		update_option( 'woocommerce_store_postcode', 1040 );
104
+		update_option('woocommerce_store_postcode', 1040);
105 105
 
106 106
 		// Arrange: Create a couple of products to use.
107 107
 		$product = WC_Helper_Product::create_simple_product();
108
-		$product->set_regular_price( 19.19 );
108
+		$product->set_regular_price(19.19);
109 109
 		$product->save();
110 110
 
111 111
 		// Arrange: Set up an order with a non-US postcode.
112 112
 		$order = new WC_Order();
113
-		$order->set_shipping_postcode( '1050' );
114
-		$order->add_product( $product, 1 );
113
+		$order->set_shipping_postcode('1050');
114
+		$order->add_product($product, 1);
115 115
 		$order->save();
116 116
 		$order->calculate_totals();
117 117
 
118 118
 		// Act: Call get_level3_data_from_order().
119 119
 		$store_postcode = '1100';
120 120
 		$gateway = new WC_Gateway_Stripe();
121
-		$result = $gateway->get_level3_data_from_order( $order );
121
+		$result = $gateway->get_level3_data_from_order($order);
122 122
 
123 123
 		// Assert.
124 124
 		$this->assertEquals(
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 				'line_items' => array(
129 129
 					(object) array(
130 130
 						'product_code'        => (string) $product->get_id(),
131
-						'product_description' => substr( $product->get_name(), 0, 26 ),
131
+						'product_description' => substr($product->get_name(), 0, 26),
132 132
 						'unit_cost'           => 1919,
133 133
 						'quantity'            => 1,
134 134
 						'tax_amount'          => 0,
@@ -141,14 +141,14 @@  discard block
 block discarded – undo
141 141
 	}
142 142
 
143 143
 	public function test_pre_30_postal_code_omission() {
144
-		if ( ! WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
144
+		if ( ! WC_Stripe_Helper::is_wc_lt('3.0')) {
145 145
 			// Dummy assertion.
146
-			$this->assertEquals( WC_Stripe_Helper::is_wc_lt( '3.0' ), false );
146
+			$this->assertEquals(WC_Stripe_Helper::is_wc_lt('3.0'), false);
147 147
 			return;
148 148
 		}
149 149
 
150 150
 		$order = new WC_Order();
151 151
 		$gateway = new WC_Gateway_Stripe();
152
-		$this->assertEquals( array(), $gateway->get_level3_data_from_order( $order ) );
152
+		$this->assertEquals(array(), $gateway->get_level3_data_from_order($order));
153 153
 	}
154 154
 }
Please login to merge, or discard this patch.