Completed
Pull Request — master (#503)
by Roy
03:29
created
includes/class-wc-stripe-api.php 1 patch
Spacing   +26 added lines, -26 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
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * Set secret API Key.
27 27
 	 * @param string $key
28 28
 	 */
29
-	public static function set_secret_key( $secret_key ) {
29
+	public static function set_secret_key($secret_key) {
30 30
 		self::$secret_key = $secret_key;
31 31
 	}
32 32
 
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	 * @return string
36 36
 	 */
37 37
 	public static function get_secret_key() {
38
-		if ( ! self::$secret_key ) {
39
-			$options = get_option( 'woocommerce_stripe_settings' );
38
+		if ( ! self::$secret_key) {
39
+			$options = get_option('woocommerce_stripe_settings');
40 40
 
41
-			if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) {
42
-				self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] );
41
+			if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) {
42
+				self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']);
43 43
 			}
44 44
 		}
45 45
 		return self::$secret_key;
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
 		$user_agent = self::get_user_agent();
79 79
 		$app_info   = $user_agent['application'];
80 80
 
81
-		return apply_filters( 'woocommerce_stripe_request_headers', array(
82
-			'Authorization'              => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
81
+		return apply_filters('woocommerce_stripe_request_headers', array(
82
+			'Authorization'              => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
83 83
 			'Stripe-Version'             => self::STRIPE_API_VERSION,
84 84
 			'User-Agent'                 => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')',
85
-			'X-Stripe-Client-User-Agent' => json_encode( $user_agent ),
86
-		) );
85
+			'X-Stripe-Client-User-Agent' => json_encode($user_agent),
86
+		));
87 87
 	}
88 88
 
89 89
 	/**
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 	 * @param string $api
96 96
 	 * @return array|WP_Error
97 97
 	 */
98
-	public static function request( $request, $api = 'charges', $method = 'POST' ) {
99
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
98
+	public static function request($request, $api = 'charges', $method = 'POST') {
99
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
100 100
 
101 101
 		$headers = self::get_headers();
102 102
 
103
-		if ( 'charges' === $api && 'POST' === $method ) {
104
-			$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
105
-			$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
103
+		if ('charges' === $api && 'POST' === $method) {
104
+			$customer = ! empty($request['customer']) ? $request['customer'] : '';
105
+			$source   = ! empty($request['source']) ? $request['source'] : $customer;
106 106
 
107 107
 			$headers['Idempotency-Key'] = $request['metadata']['order_id'] . '-' . $source;
108 108
 		}
@@ -112,17 +112,17 @@  discard block
 block discarded – undo
112 112
 			array(
113 113
 				'method'  => $method,
114 114
 				'headers' => $headers,
115
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
115
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
116 116
 				'timeout' => 70,
117 117
 			)
118 118
 		);
119 119
 
120
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
121
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
122
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
120
+		if (is_wp_error($response) || empty($response['body'])) {
121
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
122
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
123 123
 		}
124 124
 
125
-		return json_decode( $response['body'] );
125
+		return json_decode($response['body']);
126 126
 	}
127 127
 
128 128
 	/**
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @version 4.0.0
133 133
 	 * @param string $api
134 134
 	 */
135
-	public static function retrieve( $api ) {
136
-		WC_Stripe_Logger::log( "{$api}" );
135
+	public static function retrieve($api) {
136
+		WC_Stripe_Logger::log("{$api}");
137 137
 
138 138
 		$response = wp_safe_remote_get(
139 139
 			self::ENDPOINT . $api,
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 			)
145 145
 		);
146 146
 
147
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
148
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
149
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
147
+		if (is_wp_error($response) || empty($response['body'])) {
148
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
149
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
150 150
 		}
151 151
 
152
-		return json_decode( $response['body'] );
152
+		return json_decode($response['body']);
153 153
 	}
154 154
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +172 added lines, -172 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,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$this->retry_interval = 2;
25 25
 
26
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
31
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
31
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
32 32
 	}
33 33
 
34 34
 	/**
@@ -49,25 +49,25 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function process_redirect_payment( $order_id, $retry = true ) {
52
+	public function process_redirect_payment($order_id, $retry = true) {
53 53
 		try {
54
-			$source = wc_clean( $_GET['source'] );
54
+			$source = wc_clean($_GET['source']);
55 55
 
56
-			if ( empty( $source ) ) {
56
+			if (empty($source)) {
57 57
 				return;
58 58
 			}
59 59
 
60
-			if ( empty( $order_id ) ) {
60
+			if (empty($order_id)) {
61 61
 				return;
62 62
 			}
63 63
 
64
-			$order = wc_get_order( $order_id );
64
+			$order = wc_get_order($order_id);
65 65
 
66
-			if ( ! is_object( $order ) ) {
66
+			if ( ! is_object($order)) {
67 67
 				return;
68 68
 			}
69 69
 
70
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
70
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
71 71
 				return;
72 72
 			}
73 73
 
@@ -75,127 +75,127 @@  discard block
 block discarded – undo
75 75
 			$response = null;
76 76
 
77 77
 			// This will throw exception if not valid.
78
-			$this->validate_minimum_order_amount( $order );
78
+			$this->validate_minimum_order_amount($order);
79 79
 
80
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
80
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
81 81
 
82 82
 			/**
83 83
 			 * First check if the source is chargeable at this time. If not,
84 84
 			 * webhook will take care of it later.
85 85
 			 */
86
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
86
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
87 87
 
88
-			if ( ! empty( $source_info->error ) ) {
89
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
88
+			if ( ! empty($source_info->error)) {
89
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
90 90
 			}
91 91
 
92
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
93
-				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' ) );
92
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
93
+				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 94
 			}
95 95
 
96 96
 			// If already consumed, then ignore request.
97
-			if ( 'consumed' === $source_info->status ) {
97
+			if ('consumed' === $source_info->status) {
98 98
 				return;
99 99
 			}
100 100
 
101 101
 			// If not chargeable, then ignore request.
102
-			if ( 'chargeable' !== $source_info->status ) {
102
+			if ('chargeable' !== $source_info->status) {
103 103
 				return;
104 104
 			}
105 105
 
106 106
 			// Prep source object.
107 107
 			$source_object           = new stdClass();
108 108
 			$source_object->token_id = '';
109
-			$source_object->customer = $this->get_stripe_customer_id( $order );
109
+			$source_object->customer = $this->get_stripe_customer_id($order);
110 110
 			$source_object->source   = $source_info->id;
111 111
 
112 112
 			// Make the request.
113
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
113
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
114 114
 
115
-			if ( ! empty( $response->error ) ) {
115
+			if ( ! empty($response->error)) {
116 116
 				// If it is an API error such connection or server, let's retry.
117
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
118
-					if ( $retry ) {
119
-						sleep( 5 );
120
-						return $this->process_redirect_payment( $order_id, false );
117
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
118
+					if ($retry) {
119
+						sleep(5);
120
+						return $this->process_redirect_payment($order_id, false);
121 121
 					} else {
122
-						$localized_message = __( 'API connection error and retries exhausted.', 'woocommerce-gateway-stripe' );
123
-						$order->add_order_note( $localized_message );
124
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
122
+						$localized_message = __('API connection error and retries exhausted.', 'woocommerce-gateway-stripe');
123
+						$order->add_order_note($localized_message);
124
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
125 125
 					}
126 126
 				}
127 127
 
128 128
 				// We want to retry.
129
-				if ( $this->is_retryable_error( $response->error ) ) {
130
-					if ( $retry ) {
129
+				if ($this->is_retryable_error($response->error)) {
130
+					if ($retry) {
131 131
 						// Don't do anymore retries after this.
132
-						if ( 5 <= $this->retry_interval ) {
133
-							return $this->process_redirect_payment( $order_id, false );
132
+						if (5 <= $this->retry_interval) {
133
+							return $this->process_redirect_payment($order_id, false);
134 134
 						}
135 135
 
136
-						sleep( $this->retry_interval );
136
+						sleep($this->retry_interval);
137 137
 
138 138
 						$this->retry_interval++;
139
-						return $this->process_redirect_payment( $order_id, true );
139
+						return $this->process_redirect_payment($order_id, true);
140 140
 					} else {
141
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
142
-						$order->add_order_note( $localized_message );
143
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
141
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
142
+						$order->add_order_note($localized_message);
143
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
144 144
 					}
145 145
 				}
146 146
 
147 147
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
148
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
149
-					if ( WC_Stripe_Helper::is_pre_30() ) {
150
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
151
-						delete_post_meta( $order_id, '_stripe_customer_id' );
148
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
149
+					if (WC_Stripe_Helper::is_pre_30()) {
150
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
151
+						delete_post_meta($order_id, '_stripe_customer_id');
152 152
 					} else {
153
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
154
-						$order->delete_meta_data( '_stripe_customer_id' );
153
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
154
+						$order->delete_meta_data('_stripe_customer_id');
155 155
 						$order->save();
156 156
 					}
157 157
 
158
-					return $this->process_redirect_payment( $order_id, false );
158
+					return $this->process_redirect_payment($order_id, false);
159 159
 
160
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
160
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
161 161
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
162 162
 
163
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
163
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
164 164
 					$wc_token->delete();
165
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
166
-					$order->add_order_note( $message );
167
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
165
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
166
+					$order->add_order_note($message);
167
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
168 168
 				}
169 169
 
170 170
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
171 171
 
172
-				if ( 'card_error' === $response->error->type ) {
173
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
172
+				if ('card_error' === $response->error->type) {
173
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
174 174
 				} else {
175
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
175
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
176 176
 				}
177 177
 
178
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
178
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
179 179
 			}
180 180
 
181
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
181
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
182 182
 
183
-			$this->process_response( $response, $order );
183
+			$this->process_response($response, $order);
184 184
 
185
-		} catch ( WC_Stripe_Exception $e ) {
186
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
185
+		} catch (WC_Stripe_Exception $e) {
186
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
187 187
 
188
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
188
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
189 189
 
190 190
 			/* translators: error message */
191
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
191
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
192 192
 
193
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
194
-				$this->send_failed_order_email( $order_id );
193
+			if ($order->has_status(array('pending', 'failed'))) {
194
+				$this->send_failed_order_email($order_id);
195 195
 			}
196 196
 
197
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
198
-			wp_safe_redirect( wc_get_checkout_url() );
197
+			wc_add_notice($e->getLocalizedMessage(), 'error');
198
+			wp_safe_redirect(wc_get_checkout_url());
199 199
 			exit;
200 200
 		}
201 201
 	}
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
 	 * @version 4.0.0
208 208
 	 */
209 209
 	public function maybe_process_redirect_order() {
210
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
210
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
211 211
 			return;
212 212
 		}
213 213
 
214
-		$order_id = wc_clean( $_GET['order_id'] );
214
+		$order_id = wc_clean($_GET['order_id']);
215 215
 
216
-		$this->process_redirect_payment( $order_id );
216
+		$this->process_redirect_payment($order_id);
217 217
 	}
218 218
 
219 219
 	/**
@@ -223,52 +223,52 @@  discard block
 block discarded – undo
223 223
 	 * @version 4.0.0
224 224
 	 * @param  int $order_id
225 225
 	 */
226
-	public function capture_payment( $order_id ) {
227
-		$order = wc_get_order( $order_id );
226
+	public function capture_payment($order_id) {
227
+		$order = wc_get_order($order_id);
228 228
 
229
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
230
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
231
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
229
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
230
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
231
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
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
-				$result = WC_Stripe_API::request( array(
241
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
240
+				$result = WC_Stripe_API::request(array(
241
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
242 242
 					'expand[]' => 'balance_transaction',
243
-				), 'charges/' . $charge . '/capture' );
243
+				), 'charges/' . $charge . '/capture');
244 244
 
245
-				if ( ! empty( $result->error ) ) {
245
+				if ( ! empty($result->error)) {
246 246
 					/* translators: error message */
247
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
247
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
248 248
 				} else {
249 249
 					/* translators: transaction id */
250
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
251
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
250
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
251
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
252 252
 
253 253
 					// Store other data such as fees
254
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
254
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
255 255
 
256
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
256
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
257 257
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
258 258
 						// values are in the local currency of the Stripe account, not from WC.
259
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
260
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
261
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee );
262
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net );
259
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
260
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
261
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee);
262
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net);
263 263
 					}
264 264
 
265
-					if ( is_callable( array( $order, 'save' ) ) ) {
265
+					if (is_callable(array($order, 'save'))) {
266 266
 						$order->save();
267 267
 					}
268 268
 				}
269 269
 
270 270
 				// This hook fires when admin manually changes order status to processing or completed.
271
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
271
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
272 272
 			}
273 273
 		}
274 274
 	}
@@ -280,14 +280,14 @@  discard block
 block discarded – undo
280 280
 	 * @version 4.0.0
281 281
 	 * @param  int $order_id
282 282
 	 */
283
-	public function cancel_payment( $order_id ) {
284
-		$order = wc_get_order( $order_id );
283
+	public function cancel_payment($order_id) {
284
+		$order = wc_get_order($order_id);
285 285
 
286
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
287
-			$this->process_refund( $order_id );
286
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
287
+			$this->process_refund($order_id);
288 288
 
289 289
 			// This hook fires when admin manually changes order status to cancel.
290
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
290
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
291 291
 		}
292 292
 	}
293 293
 
@@ -299,21 +299,21 @@  discard block
 block discarded – undo
299 299
 	 * @param string $field
300 300
 	 * @return string $error_field
301 301
 	 */
302
-	public function normalize_field( $field ) {
302
+	public function normalize_field($field) {
303 303
 		$checkout_fields = WC()->checkout->get_checkout_fields();
304 304
 		$org_str         = array();
305 305
 		$replace_str     = array();
306 306
 
307
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
308
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
309
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
310
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
311
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
312
-			$error_field = $checkout_fields['order'][ $field ]['label'];
313
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
314
-			$error_field = $checkout_fields['account'][ $field ]['label'];
307
+		if (array_key_exists($field, $checkout_fields['billing'])) {
308
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
309
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
310
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
311
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
312
+			$error_field = $checkout_fields['order'][$field]['label'];
313
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
314
+			$error_field = $checkout_fields['account'][$field]['label'];
315 315
 		} else {
316
-			$error_field = str_replace( '_', ' ', $field );
316
+			$error_field = str_replace('_', ' ', $field);
317 317
 
318 318
 			$org_str[]     = 'stripe';
319 319
 			$replace_str[] = '';
@@ -328,9 +328,9 @@  discard block
 block discarded – undo
328 328
 			$replace_str[] = 'SOFORT';
329 329
 
330 330
 			$org_str[]     = 'owner';
331
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
331
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
332 332
 
333
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
333
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
334 334
 		}
335 335
 
336 336
 		return $error_field;
@@ -343,138 +343,138 @@  discard block
 block discarded – undo
343 343
 	 * @version 4.0.0
344 344
 	 */
345 345
 	public function validate_checkout() {
346
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
347
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
346
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
347
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
348 348
 		}
349 349
 
350 350
 		$errors = new WP_Error();
351
-		parse_str( $_POST['required_fields'], $required_fields );
352
-		parse_str( $_POST['all_fields'], $all_fields );
353
-		$source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : '';
351
+		parse_str($_POST['required_fields'], $required_fields);
352
+		parse_str($_POST['all_fields'], $all_fields);
353
+		$source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : '';
354 354
 		$validate_shipping_fields = false;
355 355
 		$create_account = false;
356 356
 
357
-		$all_fields      = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
358
-		$required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
357
+		$all_fields      = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
358
+		$required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
359 359
 
360
-		array_walk_recursive( $required_fields, 'wc_clean' );
361
-		array_walk_recursive( $all_fields, 'wc_clean' );
360
+		array_walk_recursive($required_fields, 'wc_clean');
361
+		array_walk_recursive($all_fields, 'wc_clean');
362 362
 
363 363
 		/**
364 364
 		 * If ship to different address checkbox is checked then we need
365 365
 		 * to validate shipping fields too.
366 366
 		 */
367
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
367
+		if (isset($all_fields['ship_to_different_address'])) {
368 368
 			$validate_shipping_fields = true;
369 369
 		}
370 370
 
371 371
 		// Check if createaccount is checked.
372
-		if ( isset( $all_fields['createaccount'] ) ) {
372
+		if (isset($all_fields['createaccount'])) {
373 373
 			$create_account = true;
374 374
 		}
375 375
 
376 376
 		// Check if required fields are empty.
377
-		foreach ( $required_fields as $field => $field_value ) {
377
+		foreach ($required_fields as $field => $field_value) {
378 378
 			// Check for shipping field.
379
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
379
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
380 380
 				continue;
381 381
 			}
382 382
 
383 383
 			// Check create account name.
384
-			if ( 'account_username' === $field && ! $create_account ) {
384
+			if ('account_username' === $field && ! $create_account) {
385 385
 				continue;
386 386
 			}
387 387
 
388 388
 			// Check create account password.
389
-			if ( 'account_password' === $field && ! $create_account ) {
389
+			if ('account_password' === $field && ! $create_account) {
390 390
 				continue;
391 391
 			}
392 392
 
393
-			if ( empty( $field_value ) || '-1' === $field_value ) {
394
-				$error_field = $this->normalize_field( $field );
393
+			if (empty($field_value) || '-1' === $field_value) {
394
+				$error_field = $this->normalize_field($field);
395 395
 				/* translators: error field name */
396
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
396
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
397 397
 			}
398 398
 		}
399 399
 
400 400
 		// Check if email is valid format.
401
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
402
-			$errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) );
401
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
402
+			$errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe'));
403 403
 		}
404 404
 
405 405
 		// Check if phone number is valid format.
406
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
407
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
406
+		if ( ! empty($required_fields['billing_phone'])) {
407
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
408 408
 
409
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
409
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
410 410
 				/* translators: %s: phone number */
411
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
411
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
412 412
 			}
413 413
 		}
414 414
 
415 415
 		// Check if postal code is valid format.
416
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
417
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
418
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
416
+		if ( ! empty($required_fields['billing_postcode'])) {
417
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
418
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
419 419
 
420
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
421
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
420
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
421
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
422 422
 			}
423 423
 		}
424 424
 
425 425
 		// Don't check this on add payment method page.
426
-		if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) {
427
-			if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
428
-				$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
426
+		if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) {
427
+			if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
428
+				$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
429 429
 			}
430 430
 		}
431 431
 
432
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
432
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
433 433
 			// Check if postal code is valid format.
434
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
435
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
436
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
434
+			if ( ! empty($required_fields['shipping_postcode'])) {
435
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
436
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
437 437
 
438
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
439
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
438
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
439
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
440 440
 				}
441 441
 			}
442 442
 		}
443 443
 
444
-		if ( WC()->cart->needs_shipping() ) {
444
+		if (WC()->cart->needs_shipping()) {
445 445
 			$shipping_country = WC()->customer->get_shipping_country();
446 446
 
447
-			if ( empty( $shipping_country ) ) {
448
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
449
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
447
+			if (empty($shipping_country)) {
448
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
449
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
450 450
 				/* translators: country name */
451
-				$errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
451
+				$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()));
452 452
 			} else {
453
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
453
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
454 454
 
455
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
456
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
457
-						$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) );
455
+				foreach (WC()->shipping->get_packages() as $i => $package) {
456
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
457
+						$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe'));
458 458
 					}
459 459
 				}
460 460
 			}
461 461
 		}
462 462
 
463
-		if ( WC()->cart->needs_payment() ) {
463
+		if (WC()->cart->needs_payment()) {
464 464
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
465 465
 
466
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
467
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
466
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
467
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
468 468
 			} else {
469
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
469
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
470 470
 			}
471 471
 		}
472 472
 
473
-		if ( 0 === count( $errors->errors ) ) {
474
-			wp_send_json( 'success' );
473
+		if (0 === count($errors->errors)) {
474
+			wp_send_json('success');
475 475
 		} else {
476
-			foreach ( $errors->get_error_messages() as $message ) {
477
-				wc_add_notice( $message, 'error' );
476
+			foreach ($errors->get_error_messages() as $message) {
477
+				wc_add_notice($message, 'error');
478 478
 			}
479 479
 
480 480
 			$this->send_ajax_failure_response();
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
 	 * @version 4.0.0
489 489
 	 */
490 490
 	public function send_ajax_failure_response() {
491
-		if ( is_ajax() ) {
491
+		if (is_ajax()) {
492 492
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
493
-			if ( ! isset( WC()->session->reload_checkout ) ) {
493
+			if ( ! isset(WC()->session->reload_checkout)) {
494 494
 				ob_start();
495 495
 				wc_print_notices();
496 496
 				$messages = ob_get_clean();
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 
499 499
 			$response = array(
500 500
 				'result'   => 'failure',
501
-				'messages' => isset( $messages ) ? $messages : '',
502
-				'refresh'  => isset( WC()->session->refresh_totals ),
503
-				'reload'   => isset( WC()->session->reload_checkout ),
501
+				'messages' => isset($messages) ? $messages : '',
502
+				'refresh'  => isset(WC()->session->refresh_totals),
503
+				'reload'   => isset(WC()->session->reload_checkout),
504 504
 			);
505 505
 
506
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
506
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
507 507
 
508
-			wp_send_json( $response );
508
+			wp_send_json($response);
509 509
 		}
510 510
 	}
511 511
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +157 added lines, -157 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
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 	public function __construct() {
22 22
 		$this->retry_interval = 2;
23
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
23
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
24 24
 	}
25 25
 
26 26
 	/**
@@ -30,24 +30,24 @@  discard block
 block discarded – undo
30 30
 	 * @version 4.0.0
31 31
 	 */
32 32
 	public function check_for_webhook() {
33
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
34
-			|| ! isset( $_GET['wc-api'] )
35
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
33
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
34
+			|| ! isset($_GET['wc-api'])
35
+			|| ('wc_stripe' !== $_GET['wc-api'])
36 36
 		) {
37 37
 			return;
38 38
 		}
39 39
 
40
-		$request_body    = file_get_contents( 'php://input' );
41
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
40
+		$request_body    = file_get_contents('php://input');
41
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
42 42
 
43 43
 		// Validate it to make sure it is legit.
44
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
45
-			$this->process_webhook( $request_body );
46
-			status_header( 200 );
44
+		if ($this->is_valid_request($request_headers, $request_body)) {
45
+			$this->process_webhook($request_body);
46
+			status_header(200);
47 47
 			exit;
48 48
 		} else {
49
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
50
-			status_header( 400 );
49
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
50
+			status_header(400);
51 51
 			exit;
52 52
 		}
53 53
 	}
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
 	 * @param string $request_body The request body from Stripe.
63 63
 	 * @return bool
64 64
 	 */
65
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
66
-		if ( null === $request_headers || null === $request_body ) {
65
+	public function is_valid_request($request_headers = null, $request_body = null) {
66
+		if (null === $request_headers || null === $request_body) {
67 67
 			return false;
68 68
 		}
69 69
 
70
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
70
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
71 71
 			return false;
72 72
 		}
73 73
 
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 	 * @version 4.0.0
84 84
 	 */
85 85
 	public function get_request_headers() {
86
-		if ( ! function_exists( 'getallheaders' ) ) {
86
+		if ( ! function_exists('getallheaders')) {
87 87
 			$headers = [];
88
-			foreach ( $_SERVER as $name => $value ) {
89
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
90
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
88
+			foreach ($_SERVER as $name => $value) {
89
+				if ('HTTP_' === substr($name, 0, 5)) {
90
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
91 91
 				}
92 92
 			}
93 93
 
@@ -106,30 +106,30 @@  discard block
 block discarded – undo
106 106
 	 * @param object $notification
107 107
 	 * @param bool $retry
108 108
 	 */
109
-	public function process_webhook_payment( $notification, $retry = true ) {
109
+	public function process_webhook_payment($notification, $retry = true) {
110 110
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
111
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
111
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
112 112
 			return;
113 113
 		}
114 114
 
115
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
115
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
116 116
 
117
-		if ( ! $order ) {
118
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
117
+		if ( ! $order) {
118
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
119 119
 			return;
120 120
 		}
121 121
 
122 122
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
123 123
 		$source_id = $notification->data->object->id;
124 124
 
125
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
125
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
126 126
 
127 127
 		try {
128
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
128
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
129 129
 				return;
130 130
 			}
131 131
 
132
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
132
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
133 133
 				return;
134 134
 			}
135 135
 
@@ -137,100 +137,100 @@  discard block
 block discarded – undo
137 137
 			$response = null;
138 138
 
139 139
 			// This will throw exception if not valid.
140
-			$this->validate_minimum_order_amount( $order );
140
+			$this->validate_minimum_order_amount($order);
141 141
 
142
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
142
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
143 143
 
144 144
 			// Prep source object.
145 145
 			$source_object           = new stdClass();
146 146
 			$source_object->token_id = '';
147
-			$source_object->customer = $this->get_stripe_customer_id( $order );
147
+			$source_object->customer = $this->get_stripe_customer_id($order);
148 148
 			$source_object->source   = $source_id;
149 149
 
150 150
 			// Make the request.
151
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
151
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
152 152
 
153
-			if ( ! empty( $response->error ) ) {
153
+			if ( ! empty($response->error)) {
154 154
 				// If it is an API error such connection or server, let's retry.
155
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
156
-					if ( $retry ) {
157
-						sleep( 5 );
158
-						return $this->process_webhook_payment( $notification, false );
155
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
156
+					if ($retry) {
157
+						sleep(5);
158
+						return $this->process_webhook_payment($notification, false);
159 159
 					} else {
160 160
 						$localized_message = 'API connection error and retries exhausted.';
161
-						$order->add_order_note( $localized_message );
162
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
161
+						$order->add_order_note($localized_message);
162
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
163 163
 					}
164 164
 				}
165 165
 
166 166
 				// We want to retry.
167
-				if ( $this->is_retryable_error( $response->error ) ) {
168
-					if ( $retry ) {
167
+				if ($this->is_retryable_error($response->error)) {
168
+					if ($retry) {
169 169
 						// Don't do anymore retries after this.
170
-						if ( 5 <= $this->retry_interval ) {
170
+						if (5 <= $this->retry_interval) {
171 171
 
172
-							return $this->process_webhook_payment( $notification, false );
172
+							return $this->process_webhook_payment($notification, false);
173 173
 						}
174 174
 
175
-						sleep( $this->retry_interval );
175
+						sleep($this->retry_interval);
176 176
 
177 177
 						$this->retry_interval++;
178
-						return $this->process_webhook_payment( $notification, true );
178
+						return $this->process_webhook_payment($notification, true);
179 179
 					} else {
180
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
181
-						$order->add_order_note( $localized_message );
182
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
180
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
181
+						$order->add_order_note($localized_message);
182
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
183 183
 					}
184 184
 				}
185 185
 
186 186
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
187
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
188
-					if ( WC_Stripe_Helper::is_pre_30() ) {
189
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
190
-						delete_post_meta( $order_id, '_stripe_customer_id' );
187
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
188
+					if (WC_Stripe_Helper::is_pre_30()) {
189
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
190
+						delete_post_meta($order_id, '_stripe_customer_id');
191 191
 					} else {
192
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
193
-						$order->delete_meta_data( '_stripe_customer_id' );
192
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
193
+						$order->delete_meta_data('_stripe_customer_id');
194 194
 						$order->save();
195 195
 					}
196 196
 
197
-					return $this->process_webhook_payment( $notification, false );
197
+					return $this->process_webhook_payment($notification, false);
198 198
 
199
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
199
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
200 200
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
201
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
201
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
202 202
 					$wc_token->delete();
203
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
204
-					$order->add_order_note( $message );
205
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
203
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
204
+					$order->add_order_note($message);
205
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
206 206
 				}
207 207
 
208 208
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
209 209
 
210
-				if ( 'card_error' === $response->error->type ) {
211
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
210
+				if ('card_error' === $response->error->type) {
211
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
212 212
 				} else {
213
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
213
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
214 214
 				}
215 215
 
216
-				$order->add_order_note( $localized_message );
216
+				$order->add_order_note($localized_message);
217 217
 
218
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
218
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
219 219
 			}
220 220
 
221
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
221
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
222 222
 
223
-			$this->process_response( $response, $order );
223
+			$this->process_response($response, $order);
224 224
 
225
-		} catch ( WC_Stripe_Exception $e ) {
226
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
225
+		} catch (WC_Stripe_Exception $e) {
226
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
227 227
 
228
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
228
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
229 229
 
230
-			$statuses = array( 'pending', 'failed' );
230
+			$statuses = array('pending', 'failed');
231 231
 
232
-			if ( $order->has_status( $statuses ) ) {
233
-				$this->send_failed_order_email( $order_id );
232
+			if ($order->has_status($statuses)) {
233
+				$this->send_failed_order_email($order_id);
234 234
 			}
235 235
 		}
236 236
 	}
@@ -243,20 +243,20 @@  discard block
 block discarded – undo
243 243
 	 * @since 4.0.0
244 244
 	 * @param object $notification
245 245
 	 */
246
-	public function process_webhook_dispute( $notification ) {
247
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
246
+	public function process_webhook_dispute($notification) {
247
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
248 248
 
249
-		if ( ! $order ) {
250
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
249
+		if ( ! $order) {
250
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
251 251
 			return;
252 252
 		}
253 253
 
254
-		$order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) );
254
+		$order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe'));
255 255
 
256
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
256
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
257 257
 
258 258
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
259
-		$this->send_failed_order_email( $order_id );
259
+		$this->send_failed_order_email($order_id);
260 260
 	}
261 261
 
262 262
 	/**
@@ -267,41 +267,41 @@  discard block
 block discarded – undo
267 267
 	 * @version 4.0.0
268 268
 	 * @param object $notification
269 269
 	 */
270
-	public function process_webhook_capture( $notification ) {
271
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
270
+	public function process_webhook_capture($notification) {
271
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
272 272
 
273
-		if ( ! $order ) {
274
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
273
+		if ( ! $order) {
274
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
275 275
 			return;
276 276
 		}
277 277
 
278 278
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
279 279
 
280
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
281
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
282
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
280
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
281
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
282
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
283 283
 
284
-			if ( $charge && 'no' === $captured ) {
285
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
284
+			if ($charge && 'no' === $captured) {
285
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
286 286
 
287 287
 				// Store other data such as fees
288
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
288
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
289 289
 
290
-				if ( isset( $notification->data->object->balance_transaction ) ) {
291
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
290
+				if (isset($notification->data->object->balance_transaction)) {
291
+					$this->update_fees($order, $notification->data->object->balance_transaction);
292 292
 				}
293 293
 
294
-				if ( is_callable( array( $order, 'save' ) ) ) {
294
+				if (is_callable(array($order, 'save'))) {
295 295
 					$order->save();
296 296
 				}
297 297
 
298 298
 				/* translators: transaction id */
299
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
299
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
300 300
 
301 301
 				// Check and see if capture is partial.
302
-				if ( $this->is_partial_capture( $notification ) ) {
303
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
304
-					$order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
302
+				if ($this->is_partial_capture($notification)) {
303
+					$order->set_total($this->get_partial_amount_to_charge($notification));
304
+					$order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
305 305
 					$order->save();
306 306
 				}
307 307
 			}
@@ -316,38 +316,38 @@  discard block
 block discarded – undo
316 316
 	 * @version 4.0.0
317 317
 	 * @param object $notification
318 318
 	 */
319
-	public function process_webhook_charge_succeeded( $notification ) {
319
+	public function process_webhook_charge_succeeded($notification) {
320 320
 		// The following payment methods are synchronous so does not need to be handle via webhook.
321
-		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 ) ) {
321
+		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)) {
322 322
 			return;
323 323
 		}
324 324
 
325
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
325
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
326 326
 
327
-		if ( ! $order ) {
328
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
327
+		if ( ! $order) {
328
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
329 329
 			return;
330 330
 		}
331 331
 
332 332
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
333 333
 
334
-		if ( 'on-hold' !== $order->get_status() ) {
334
+		if ('on-hold' !== $order->get_status()) {
335 335
 			return;
336 336
 		}
337 337
 
338 338
 		// Store other data such as fees
339
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
339
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
340 340
 
341
-		if ( isset( $notification->data->object->balance_transaction ) ) {
342
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
341
+		if (isset($notification->data->object->balance_transaction)) {
342
+			$this->update_fees($order, $notification->data->object->balance_transaction);
343 343
 		}
344 344
 
345
-		if ( is_callable( array( $order, 'save' ) ) ) {
345
+		if (is_callable(array($order, 'save'))) {
346 346
 			$order->save();
347 347
 		}
348 348
 
349 349
 		/* translators: transaction id */
350
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
350
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
351 351
 	}
352 352
 
353 353
 	/**
@@ -358,23 +358,23 @@  discard block
 block discarded – undo
358 358
 	 * @version 4.0.0
359 359
 	 * @param object $notification
360 360
 	 */
361
-	public function process_webhook_charge_failed( $notification ) {
362
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
361
+	public function process_webhook_charge_failed($notification) {
362
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
363 363
 
364
-		if ( ! $order ) {
365
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
364
+		if ( ! $order) {
365
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
366 366
 			return;
367 367
 		}
368 368
 
369 369
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
370 370
 
371
-		if ( 'on-hold' !== $order->get_status() ) {
371
+		if ('on-hold' !== $order->get_status()) {
372 372
 			return;
373 373
 		}
374 374
 
375
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
375
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
376 376
 
377
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
377
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
378 378
 	}
379 379
 
380 380
 	/**
@@ -385,23 +385,23 @@  discard block
 block discarded – undo
385 385
 	 * @version 4.0.0
386 386
 	 * @param object $notification
387 387
 	 */
388
-	public function process_webhook_source_canceled( $notification ) {
389
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
388
+	public function process_webhook_source_canceled($notification) {
389
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
390 390
 
391
-		if ( ! $order ) {
392
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
391
+		if ( ! $order) {
392
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
393 393
 			return;
394 394
 		}
395 395
 
396 396
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
397 397
 
398
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
398
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
399 399
 			return;
400 400
 		}
401 401
 
402
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
402
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
403 403
 
404
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
404
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
405 405
 	}
406 406
 
407 407
 	/**
@@ -412,42 +412,42 @@  discard block
 block discarded – undo
412 412
 	 * @version 4.0.0
413 413
 	 * @param object $notification
414 414
 	 */
415
-	public function process_webhook_refund( $notification ) {
416
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
415
+	public function process_webhook_refund($notification) {
416
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
417 417
 
418
-		if ( ! $order ) {
419
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
418
+		if ( ! $order) {
419
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
420 420
 			return;
421 421
 		}
422 422
 
423 423
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
424 424
 
425
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
426
-			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
427
-			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
428
-			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
425
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
426
+			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
427
+			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
428
+			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
429 429
 
430 430
 			// If the refund ID matches, don't continue to prevent double refunding.
431
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
431
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
432 432
 				return;
433 433
 			}
434 434
 
435 435
 			// Only refund captured charge.
436
-			if ( $charge ) {
437
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
436
+			if ($charge) {
437
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
438 438
 
439 439
 				// Create the refund.
440
-				$refund = wc_create_refund( array(
440
+				$refund = wc_create_refund(array(
441 441
 					'order_id'       => $order_id,
442
-					'amount'         => $this->get_refund_amount( $notification ),
442
+					'amount'         => $this->get_refund_amount($notification),
443 443
 					'reason'         => $reason,
444
-				) );
444
+				));
445 445
 
446
-				if ( is_wp_error( $refund ) ) {
447
-					WC_Stripe_Logger::log( $refund->get_error_message() );
446
+				if (is_wp_error($refund)) {
447
+					WC_Stripe_Logger::log($refund->get_error_message());
448 448
 				}
449 449
 
450
-				$order->add_order_note( $reason );
450
+				$order->add_order_note($reason);
451 451
 			}
452 452
 		}
453 453
 	}
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 	 * @version 4.0.0
460 460
 	 * @param object $notification
461 461
 	 */
462
-	public function is_partial_capture( $notification ) {
462
+	public function is_partial_capture($notification) {
463 463
 		return 0 < $notification->data->object->amount_refunded;
464 464
 	}
465 465
 
@@ -470,11 +470,11 @@  discard block
 block discarded – undo
470 470
 	 * @version 4.0.0
471 471
 	 * @param object $notification
472 472
 	 */
473
-	public function get_refund_amount( $notification ) {
474
-		if ( $this->is_partial_capture( $notification ) ) {
473
+	public function get_refund_amount($notification) {
474
+		if ($this->is_partial_capture($notification)) {
475 475
 			$amount = $notification->data->object->amount_refunded / 100;
476 476
 
477
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
477
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
478 478
 				$amount = $notification->data->object->amount_refunded;
479 479
 			}
480 480
 
@@ -491,12 +491,12 @@  discard block
 block discarded – undo
491 491
 	 * @version 4.0.0
492 492
 	 * @param object $notification
493 493
 	 */
494
-	public function get_partial_amount_to_charge( $notification ) {
495
-		if ( $this->is_partial_capture( $notification ) ) {
496
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
494
+	public function get_partial_amount_to_charge($notification) {
495
+		if ($this->is_partial_capture($notification)) {
496
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
497 497
 
498
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
499
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
498
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
499
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
500 500
 			}
501 501
 
502 502
 			return $amount;
@@ -512,36 +512,36 @@  discard block
 block discarded – undo
512 512
 	 * @version 4.0.0
513 513
 	 * @param string $request_body
514 514
 	 */
515
-	public function process_webhook( $request_body ) {
516
-		$notification = json_decode( $request_body );
515
+	public function process_webhook($request_body) {
516
+		$notification = json_decode($request_body);
517 517
 
518
-		switch ( $notification->type ) {
518
+		switch ($notification->type) {
519 519
 			case 'source.chargeable':
520
-				$this->process_webhook_payment( $notification );
520
+				$this->process_webhook_payment($notification);
521 521
 				break;
522 522
 
523 523
 			case 'source.canceled':
524
-				$this->process_webhook_source_canceled( $notification );
524
+				$this->process_webhook_source_canceled($notification);
525 525
 				break;
526 526
 
527 527
 			case 'charge.succeeded':
528
-				$this->process_webhook_charge_succeeded( $notification );
528
+				$this->process_webhook_charge_succeeded($notification);
529 529
 				break;
530 530
 
531 531
 			case 'charge.failed':
532
-				$this->process_webhook_charge_failed( $notification );
532
+				$this->process_webhook_charge_failed($notification);
533 533
 				break;
534 534
 
535 535
 			case 'charge.captured':
536
-				$this->process_webhook_capture( $notification );
536
+				$this->process_webhook_capture($notification);
537 537
 				break;
538 538
 
539 539
 			case 'charge.dispute.created':
540
-				$this->process_webhook_dispute( $notification );
540
+				$this->process_webhook_dispute($notification);
541 541
 				break;
542 542
 
543 543
 			case 'charge.refunded':
544
-				$this->process_webhook_refund( $notification );
544
+				$this->process_webhook_refund($notification);
545 545
 				break;
546 546
 
547 547
 		}
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +200 added lines, -201 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @since 4.0.5
22 22
 	 * @param array $error
23 23
 	 */
24
-	public function is_retryable_error( $error ) {
24
+	public function is_retryable_error($error) {
25 25
 		return (
26 26
 			'invalid_request_error' === $error->type ||
27 27
 			'idempotency_error' === $error->type ||
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * Check if this gateway is enabled
34 34
 	 */
35 35
 	public function is_available() {
36
-		if ( 'yes' === $this->enabled ) {
37
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
36
+		if ('yes' === $this->enabled) {
37
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
38 38
 				return false;
39 39
 			}
40
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
40
+			if ( ! $this->secret_key || ! $this->publishable_key) {
41 41
 				return false;
42 42
 			}
43 43
 			return true;
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	 * @since 4.0.0
53 53
 	 * @version 4.0.0
54 54
 	 */
55
-	public function add_admin_notice( $slug, $class, $message ) {
56
-		$this->notices[ $slug ] = array(
55
+	public function add_admin_notice($slug, $class, $message) {
56
+		$this->notices[$slug] = array(
57 57
 			'class'   => $class,
58 58
 			'message' => $message,
59 59
 		);
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	 * @version 4.0.0
67 67
 	 */
68 68
 	public function remove_admin_notice() {
69
-		if ( did_action( 'woocommerce_update_options' ) ) {
70
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
69
+		if (did_action('woocommerce_update_options')) {
70
+			remove_action('admin_notices', array($this, 'check_environment'));
71 71
 		}
72 72
 	}
73 73
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @return array
80 80
 	 */
81 81
 	public function payment_icons() {
82
-		return apply_filters( 'wc_stripe_payment_icons', array(
82
+		return apply_filters('wc_stripe_payment_icons', array(
83 83
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
84 84
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
85 85
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
97 97
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
98 98
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
99
-		) );
99
+		));
100 100
 	}
101 101
 
102 102
 	/**
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 	 * @version 4.0.0
108 108
 	 * @param object $order
109 109
 	 */
110
-	public function validate_minimum_order_amount( $order ) {
111
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
110
+	public function validate_minimum_order_amount($order) {
111
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
112 112
 			/* translators: 1) dollar amount */
113
-			throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
113
+			throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
114 114
 		}
115 115
 	}
116 116
 
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 	 * @since 4.0.0
121 121
 	 * @version 4.0.0
122 122
 	 */
123
-	public function get_transaction_url( $order ) {
124
-		if ( $this->testmode ) {
123
+	public function get_transaction_url($order) {
124
+		if ($this->testmode) {
125 125
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
126 126
 		} else {
127 127
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
128 128
 		}
129 129
 
130
-		return parent::get_transaction_url( $order );
130
+		return parent::get_transaction_url($order);
131 131
 	}
132 132
 
133 133
 	/**
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 	 * @since 4.0.0
137 137
 	 * @version 4.0.0
138 138
 	 */
139
-	public function get_stripe_customer_id( $order ) {
140
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
139
+	public function get_stripe_customer_id($order) {
140
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
141 141
 
142
-		if ( empty( $customer ) ) {
142
+		if (empty($customer)) {
143 143
 			// Try to get it via the order.
144
-			if ( WC_Stripe_Helper::is_pre_30() ) {
145
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
144
+			if (WC_Stripe_Helper::is_pre_30()) {
145
+				return get_post_meta($order->id, '_stripe_customer_id', true);
146 146
 			} else {
147
-				return $order->get_meta( '_stripe_customer_id', true );
147
+				return $order->get_meta('_stripe_customer_id', true);
148 148
 			}
149 149
 		} else {
150 150
 			return $customer;
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 * @param object $order
162 162
 	 * @param int $id Stripe session id.
163 163
 	 */
164
-	public function get_stripe_return_url( $order = null, $id = null ) {
165
-		if ( is_object( $order ) ) {
166
-			if ( empty( $id ) ) {
164
+	public function get_stripe_return_url($order = null, $id = null) {
165
+		if (is_object($order)) {
166
+			if (empty($id)) {
167 167
 				$id = uniqid();
168 168
 			}
169 169
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 				'order_id'       => $order_id,
175 175
 			);
176 176
 
177
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
177
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
178 178
 		}
179 179
 
180
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
180
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
181 181
 	}
182 182
 
183 183
 	/**
@@ -189,34 +189,33 @@  discard block
 block discarded – undo
189 189
 	 * @param  object $source
190 190
 	 * @return array()
191 191
 	 */
192
-	public function generate_payment_request( $order, $source ) {
193
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
194
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
195
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
192
+	public function generate_payment_request($order, $source) {
193
+		$settings                          = get_option('woocommerce_stripe_settings', array());
194
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
195
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
196 196
 		$post_data                         = array();
197
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
198
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
197
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
198
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
199 199
 		/* translators: 1) blog name 2) order number */
200
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
200
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
201 201
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
202 202
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
203 203
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
204 204
 
205
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
205
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
206 206
 			$post_data['receipt_email'] = $billing_email;
207 207
 		}
208 208
 
209
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
210
-			case 'stripe':
211
-				if ( ! empty( $statement_descriptor ) ) {
212
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
209
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
210
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
211
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
213 212
 				}
214 213
 
215 214
 				$post_data['capture'] = $capture ? 'true' : 'false';
216 215
 				break;
217 216
 			case 'stripe_sepa':
218
-				if ( ! empty( $statement_descriptor ) ) {
219
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
217
+				if ( ! empty($statement_descriptor)) {
218
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
220 219
 				}
221 220
 				break;
222 221
 		}
@@ -224,18 +223,18 @@  discard block
 block discarded – undo
224 223
 		$post_data['expand[]'] = 'balance_transaction';
225 224
 
226 225
 		$metadata = array(
227
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
228
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
226
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
227
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
229 228
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
230 229
 		);
231 230
 
232
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
231
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
233 232
 
234
-		if ( $source->customer ) {
233
+		if ($source->customer) {
235 234
 			$post_data['customer'] = $source->customer;
236 235
 		}
237 236
 
238
-		if ( $source->source ) {
237
+		if ($source->source) {
239 238
 			$post_data['source'] = $source->source;
240 239
 		}
241 240
 
@@ -247,77 +246,77 @@  discard block
 block discarded – undo
247 246
 		 * @param WC_Order $order
248 247
 		 * @param object $source
249 248
 		 */
250
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
249
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
251 250
 	}
252 251
 
253 252
 	/**
254 253
 	 * Store extra meta data for an order from a Stripe Response.
255 254
 	 */
256
-	public function process_response( $response, $order ) {
257
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
255
+	public function process_response($response, $order) {
256
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
258 257
 
259 258
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
260 259
 
261
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
260
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
262 261
 
263 262
 		// Store charge data
264
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
263
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
265 264
 
266 265
 		// Store other data such as fees
267
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
266
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
268 267
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
269 268
 			// values are in the local currency of the Stripe account, not from WC.
270
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
271
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
272
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
273
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
269
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
270
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
271
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
272
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
274 273
 		}
275 274
 
276
-		if ( 'yes' === $captured ) {
275
+		if ('yes' === $captured) {
277 276
 			/**
278 277
 			 * Charge can be captured but in a pending state. Payment methods
279 278
 			 * that are asynchronous may take couple days to clear. Webhook will
280 279
 			 * take care of the status changes.
281 280
 			 */
282
-			if ( 'pending' === $response->status ) {
283
-				if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) {
284
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
281
+			if ('pending' === $response->status) {
282
+				if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) {
283
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
285 284
 				}
286 285
 
287
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
286
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
288 287
 				/* translators: transaction id */
289
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
288
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
290 289
 			}
291 290
 
292
-			if ( 'succeeded' === $response->status ) {
293
-				$order->payment_complete( $response->id );
291
+			if ('succeeded' === $response->status) {
292
+				$order->payment_complete($response->id);
294 293
 
295 294
 				/* translators: transaction id */
296
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
297
-				$order->add_order_note( $message );
295
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
296
+				$order->add_order_note($message);
298 297
 			}
299 298
 
300
-			if ( 'failed' === $response->status ) {
301
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
302
-				$order->add_order_note( $localized_message );
303
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
299
+			if ('failed' === $response->status) {
300
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
301
+				$order->add_order_note($localized_message);
302
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
304 303
 			}
305 304
 		} else {
306
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
305
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
307 306
 
308
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
309
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
307
+			if ($order->has_status(array('pending', 'failed'))) {
308
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
310 309
 			}
311 310
 
312 311
 			/* translators: transaction id */
313
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
312
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
314 313
 		}
315 314
 
316
-		if ( is_callable( array( $order, 'save' ) ) ) {
315
+		if (is_callable(array($order, 'save'))) {
317 316
 			$order->save();
318 317
 		}
319 318
 
320
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
319
+		do_action('wc_gateway_stripe_process_response', $response, $order);
321 320
 
322 321
 		return $response;
323 322
 	}
@@ -330,10 +329,10 @@  discard block
 block discarded – undo
330 329
 	 * @param int $order_id
331 330
 	 * @return null
332 331
 	 */
333
-	public function send_failed_order_email( $order_id ) {
332
+	public function send_failed_order_email($order_id) {
334 333
 		$emails = WC()->mailer()->get_emails();
335
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
336
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
334
+		if ( ! empty($emails) && ! empty($order_id)) {
335
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
337 336
 		}
338 337
 	}
339 338
 
@@ -345,7 +344,7 @@  discard block
 block discarded – undo
345 344
 	 * @param object $order
346 345
 	 * @return object $details
347 346
 	 */
348
-	public function get_owner_details( $order ) {
347
+	public function get_owner_details($order) {
349 348
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
350 349
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
351 350
 
@@ -356,8 +355,8 @@  discard block
 block discarded – undo
356 355
 
357 356
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
358 357
 
359
-		if ( ! empty( $phone ) ) {
360
-			$details['phone']              = $phone;
358
+		if ( ! empty($phone)) {
359
+			$details['phone'] = $phone;
361 360
 		}
362 361
 
363 362
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -367,7 +366,7 @@  discard block
 block discarded – undo
367 366
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
368 367
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
369 368
 
370
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
369
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
371 370
 	}
372 371
 
373 372
 	/**
@@ -376,16 +375,16 @@  discard block
 block discarded – undo
376 375
 	 * @since 4.0.3
377 376
 	 */
378 377
 	public function get_source_object() {
379
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
378
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
380 379
 
381
-		if ( empty( $source ) ) {
380
+		if (empty($source)) {
382 381
 			return '';
383 382
 		}
384 383
 
385
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
384
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
386 385
 
387
-		if ( ! empty( $source_object->error ) ) {
388
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
386
+		if ( ! empty($source_object->error)) {
387
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
389 388
 		}
390 389
 
391 390
 		return $source_object;
@@ -398,11 +397,11 @@  discard block
 block discarded – undo
398 397
 	 * @param object $source_object
399 398
 	 * @return bool
400 399
 	 */
401
-	public function is_3ds_required( $source_object ) {
400
+	public function is_3ds_required($source_object) {
402 401
 		return (
403
-			$source_object && ! empty( $source_object->card ) ) &&
404
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
405
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
402
+			$source_object && ! empty($source_object->card) ) &&
403
+			('card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
404
+			($this->three_d_secure && 'optional' === $source_object->card->three_d_secure)
406 405
 		);
407 406
 	}
408 407
 
@@ -413,8 +412,8 @@  discard block
 block discarded – undo
413 412
 	 * @param object $source_object
414 413
 	 * @return bool
415 414
 	 */
416
-	public function is_3ds_card( $source_object ) {
417
-		return ( $source_object && 'three_d_secure' === $source_object->type );
415
+	public function is_3ds_card($source_object) {
416
+		return ($source_object && 'three_d_secure' === $source_object->type);
418 417
 	}
419 418
 
420 419
 	/**
@@ -427,22 +426,22 @@  discard block
 block discarded – undo
427 426
 	 * @param string $return_url
428 427
 	 * @return mixed
429 428
 	 */
430
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
429
+	public function create_3ds_source($order, $source_object, $return_url = '') {
431 430
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
432 431
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
433
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
432
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
434 433
 
435 434
 		$post_data                   = array();
436
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
437
-		$post_data['currency']       = strtolower( $currency );
435
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
436
+		$post_data['currency']       = strtolower($currency);
438 437
 		$post_data['type']           = 'three_d_secure';
439
-		$post_data['owner']          = $this->get_owner_details( $order );
440
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
441
-		$post_data['redirect']       = array( 'return_url' => $return_url );
438
+		$post_data['owner']          = $this->get_owner_details($order);
439
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
440
+		$post_data['redirect']       = array('return_url' => $return_url);
442 441
 
443
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
442
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
444 443
 
445
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
444
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
446 445
 	}
447 446
 
448 447
 	/**
@@ -459,54 +458,54 @@  discard block
 block discarded – undo
459 458
 	 * @throws Exception When card was not added or for and invalid card.
460 459
 	 * @return object
461 460
 	 */
462
-	public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) {
463
-		$customer           = new WC_Stripe_Customer( $user_id );
461
+	public function prepare_source($source_object = '', $user_id, $force_save_source = false) {
462
+		$customer           = new WC_Stripe_Customer($user_id);
464 463
 		$set_customer       = true;
465
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
464
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
466 465
 		$source_id          = '';
467 466
 		$wc_token_id        = false;
468
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
467
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
469 468
 
470 469
 		// New CC info was entered and we have a new source to process.
471
-		if ( ! empty( $source_object ) ) {
470
+		if ( ! empty($source_object)) {
472 471
 			$source_id = $source_object->id;
473 472
 
474 473
 			// This checks to see if customer opted to save the payment method to file.
475
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
474
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
476 475
 
477 476
 			/**
478 477
 			 * This is true if the user wants to store the card to their account.
479 478
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
480 479
 			 * actually reusable. Either that or force_save_source is true.
481 480
 			 */
482
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
483
-				$response = $customer->add_source( $source_object->id );
481
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
482
+				$response = $customer->add_source($source_object->id);
484 483
 
485
-				if ( ! empty( $response->error ) ) {
486
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
484
+				if ( ! empty($response->error)) {
485
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
487 486
 				}
488 487
 			}
489
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
488
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
490 489
 			// Use an existing token, and then process the payment
491
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
492
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
490
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
491
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
493 492
 
494
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
495
-				WC()->session->set( 'refresh_totals', true );
496
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
493
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
494
+				WC()->session->set('refresh_totals', true);
495
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
497 496
 			}
498 497
 
499 498
 			$source_id = $wc_token->get_token();
500
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
501
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
502
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
499
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
500
+			$stripe_token     = wc_clean($_POST['stripe_token']);
501
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
503 502
 
504 503
 			// This is true if the user wants to store the card to their account.
505
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
506
-				$response = $customer->add_source( $stripe_token );
504
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
505
+				$response = $customer->add_source($stripe_token);
507 506
 
508
-				if ( ! empty( $response->error ) ) {
509
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
507
+				if ( ! empty($response->error)) {
508
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
510 509
 				}
511 510
 			} else {
512 511
 				$set_customer = false;
@@ -514,7 +513,7 @@  discard block
 block discarded – undo
514 513
 			}
515 514
 		}
516 515
 
517
-		if ( ! $set_customer ) {
516
+		if ( ! $set_customer) {
518 517
 			$customer_id = false;
519 518
 		} else {
520 519
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
@@ -540,37 +539,37 @@  discard block
 block discarded – undo
540 539
 	 * @param object $order
541 540
 	 * @return object
542 541
 	 */
543
-	public function prepare_order_source( $order = null ) {
542
+	public function prepare_order_source($order = null) {
544 543
 		$stripe_customer = new WC_Stripe_Customer();
545 544
 		$stripe_source   = false;
546 545
 		$token_id        = false;
547 546
 
548
-		if ( $order ) {
547
+		if ($order) {
549 548
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
550 549
 
551
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
550
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
552 551
 
553
-			if ( $stripe_customer_id ) {
554
-				$stripe_customer->set_id( $stripe_customer_id );
552
+			if ($stripe_customer_id) {
553
+				$stripe_customer->set_id($stripe_customer_id);
555 554
 			}
556 555
 
557
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
556
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
558 557
 
559 558
 			// Since 4.0.0, we changed card to source so we need to account for that.
560
-			if ( empty( $source_id ) ) {
561
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
559
+			if (empty($source_id)) {
560
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
562 561
 
563 562
 				// Take this opportunity to update the key name.
564
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id );
563
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id);
565 564
 
566
-				if ( is_callable( array( $order, 'save' ) ) ) {
565
+				if (is_callable(array($order, 'save'))) {
567 566
 					$order->save();
568 567
 				}
569 568
 			}
570 569
 
571
-			if ( $source_id ) {
570
+			if ($source_id) {
572 571
 				$stripe_source = $source_id;
573
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
572
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
574 573
 				/*
575 574
 				 * We can attempt to charge the customer's default source
576 575
 				 * by sending empty source id.
@@ -594,27 +593,27 @@  discard block
 block discarded – undo
594 593
 	 * @param WC_Order $order For to which the source applies.
595 594
 	 * @param stdClass $source Source information.
596 595
 	 */
597
-	public function save_source_to_order( $order, $source ) {
596
+	public function save_source_to_order($order, $source) {
598 597
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
599 598
 
600 599
 		// Store source in the order.
601
-		if ( $source->customer ) {
602
-			if ( WC_Stripe_Helper::is_pre_30() ) {
603
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
600
+		if ($source->customer) {
601
+			if (WC_Stripe_Helper::is_pre_30()) {
602
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
604 603
 			} else {
605
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
604
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
606 605
 			}
607 606
 		}
608 607
 
609
-		if ( $source->source ) {
610
-			if ( WC_Stripe_Helper::is_pre_30() ) {
611
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
608
+		if ($source->source) {
609
+			if (WC_Stripe_Helper::is_pre_30()) {
610
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
612 611
 			} else {
613
-				$order->update_meta_data( '_stripe_source_id', $source->source );
612
+				$order->update_meta_data('_stripe_source_id', $source->source);
614 613
 			}
615 614
 		}
616 615
 
617
-		if ( is_callable( array( $order, 'save' ) ) ) {
616
+		if (is_callable(array($order, 'save'))) {
618 617
 			$order->save();
619 618
 		}
620 619
 	}
@@ -628,27 +627,27 @@  discard block
 block discarded – undo
628 627
 	 * @param object $order The order object
629 628
 	 * @param int $balance_transaction_id
630 629
 	 */
631
-	public function update_fees( $order, $balance_transaction_id ) {
630
+	public function update_fees($order, $balance_transaction_id) {
632 631
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
633 632
 
634
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
633
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
635 634
 
636
-		if ( empty( $balance_transaction->error ) ) {
637
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
635
+		if (empty($balance_transaction->error)) {
636
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
638 637
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
639 638
 				// values are in the local currency of the Stripe account, not from WC.
640
-				$fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
641
-				$net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
639
+				$fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
640
+				$net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
642 641
 
643
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
644
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
642
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
643
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
645 644
 
646
-				if ( is_callable( array( $order, 'save' ) ) ) {
645
+				if (is_callable(array($order, 'save'))) {
647 646
 					$order->save();
648 647
 				}
649 648
 			}
650 649
 		} else {
651
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
650
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
652 651
 		}
653 652
 	}
654 653
 
@@ -661,33 +660,33 @@  discard block
 block discarded – undo
661 660
 	 * @param  float $amount
662 661
 	 * @return bool
663 662
 	 */
664
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
665
-		$order = wc_get_order( $order_id );
663
+	public function process_refund($order_id, $amount = null, $reason = '') {
664
+		$order = wc_get_order($order_id);
666 665
 
667
-		if ( ! $order || ! $order->get_transaction_id() ) {
666
+		if ( ! $order || ! $order->get_transaction_id()) {
668 667
 			return false;
669 668
 		}
670 669
 
671 670
 		$request = array();
672 671
 
673
-		if ( WC_Stripe_Helper::is_pre_30() ) {
674
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
675
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
672
+		if (WC_Stripe_Helper::is_pre_30()) {
673
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
674
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
676 675
 		} else {
677 676
 			$order_currency = $order->get_currency();
678
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
677
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
679 678
 		}
680 679
 
681
-		if ( ! is_null( $amount ) ) {
682
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
680
+		if ( ! is_null($amount)) {
681
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
683 682
 		}
684 683
 
685 684
 		// If order is only authorized, don't pass amount.
686
-		if ( 'yes' !== $captured ) {
687
-			unset( $request['amount'] );
685
+		if ('yes' !== $captured) {
686
+			unset($request['amount']);
688 687
 		}
689 688
 
690
-		if ( $reason ) {
689
+		if ($reason) {
691 690
 			$request['metadata'] = array(
692 691
 				'reason' => $reason,
693 692
 			);
@@ -695,33 +694,33 @@  discard block
 block discarded – undo
695 694
 
696 695
 		$request['charge'] = $order->get_transaction_id();
697 696
 
698
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
697
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
699 698
 
700
-		$response = WC_Stripe_API::request( $request, 'refunds' );
699
+		$response = WC_Stripe_API::request($request, 'refunds');
701 700
 
702
-		if ( ! empty( $response->error ) ) {
703
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
701
+		if ( ! empty($response->error)) {
702
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
704 703
 
705 704
 			return $response;
706 705
 
707
-		} elseif ( ! empty( $response->id ) ) {
708
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id );
706
+		} elseif ( ! empty($response->id)) {
707
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id);
709 708
 
710
-			$amount = wc_price( $response->amount / 100 );
709
+			$amount = wc_price($response->amount / 100);
711 710
 
712
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
713
-				$amount = wc_price( $response->amount );
711
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
712
+				$amount = wc_price($response->amount);
714 713
 			}
715 714
 
716
-			if ( isset( $response->balance_transaction ) ) {
717
-				$this->update_fees( $order, $response->balance_transaction );
715
+			if (isset($response->balance_transaction)) {
716
+				$this->update_fees($order, $response->balance_transaction);
718 717
 			}
719 718
 
720 719
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
721
-			$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' );
720
+			$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe');
722 721
 
723
-			$order->add_order_note( $refund_message );
724
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
722
+			$order->add_order_note($refund_message);
723
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
725 724
 
726 725
 			return true;
727 726
 		}
@@ -736,44 +735,44 @@  discard block
 block discarded – undo
736 735
 	 */
737 736
 	public function add_payment_method() {
738 737
 		$error     = false;
739
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
738
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
740 739
 		$source_id = '';
741 740
 
742
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
741
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
743 742
 			$error = true;
744 743
 		}
745 744
 
746
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
745
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
747 746
 
748
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
747
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
749 748
 
750
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
749
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
751 750
 
752
-		if ( isset( $source_object ) ) {
753
-			if ( ! empty( $source_object->error ) ) {
751
+		if (isset($source_object)) {
752
+			if ( ! empty($source_object->error)) {
754 753
 				$error = true;
755 754
 			}
756 755
 
757 756
 			$source_id = $source_object->id;
758
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
759
-			$source_id = wc_clean( $_POST['stripe_token'] );
757
+		} elseif (isset($_POST['stripe_token'])) {
758
+			$source_id = wc_clean($_POST['stripe_token']);
760 759
 		}
761 760
 
762
-		$response = $stripe_customer->add_source( $source_id );
761
+		$response = $stripe_customer->add_source($source_id);
763 762
 
764
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
763
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
765 764
 			$error = true;
766 765
 		}
767 766
 
768
-		if ( $error ) {
769
-			wc_add_notice( $error_msg, 'error' );
770
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
767
+		if ($error) {
768
+			wc_add_notice($error_msg, 'error');
769
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
771 770
 			return;
772 771
 		}
773 772
 
774 773
 		return array(
775 774
 			'result'   => 'success',
776
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
775
+			'redirect' => wc_get_endpoint_url('payment-methods'),
777 776
 		);
778 777
 	}
779 778
 }
Please login to merge, or discard this patch.