Completed
Pull Request — master (#488)
by Roy
02:47
created
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
 
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 	public function __construct() {
21 21
 		self::$_this = $this;
22 22
 
23
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
24
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
25
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
26
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
28
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
23
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
24
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
25
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
26
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
27
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
28
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
29 29
 	}
30 30
 
31 31
 	/**
@@ -46,25 +46,25 @@  discard block
 block discarded – undo
46 46
 	 * @since 4.0.0
47 47
 	 * @version 4.0.0
48 48
 	 */
49
-	public function process_redirect_payment( $order_id, $retry = true ) {
49
+	public function process_redirect_payment($order_id, $retry = true) {
50 50
 		try {
51
-			$source = wc_clean( $_GET['source'] );
51
+			$source = wc_clean($_GET['source']);
52 52
 
53
-			if ( empty( $source ) ) {
53
+			if (empty($source)) {
54 54
 				return;
55 55
 			}
56 56
 
57
-			if ( empty( $order_id ) ) {
57
+			if (empty($order_id)) {
58 58
 				return;
59 59
 			}
60 60
 
61
-			$order = wc_get_order( $order_id );
61
+			$order = wc_get_order($order_id);
62 62
 
63
-			if ( ! is_object( $order ) ) {
63
+			if ( ! is_object($order)) {
64 64
 				return;
65 65
 			}
66 66
 
67
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
67
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
68 68
 				return;
69 69
 			}
70 70
 
@@ -72,108 +72,108 @@  discard block
 block discarded – undo
72 72
 			$response = null;
73 73
 
74 74
 			// This will throw exception if not valid.
75
-			$this->validate_minimum_order_amount( $order );
75
+			$this->validate_minimum_order_amount($order);
76 76
 
77
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
77
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
78 78
 
79 79
 			/**
80 80
 			 * First check if the source is chargeable at this time. If not,
81 81
 			 * webhook will take care of it later.
82 82
 			 */
83
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
83
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
84 84
 
85
-			if ( ! empty( $source_info->error ) ) {
86
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
85
+			if ( ! empty($source_info->error)) {
86
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
87 87
 			}
88 88
 
89
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
90
-				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' ) );
89
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
90
+				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'));
91 91
 			}
92 92
 
93 93
 			// If already consumed, then ignore request.
94
-			if ( 'consumed' === $source_info->status ) {
94
+			if ('consumed' === $source_info->status) {
95 95
 				return;
96 96
 			}
97 97
 
98 98
 			// If not chargeable, then ignore request.
99
-			if ( 'chargeable' !== $source_info->status ) {
99
+			if ('chargeable' !== $source_info->status) {
100 100
 				return;
101 101
 			}
102 102
 
103 103
 			// Prep source object.
104 104
 			$source_object           = new stdClass();
105 105
 			$source_object->token_id = '';
106
-			$source_object->customer = $this->get_stripe_customer_id( $order );
106
+			$source_object->customer = $this->get_stripe_customer_id($order);
107 107
 			$source_object->source   = $source_info->id;
108 108
 
109 109
 			// Make the request.
110
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
110
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
111 111
 
112
-			if ( ! empty( $response->error ) ) {
112
+			if ( ! empty($response->error)) {
113 113
 				// If it is an API error such connection or server, let's retry.
114
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
115
-					if ( $retry ) {
116
-						sleep( 5 );
117
-						return $this->process_redirect_payment( $order_id, false );
114
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
115
+					if ($retry) {
116
+						sleep(5);
117
+						return $this->process_redirect_payment($order_id, false);
118 118
 					} else {
119 119
 						$message = 'API connection error and retries exhausted.';
120
-						$order->add_order_note( $message );
121
-						throw new WC_Stripe_Exception( print_r( $response, true ), $message );
120
+						$order->add_order_note($message);
121
+						throw new WC_Stripe_Exception(print_r($response, true), $message);
122 122
 					}
123 123
 				}
124 124
 
125 125
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
126
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
127
-					if ( WC_Stripe_Helper::is_pre_30() ) {
128
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
129
-						delete_post_meta( $order_id, '_stripe_customer_id' );
126
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
127
+					if (WC_Stripe_Helper::is_pre_30()) {
128
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
129
+						delete_post_meta($order_id, '_stripe_customer_id');
130 130
 					} else {
131
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
132
-						$order->delete_meta_data( '_stripe_customer_id' );
131
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
132
+						$order->delete_meta_data('_stripe_customer_id');
133 133
 						$order->save();
134 134
 					}
135 135
 
136
-					return $this->process_redirect_payment( $order_id, false );
136
+					return $this->process_redirect_payment($order_id, false);
137 137
 
138
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
138
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
139 139
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
140 140
 
141
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
141
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
142 142
 					$wc_token->delete();
143
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
144
-					$order->add_order_note( $message );
145
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
143
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
144
+					$order->add_order_note($message);
145
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
146 146
 				}
147 147
 
148 148
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
149 149
 
150
-				if ( 'card_error' === $response->error->type ) {
151
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
150
+				if ('card_error' === $response->error->type) {
151
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
152 152
 				} else {
153
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
153
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
154 154
 				}
155 155
 
156
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
156
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
157 157
 			}
158 158
 
159
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
159
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
160 160
 
161
-			$this->process_response( $response, $order );
161
+			$this->process_response($response, $order);
162 162
 
163
-		} catch ( WC_Stripe_Exception $e ) {
164
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
163
+		} catch (WC_Stripe_Exception $e) {
164
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
165 165
 
166
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
166
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
167 167
 
168 168
 			/* translators: error message */
169
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
169
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
170 170
 
171
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
172
-				$this->send_failed_order_email( $order_id );
171
+			if ($order->has_status(array('pending', 'failed'))) {
172
+				$this->send_failed_order_email($order_id);
173 173
 			}
174 174
 
175
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
176
-			wp_safe_redirect( wc_get_checkout_url() );
175
+			wc_add_notice($e->getLocalizedMessage(), 'error');
176
+			wp_safe_redirect(wc_get_checkout_url());
177 177
 			exit;
178 178
 		}
179 179
 	}
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 	 * @version 4.0.0
186 186
 	 */
187 187
 	public function maybe_process_redirect_order() {
188
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
188
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
189 189
 			return;
190 190
 		}
191 191
 
192
-		$order_id = wc_clean( $_GET['order_id'] );
192
+		$order_id = wc_clean($_GET['order_id']);
193 193
 
194
-		$this->process_redirect_payment( $order_id );
194
+		$this->process_redirect_payment($order_id);
195 195
 	}
196 196
 
197 197
 	/**
@@ -201,52 +201,52 @@  discard block
 block discarded – undo
201 201
 	 * @version 4.0.0
202 202
 	 * @param  int $order_id
203 203
 	 */
204
-	public function capture_payment( $order_id ) {
205
-		$order = wc_get_order( $order_id );
204
+	public function capture_payment($order_id) {
205
+		$order = wc_get_order($order_id);
206 206
 
207
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
208
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
209
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
207
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
208
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
209
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
210 210
 
211
-			if ( $charge && 'no' === $captured ) {
211
+			if ($charge && 'no' === $captured) {
212 212
 				$order_total = $order->get_total();
213 213
 
214
-				if ( 0 < $order->get_total_refunded() ) {
214
+				if (0 < $order->get_total_refunded()) {
215 215
 					$order_total = $order_total - $order->get_total_refunded();
216 216
 				}
217 217
 
218
-				$result = WC_Stripe_API::request( array(
219
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
218
+				$result = WC_Stripe_API::request(array(
219
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
220 220
 					'expand[]' => 'balance_transaction',
221
-				), 'charges/' . $charge . '/capture' );
221
+				), 'charges/' . $charge . '/capture');
222 222
 
223
-				if ( ! empty( $result->error ) ) {
223
+				if ( ! empty($result->error)) {
224 224
 					/* translators: error message */
225
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
225
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
226 226
 				} else {
227 227
 					/* translators: transaction id */
228
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
229
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
228
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
229
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
230 230
 
231 231
 					// Store other data such as fees
232
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
232
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
233 233
 
234
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
234
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
235 235
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
236 236
 						// values are in the local currency of the Stripe account, not from WC.
237
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
238
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
239
-						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 );
240
-						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 );
237
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
238
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
239
+						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);
240
+						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);
241 241
 					}
242 242
 
243
-					if ( is_callable( array( $order, 'save' ) ) ) {
243
+					if (is_callable(array($order, 'save'))) {
244 244
 						$order->save();
245 245
 					}
246 246
 				}
247 247
 
248 248
 				// This hook fires when admin manually changes order status to processing or completed.
249
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
249
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
250 250
 			}
251 251
 		}
252 252
 	}
@@ -258,32 +258,32 @@  discard block
 block discarded – undo
258 258
 	 * @version 4.0.0
259 259
 	 * @param  int $order_id
260 260
 	 */
261
-	public function cancel_payment( $order_id ) {
262
-		$order = wc_get_order( $order_id );
261
+	public function cancel_payment($order_id) {
262
+		$order = wc_get_order($order_id);
263 263
 
264
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
265
-			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
264
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
265
+			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
266 266
 
267
-			if ( $charge_id ) {
268
-				$result = WC_Stripe_API::request( array(
269
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
270
-				), 'charges/' . $charge_id . '/refund' );
267
+			if ($charge_id) {
268
+				$result = WC_Stripe_API::request(array(
269
+					'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
270
+				), 'charges/' . $charge_id . '/refund');
271 271
 
272
-				if ( ! empty( $result->error ) ) {
273
-					$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->error->message );
272
+				if ( ! empty($result->error)) {
273
+					$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->error->message);
274 274
 				} else {
275 275
 					/* translators: transaction id */
276
-					$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
277
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_stripe_charge_captured' ) : $order->delete_meta_data( '_stripe_charge_captured' );
278
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_transaction_id' ) : $order->delete_meta_data( '_stripe_transaction_id' );
276
+					$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
277
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_stripe_charge_captured') : $order->delete_meta_data('_stripe_charge_captured');
278
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_transaction_id') : $order->delete_meta_data('_stripe_transaction_id');
279 279
 
280
-					if ( is_callable( array( $order, 'save' ) ) ) {
280
+					if (is_callable(array($order, 'save'))) {
281 281
 						$order->save();
282 282
 					}
283 283
 				}
284 284
 
285 285
 				// This hook fires when admin manually changes order status to cancel.
286
-				do_action( 'woocommerce_stripe_process_manual_cancel', $order, $result );
286
+				do_action('woocommerce_stripe_process_manual_cancel', $order, $result);
287 287
 			}
288 288
 		}
289 289
 	}
@@ -296,21 +296,21 @@  discard block
 block discarded – undo
296 296
 	 * @param string $field
297 297
 	 * @return string $error_field
298 298
 	 */
299
-	public function normalize_field( $field ) {
299
+	public function normalize_field($field) {
300 300
 		$checkout_fields = WC()->checkout->get_checkout_fields();
301 301
 		$org_str         = array();
302 302
 		$replace_str     = array();
303 303
 
304
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
305
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
306
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
307
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
308
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
309
-			$error_field = $checkout_fields['order'][ $field ]['label'];
310
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
311
-			$error_field = $checkout_fields['account'][ $field ]['label'];
304
+		if (array_key_exists($field, $checkout_fields['billing'])) {
305
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
306
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
307
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
308
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
309
+			$error_field = $checkout_fields['order'][$field]['label'];
310
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
311
+			$error_field = $checkout_fields['account'][$field]['label'];
312 312
 		} else {
313
-			$error_field = str_replace( '_', ' ', $field );
313
+			$error_field = str_replace('_', ' ', $field);
314 314
 
315 315
 			$org_str[]     = 'stripe';
316 316
 			$replace_str[] = '';
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 			$replace_str[] = 'SOFORT';
326 326
 
327 327
 			$org_str[]     = 'owner';
328
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
328
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
329 329
 
330
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
330
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
331 331
 		}
332 332
 
333 333
 		return $error_field;
@@ -340,138 +340,138 @@  discard block
 block discarded – undo
340 340
 	 * @version 4.0.0
341 341
 	 */
342 342
 	public function validate_checkout() {
343
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
344
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
343
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
344
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
345 345
 		}
346 346
 
347 347
 		$errors = new WP_Error();
348
-		parse_str( $_POST['required_fields'], $required_fields );
349
-		parse_str( $_POST['all_fields'], $all_fields );
350
-		$source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : '';
348
+		parse_str($_POST['required_fields'], $required_fields);
349
+		parse_str($_POST['all_fields'], $all_fields);
350
+		$source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : '';
351 351
 		$validate_shipping_fields = false;
352 352
 		$create_account = false;
353 353
 
354
-		$all_fields      = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
355
-		$required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
354
+		$all_fields      = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
355
+		$required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
356 356
 
357
-		array_walk_recursive( $required_fields, 'wc_clean' );
358
-		array_walk_recursive( $all_fields, 'wc_clean' );
357
+		array_walk_recursive($required_fields, 'wc_clean');
358
+		array_walk_recursive($all_fields, 'wc_clean');
359 359
 
360 360
 		/**
361 361
 		 * If ship to different address checkbox is checked then we need
362 362
 		 * to validate shipping fields too.
363 363
 		 */
364
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
364
+		if (isset($all_fields['ship_to_different_address'])) {
365 365
 			$validate_shipping_fields = true;
366 366
 		}
367 367
 
368 368
 		// Check if createaccount is checked.
369
-		if ( isset( $all_fields['createaccount'] ) ) {
369
+		if (isset($all_fields['createaccount'])) {
370 370
 			$create_account = true;
371 371
 		}
372 372
 
373 373
 		// Check if required fields are empty.
374
-		foreach ( $required_fields as $field => $field_value ) {
374
+		foreach ($required_fields as $field => $field_value) {
375 375
 			// Check for shipping field.
376
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
376
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
377 377
 				continue;
378 378
 			}
379 379
 
380 380
 			// Check create account name.
381
-			if ( 'account_username' === $field && ! $create_account ) {
381
+			if ('account_username' === $field && ! $create_account) {
382 382
 				continue;
383 383
 			}
384 384
 
385 385
 			// Check create account password.
386
-			if ( 'account_password' === $field && ! $create_account ) {
386
+			if ('account_password' === $field && ! $create_account) {
387 387
 				continue;
388 388
 			}
389 389
 
390
-			if ( empty( $field_value ) || '-1' === $field_value ) {
391
-				$error_field = $this->normalize_field( $field );
390
+			if (empty($field_value) || '-1' === $field_value) {
391
+				$error_field = $this->normalize_field($field);
392 392
 				/* translators: error field name */
393
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
393
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
394 394
 			}
395 395
 		}
396 396
 
397 397
 		// Check if email is valid format.
398
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
399
-			$errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) );
398
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
399
+			$errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe'));
400 400
 		}
401 401
 
402 402
 		// Check if phone number is valid format.
403
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
404
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
403
+		if ( ! empty($required_fields['billing_phone'])) {
404
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
405 405
 
406
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
406
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
407 407
 				/* translators: %s: phone number */
408
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
408
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
409 409
 			}
410 410
 		}
411 411
 
412 412
 		// Check if postal code is valid format.
413
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
414
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
415
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
413
+		if ( ! empty($required_fields['billing_postcode'])) {
414
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
415
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
416 416
 
417
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
418
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
417
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
418
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
419 419
 			}
420 420
 		}
421 421
 
422 422
 		// Don't check this on add payment method page.
423
-		if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) {
424
-			if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
425
-				$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
423
+		if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) {
424
+			if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
425
+				$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
426 426
 			}
427 427
 		}
428 428
 
429
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
429
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
430 430
 			// Check if postal code is valid format.
431
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
432
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
433
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
431
+			if ( ! empty($required_fields['shipping_postcode'])) {
432
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
433
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
434 434
 
435
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
436
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
435
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
436
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
437 437
 				}
438 438
 			}
439 439
 		}
440 440
 
441
-		if ( WC()->cart->needs_shipping() ) {
441
+		if (WC()->cart->needs_shipping()) {
442 442
 			$shipping_country = WC()->customer->get_shipping_country();
443 443
 
444
-			if ( empty( $shipping_country ) ) {
445
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
446
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
444
+			if (empty($shipping_country)) {
445
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
446
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
447 447
 				/* translators: country name */
448
-				$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() ) );
448
+				$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()));
449 449
 			} else {
450
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
450
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
451 451
 
452
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
453
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
454
-						$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' ) );
452
+				foreach (WC()->shipping->get_packages() as $i => $package) {
453
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
454
+						$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 455
 					}
456 456
 				}
457 457
 			}
458 458
 		}
459 459
 
460
-		if ( WC()->cart->needs_payment() ) {
460
+		if (WC()->cart->needs_payment()) {
461 461
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
462 462
 
463
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
464
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
463
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
464
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
465 465
 			} else {
466
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
466
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
467 467
 			}
468 468
 		}
469 469
 
470
-		if ( 0 === count( $errors->errors ) ) {
471
-			wp_send_json( 'success' );
470
+		if (0 === count($errors->errors)) {
471
+			wp_send_json('success');
472 472
 		} else {
473
-			foreach ( $errors->get_error_messages() as $message ) {
474
-				wc_add_notice( $message, 'error' );
473
+			foreach ($errors->get_error_messages() as $message) {
474
+				wc_add_notice($message, 'error');
475 475
 			}
476 476
 
477 477
 			$this->send_ajax_failure_response();
@@ -485,9 +485,9 @@  discard block
 block discarded – undo
485 485
 	 * @version 4.0.0
486 486
 	 */
487 487
 	public function send_ajax_failure_response() {
488
-		if ( is_ajax() ) {
488
+		if (is_ajax()) {
489 489
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
490
-			if ( ! isset( WC()->session->reload_checkout ) ) {
490
+			if ( ! isset(WC()->session->reload_checkout)) {
491 491
 				ob_start();
492 492
 				wc_print_notices();
493 493
 				$messages = ob_get_clean();
@@ -495,14 +495,14 @@  discard block
 block discarded – undo
495 495
 
496 496
 			$response = array(
497 497
 				'result'   => 'failure',
498
-				'messages' => isset( $messages ) ? $messages : '',
499
-				'refresh'  => isset( WC()->session->refresh_totals ),
500
-				'reload'   => isset( WC()->session->reload_checkout ),
498
+				'messages' => isset($messages) ? $messages : '',
499
+				'refresh'  => isset(WC()->session->refresh_totals),
500
+				'reload'   => isset(WC()->session->reload_checkout),
501 501
 			);
502 502
 
503
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
503
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
504 504
 
505
-			wp_send_json( $response );
505
+			wp_send_json($response);
506 506
 		}
507 507
 	}
508 508
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +25 added lines, -25 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,13 +95,13 @@  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
-			$headers['Idempotency-Key'] = uniqid( 'stripe_' );
103
+		if ('charges' === $api && 'POST' === $method) {
104
+			$headers['Idempotency-Key'] = uniqid('stripe_');
105 105
 		}
106 106
 
107 107
 		$response = wp_safe_remote_post(
@@ -109,17 +109,17 @@  discard block
 block discarded – undo
109 109
 			array(
110 110
 				'method'  => $method,
111 111
 				'headers' => $headers,
112
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
112
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
113 113
 				'timeout' => 70,
114 114
 			)
115 115
 		);
116 116
 
117
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
118
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
119
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
117
+		if (is_wp_error($response) || empty($response['body'])) {
118
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
119
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
120 120
 		}
121 121
 
122
-		return json_decode( $response['body'] );
122
+		return json_decode($response['body']);
123 123
 	}
124 124
 
125 125
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @version 4.0.0
130 130
 	 * @param string $api
131 131
 	 */
132
-	public static function retrieve( $api ) {
133
-		WC_Stripe_Logger::log( "{$api}" );
132
+	public static function retrieve($api) {
133
+		WC_Stripe_Logger::log("{$api}");
134 134
 
135 135
 		$response = wp_safe_remote_get(
136 136
 			self::ENDPOINT . $api,
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 			)
142 142
 		);
143 143
 
144
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
145
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
146
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
144
+		if (is_wp_error($response) || empty($response['body'])) {
145
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
146
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
147 147
 		}
148 148
 
149
-		return json_decode( $response['body'] );
149
+		return json_decode($response['body']);
150 150
 	}
151 151
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +147 added lines, -147 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
 
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 * @version 4.0.0
18 18
 	 */
19 19
 	public function __construct() {
20
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
20
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
21 21
 	}
22 22
 
23 23
 	/**
@@ -27,24 +27,24 @@  discard block
 block discarded – undo
27 27
 	 * @version 4.0.0
28 28
 	 */
29 29
 	public function check_for_webhook() {
30
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
31
-			|| ! isset( $_GET['wc-api'] )
32
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
30
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
31
+			|| ! isset($_GET['wc-api'])
32
+			|| ('wc_stripe' !== $_GET['wc-api'])
33 33
 		) {
34 34
 			return;
35 35
 		}
36 36
 
37
-		$request_body    = file_get_contents( 'php://input' );
38
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
37
+		$request_body    = file_get_contents('php://input');
38
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
39 39
 
40 40
 		// Validate it to make sure it is legit.
41
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
42
-			$this->process_webhook( $request_body );
43
-			status_header( 200 );
41
+		if ($this->is_valid_request($request_headers, $request_body)) {
42
+			$this->process_webhook($request_body);
43
+			status_header(200);
44 44
 			exit;
45 45
 		} else {
46
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
47
-			status_header( 400 );
46
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
47
+			status_header(400);
48 48
 			exit;
49 49
 		}
50 50
 	}
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
 	 * @param string $request_body The request body from Stripe.
60 60
 	 * @return bool
61 61
 	 */
62
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
63
-		if ( null === $request_headers || null === $request_body ) {
62
+	public function is_valid_request($request_headers = null, $request_body = null) {
63
+		if (null === $request_headers || null === $request_body) {
64 64
 			return false;
65 65
 		}
66 66
 
67
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
67
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
68 68
 			return false;
69 69
 		}
70 70
 
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	 * @version 4.0.0
81 81
 	 */
82 82
 	public function get_request_headers() {
83
-		if ( ! function_exists( 'getallheaders' ) ) {
83
+		if ( ! function_exists('getallheaders')) {
84 84
 			$headers = [];
85
-			foreach ( $_SERVER as $name => $value ) {
86
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
87
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
85
+			foreach ($_SERVER as $name => $value) {
86
+				if ('HTTP_' === substr($name, 0, 5)) {
87
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
88 88
 				}
89 89
 			}
90 90
 
@@ -103,30 +103,30 @@  discard block
 block discarded – undo
103 103
 	 * @param object $notification
104 104
 	 * @param bool $retry
105 105
 	 */
106
-	public function process_webhook_payment( $notification, $retry = true ) {
106
+	public function process_webhook_payment($notification, $retry = true) {
107 107
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
108
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
108
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
109 109
 			return;
110 110
 		}
111 111
 
112
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
112
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
113 113
 
114
-		if ( ! $order ) {
115
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
114
+		if ( ! $order) {
115
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
120 120
 		$source_id = $notification->data->object->id;
121 121
 
122
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
122
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
123 123
 
124 124
 		try {
125
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
125
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
126 126
 				return;
127 127
 			}
128 128
 
129
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
129
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
130 130
 				return;
131 131
 			}
132 132
 
@@ -134,80 +134,80 @@  discard block
 block discarded – undo
134 134
 			$response = null;
135 135
 
136 136
 			// This will throw exception if not valid.
137
-			$this->validate_minimum_order_amount( $order );
137
+			$this->validate_minimum_order_amount($order);
138 138
 
139
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
139
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
140 140
 
141 141
 			// Prep source object.
142 142
 			$source_object           = new stdClass();
143 143
 			$source_object->token_id = '';
144
-			$source_object->customer = $this->get_stripe_customer_id( $order );
144
+			$source_object->customer = $this->get_stripe_customer_id($order);
145 145
 			$source_object->source   = $source_id;
146 146
 
147 147
 			// Make the request.
148
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
148
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
149 149
 
150
-			if ( ! empty( $response->error ) ) {
150
+			if ( ! empty($response->error)) {
151 151
 				// If it is an API error such connection or server, let's retry.
152
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
153
-					if ( $retry ) {
154
-						sleep( 5 );
155
-						return $this->process_payment( $order_id, false );
152
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
153
+					if ($retry) {
154
+						sleep(5);
155
+						return $this->process_payment($order_id, false);
156 156
 					} else {
157 157
 						$localized_message = 'API connection error and retries exhausted.';
158
-						$order->add_order_note( $localized_message );
159
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
158
+						$order->add_order_note($localized_message);
159
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
160 160
 					}
161 161
 				}
162 162
 
163 163
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
164
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
165
-					if ( WC_Stripe_Helper::is_pre_30() ) {
166
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
167
-						delete_post_meta( $order_id, '_stripe_customer_id' );
164
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
165
+					if (WC_Stripe_Helper::is_pre_30()) {
166
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
167
+						delete_post_meta($order_id, '_stripe_customer_id');
168 168
 					} else {
169
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
170
-						$order->delete_meta_data( '_stripe_customer_id' );
169
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
170
+						$order->delete_meta_data('_stripe_customer_id');
171 171
 						$order->save();
172 172
 					}
173 173
 
174
-					return $this->process_payment( $order_id, false );
174
+					return $this->process_payment($order_id, false);
175 175
 
176
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
176
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
177 177
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
178
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
178
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
179 179
 					$wc_token->delete();
180
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
181
-					$order->add_order_note( $message );
182
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
180
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
181
+					$order->add_order_note($message);
182
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
183 183
 				}
184 184
 
185 185
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
186 186
 
187
-				if ( 'card_error' === $response->error->type ) {
188
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
187
+				if ('card_error' === $response->error->type) {
188
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
189 189
 				} else {
190
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
190
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
191 191
 				}
192 192
 
193
-				$order->add_order_note( $localized_message );
193
+				$order->add_order_note($localized_message);
194 194
 
195
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
195
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
196 196
 			}
197 197
 
198
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
198
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
199 199
 
200
-			$this->process_response( $response, $order );
200
+			$this->process_response($response, $order);
201 201
 
202
-		} catch ( WC_Stripe_Exception $e ) {
203
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
202
+		} catch (WC_Stripe_Exception $e) {
203
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
204 204
 
205
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
205
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
206 206
 
207
-			$statuses = array( 'pending', 'failed' );
207
+			$statuses = array('pending', 'failed');
208 208
 
209
-			if ( $order->has_status( $statuses ) ) {
210
-				$this->send_failed_order_email( $order_id );
209
+			if ($order->has_status($statuses)) {
210
+				$this->send_failed_order_email($order_id);
211 211
 			}
212 212
 		}
213 213
 	}
@@ -221,18 +221,18 @@  discard block
 block discarded – undo
221 221
 	 * @version 4.0.0
222 222
 	 * @param object $notification
223 223
 	 */
224
-	public function process_webhook_dispute( $notification ) {
225
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
224
+	public function process_webhook_dispute($notification) {
225
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
226 226
 
227
-		if ( ! $order ) {
228
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
227
+		if ( ! $order) {
228
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
229 229
 			return;
230 230
 		}
231 231
 
232
-		$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' ) );
232
+		$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'));
233 233
 
234
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
235
-		$this->send_failed_order_email( $order_id );
234
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
235
+		$this->send_failed_order_email($order_id);
236 236
 	}
237 237
 
238 238
 	/**
@@ -243,41 +243,41 @@  discard block
 block discarded – undo
243 243
 	 * @version 4.0.0
244 244
 	 * @param object $notification
245 245
 	 */
246
-	public function process_webhook_capture( $notification ) {
247
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
246
+	public function process_webhook_capture($notification) {
247
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
248 248
 
249
-		if ( ! $order ) {
250
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
249
+		if ( ! $order) {
250
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
251 251
 			return;
252 252
 		}
253 253
 
254 254
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
255 255
 
256
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
257
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
258
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
256
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
257
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
258
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
259 259
 
260
-			if ( $charge && 'no' === $captured ) {
261
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
260
+			if ($charge && 'no' === $captured) {
261
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
262 262
 
263 263
 				// Store other data such as fees
264
-				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 );
264
+				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);
265 265
 
266
-				if ( isset( $notification->data->object->balance_transaction ) ) {
267
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
266
+				if (isset($notification->data->object->balance_transaction)) {
267
+					$this->update_fees($order, $notification->data->object->balance_transaction);
268 268
 				}
269 269
 
270
-				if ( is_callable( array( $order, 'save' ) ) ) {
270
+				if (is_callable(array($order, 'save'))) {
271 271
 					$order->save();
272 272
 				}
273 273
 
274 274
 				/* translators: transaction id */
275
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
275
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
276 276
 
277 277
 				// Check and see if capture is partial.
278
-				if ( $this->is_partial_capture( $notification ) ) {
279
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
280
-					$order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
278
+				if ($this->is_partial_capture($notification)) {
279
+					$order->set_total($this->get_partial_amount_to_charge($notification));
280
+					$order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
281 281
 					$order->save();
282 282
 				}
283 283
 			}
@@ -292,38 +292,38 @@  discard block
 block discarded – undo
292 292
 	 * @version 4.0.0
293 293
 	 * @param object $notification
294 294
 	 */
295
-	public function process_webhook_charge_succeeded( $notification ) {
295
+	public function process_webhook_charge_succeeded($notification) {
296 296
 		// The following payment methods are synchronous so does not need to be handle via webhook.
297
-		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 ) ) {
297
+		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)) {
298 298
 			return;
299 299
 		}
300 300
 
301
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
301
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
302 302
 
303
-		if ( ! $order ) {
304
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
303
+		if ( ! $order) {
304
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
305 305
 			return;
306 306
 		}
307 307
 
308 308
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
309 309
 
310
-		if ( 'on-hold' !== $order->get_status() ) {
310
+		if ('on-hold' !== $order->get_status()) {
311 311
 			return;
312 312
 		}
313 313
 
314 314
 		// Store other data such as fees
315
-		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 );
315
+		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);
316 316
 
317
-		if ( isset( $notification->data->object->balance_transaction ) ) {
318
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
317
+		if (isset($notification->data->object->balance_transaction)) {
318
+			$this->update_fees($order, $notification->data->object->balance_transaction);
319 319
 		}
320 320
 
321
-		if ( is_callable( array( $order, 'save' ) ) ) {
321
+		if (is_callable(array($order, 'save'))) {
322 322
 			$order->save();
323 323
 		}
324 324
 
325 325
 		/* translators: transaction id */
326
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
326
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
327 327
 	}
328 328
 
329 329
 	/**
@@ -334,23 +334,23 @@  discard block
 block discarded – undo
334 334
 	 * @version 4.0.0
335 335
 	 * @param object $notification
336 336
 	 */
337
-	public function process_webhook_charge_failed( $notification ) {
338
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
337
+	public function process_webhook_charge_failed($notification) {
338
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
339 339
 
340
-		if ( ! $order ) {
341
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
340
+		if ( ! $order) {
341
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
342 342
 			return;
343 343
 		}
344 344
 
345 345
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
346 346
 
347
-		if ( 'on-hold' !== $order->get_status() ) {
347
+		if ('on-hold' !== $order->get_status()) {
348 348
 			return;
349 349
 		}
350 350
 
351
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
351
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
352 352
 
353
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
353
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
354 354
 	}
355 355
 
356 356
 	/**
@@ -361,23 +361,23 @@  discard block
 block discarded – undo
361 361
 	 * @version 4.0.0
362 362
 	 * @param object $notification
363 363
 	 */
364
-	public function process_webhook_source_canceled( $notification ) {
365
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
364
+	public function process_webhook_source_canceled($notification) {
365
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
366 366
 
367
-		if ( ! $order ) {
368
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
367
+		if ( ! $order) {
368
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
369 369
 			return;
370 370
 		}
371 371
 
372 372
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
373 373
 
374
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
374
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
375 375
 			return;
376 376
 		}
377 377
 
378
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
378
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
379 379
 
380
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
380
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
381 381
 	}
382 382
 
383 383
 	/**
@@ -388,37 +388,37 @@  discard block
 block discarded – undo
388 388
 	 * @version 4.0.0
389 389
 	 * @param object $notification
390 390
 	 */
391
-	public function process_webhook_refund( $notification ) {
392
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
391
+	public function process_webhook_refund($notification) {
392
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
393 393
 
394
-		if ( ! $order ) {
395
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
394
+		if ( ! $order) {
395
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
396 396
 			return;
397 397
 		}
398 398
 
399 399
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
400 400
 
401
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
402
-			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
403
-			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
404
-			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
401
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
402
+			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
403
+			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
404
+			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
405 405
 
406 406
 			// If the refund ID matches, don't continue to prevent double refunding.
407
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
407
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
408 408
 				return;
409 409
 			}
410 410
 
411 411
 			// Only refund captured charge.
412
-			if ( $charge && 'yes' === $captured ) {
412
+			if ($charge && 'yes' === $captured) {
413 413
 				// Create the refund.
414
-				$refund = wc_create_refund( array(
414
+				$refund = wc_create_refund(array(
415 415
 					'order_id'       => $order_id,
416
-					'amount'         => $this->get_refund_amount( $notification ),
417
-					'reason'         => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ),
418
-				) );
416
+					'amount'         => $this->get_refund_amount($notification),
417
+					'reason'         => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'),
418
+				));
419 419
 
420
-				if ( is_wp_error( $refund ) ) {
421
-					WC_Stripe_Logger::log( $refund->get_error_message() );
420
+				if (is_wp_error($refund)) {
421
+					WC_Stripe_Logger::log($refund->get_error_message());
422 422
 				}
423 423
 			}
424 424
 		}
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	 * @version 4.0.0
432 432
 	 * @param object $notification
433 433
 	 */
434
-	public function is_partial_capture( $notification ) {
434
+	public function is_partial_capture($notification) {
435 435
 		return 0 < $notification->data->object->amount_refunded;
436 436
 	}
437 437
 
@@ -442,11 +442,11 @@  discard block
 block discarded – undo
442 442
 	 * @version 4.0.0
443 443
 	 * @param object $notification
444 444
 	 */
445
-	public function get_refund_amount( $notification ) {
446
-		if ( $this->is_partial_capture( $notification ) ) {
445
+	public function get_refund_amount($notification) {
446
+		if ($this->is_partial_capture($notification)) {
447 447
 			$amount = $notification->data->object->amount_refunded / 100;
448 448
 
449
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
449
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
450 450
 				$amount = $notification->data->object->amount_refunded;
451 451
 			}
452 452
 
@@ -463,12 +463,12 @@  discard block
 block discarded – undo
463 463
 	 * @version 4.0.0
464 464
 	 * @param object $notification
465 465
 	 */
466
-	public function get_partial_amount_to_charge( $notification ) {
467
-		if ( $this->is_partial_capture( $notification ) ) {
468
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
466
+	public function get_partial_amount_to_charge($notification) {
467
+		if ($this->is_partial_capture($notification)) {
468
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
469 469
 
470
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
471
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
470
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
471
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
472 472
 			}
473 473
 
474 474
 			return $amount;
@@ -484,36 +484,36 @@  discard block
 block discarded – undo
484 484
 	 * @version 4.0.0
485 485
 	 * @param string $request_body
486 486
 	 */
487
-	public function process_webhook( $request_body ) {
488
-		$notification = json_decode( $request_body );
487
+	public function process_webhook($request_body) {
488
+		$notification = json_decode($request_body);
489 489
 
490
-		switch ( $notification->type ) {
490
+		switch ($notification->type) {
491 491
 			case 'source.chargeable':
492
-				$this->process_webhook_payment( $notification );
492
+				$this->process_webhook_payment($notification);
493 493
 				break;
494 494
 
495 495
 			case 'source.canceled':
496
-				$this->process_webhook_source_canceled( $notification );
496
+				$this->process_webhook_source_canceled($notification);
497 497
 				break;
498 498
 
499 499
 			case 'charge.succeeded':
500
-				$this->process_webhook_charge_succeeded( $notification );
500
+				$this->process_webhook_charge_succeeded($notification);
501 501
 				break;
502 502
 
503 503
 			case 'charge.failed':
504
-				$this->process_webhook_charge_failed( $notification );
504
+				$this->process_webhook_charge_failed($notification);
505 505
 				break;
506 506
 
507 507
 			case 'charge.captured':
508
-				$this->process_webhook_capture( $notification );
508
+				$this->process_webhook_capture($notification);
509 509
 				break;
510 510
 
511 511
 			case 'charge.dispute.created':
512
-				$this->process_webhook_dispute( $notification );
512
+				$this->process_webhook_dispute($notification);
513 513
 				break;
514 514
 
515 515
 			case 'charge.refunded':
516
-				$this->process_webhook_refund( $notification );
516
+				$this->process_webhook_refund($notification);
517 517
 				break;
518 518
 
519 519
 		}
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +198 added lines, -198 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
 
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	public function __construct() {
114 114
 		$this->id                   = 'stripe';
115
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
115
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
116 116
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
117
-		$this->method_description   = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
117
+		$this->method_description   = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
118 118
 		$this->has_fields           = true;
119 119
 		$this->supports             = array(
120 120
 			'products',
@@ -141,37 +141,37 @@  discard block
 block discarded – undo
141 141
 		$this->init_settings();
142 142
 
143 143
 		// Get setting values.
144
-		$this->title                   = $this->get_option( 'title' );
145
-		$this->description             = $this->get_option( 'description' );
146
-		$this->enabled                 = $this->get_option( 'enabled' );
147
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
148
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
149
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
150
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
151
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
152
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
153
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
154
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
155
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
156
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
157
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
158
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
159
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
144
+		$this->title                   = $this->get_option('title');
145
+		$this->description             = $this->get_option('description');
146
+		$this->enabled                 = $this->get_option('enabled');
147
+		$this->testmode                = 'yes' === $this->get_option('testmode');
148
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
149
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
150
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
151
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
152
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
153
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
154
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
155
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
156
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
157
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
158
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
159
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
160 160
 		$this->apple_pay_verify_notice = '';
161 161
 
162
-		if ( $this->stripe_checkout ) {
163
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
162
+		if ($this->stripe_checkout) {
163
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
164 164
 		}
165 165
 
166
-		WC_Stripe_API::set_secret_key( $this->secret_key );
166
+		WC_Stripe_API::set_secret_key($this->secret_key);
167 167
 
168 168
 		$this->init_apple_pay();
169 169
 
170 170
 		// Hooks.
171
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
172
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
173
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
174
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
171
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
172
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
173
+		add_action('admin_notices', array($this, 'admin_notices'));
174
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
175 175
 	}
176 176
 
177 177
 	/**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 * @since 4.0.2
181 181
 	 */
182 182
 	public function is_available() {
183
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
183
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
184 184
 			return false;
185 185
 		}
186 186
 
@@ -203,17 +203,17 @@  discard block
 block discarded – undo
203 203
 		$icons_str .= $icons['amex'];
204 204
 		$icons_str .= $icons['mastercard'];
205 205
 
206
-		if ( 'USD' === get_woocommerce_currency() ) {
206
+		if ('USD' === get_woocommerce_currency()) {
207 207
 			$icons_str .= $icons['discover'];
208 208
 			$icons_str .= $icons['jcb'];
209 209
 			$icons_str .= $icons['diners'];
210 210
 		}
211 211
 
212
-		if ( $this->bitcoin && $this->stripe_checkout ) {
212
+		if ($this->bitcoin && $this->stripe_checkout) {
213 213
 			$icons_str .= $icons['bitcoin'];
214 214
 		}
215 215
 
216
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
216
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
217 217
 	}
218 218
 
219 219
 	/**
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
 	public function init_apple_pay() {
226 226
 		if (
227 227
 			is_admin() &&
228
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
229
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
230
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
228
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
229
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
230
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
231 231
 			$this->payment_request
232 232
 		) {
233 233
 			$this->process_apple_pay_verification();
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
 	 * @version 3.1.0
242 242
 	 * @param string $secret_key
243 243
 	 */
244
-	private function register_apple_pay_domain( $secret_key = '' ) {
245
-		if ( empty( $secret_key ) ) {
246
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
244
+	private function register_apple_pay_domain($secret_key = '') {
245
+		if (empty($secret_key)) {
246
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
247 247
 		}
248 248
 
249 249
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -257,23 +257,23 @@  discard block
 block discarded – undo
257 257
 			'Authorization' => 'Bearer ' . $secret_key,
258 258
 		);
259 259
 
260
-		$response = wp_remote_post( $endpoint, array(
260
+		$response = wp_remote_post($endpoint, array(
261 261
 			'headers' => $headers,
262
-			'body'    => http_build_query( $data ),
263
-		) );
262
+			'body'    => http_build_query($data),
263
+		));
264 264
 
265
-		if ( is_wp_error( $response ) ) {
265
+		if (is_wp_error($response)) {
266 266
 			/* translators: error message */
267
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
267
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
268 268
 		}
269 269
 
270
-		if ( 200 !== $response['response']['code'] ) {
271
-			$parsed_response = json_decode( $response['body'] );
270
+		if (200 !== $response['response']['code']) {
271
+			$parsed_response = json_decode($response['body']);
272 272
 
273 273
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
274 274
 
275 275
 			/* translators: error message */
276
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
276
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
277 277
 		}
278 278
 	}
279 279
 
@@ -284,48 +284,48 @@  discard block
 block discarded – undo
284 284
 	 * @version 3.1.0
285 285
 	 */
286 286
 	public function process_apple_pay_verification() {
287
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', array() );
287
+		$gateway_settings = get_option('woocommerce_stripe_settings', array());
288 288
 
289 289
 		try {
290
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
290
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
291 291
 			$dir      = '.well-known';
292 292
 			$file     = 'apple-developer-merchantid-domain-association';
293 293
 			$fullpath = $path . '/' . $dir . '/' . $file;
294 294
 
295
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
295
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
296 296
 				return;
297 297
 			}
298 298
 
299
-			if ( ! file_exists( $path . '/' . $dir ) ) {
300
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
301
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
299
+			if ( ! file_exists($path . '/' . $dir)) {
300
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
301
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
302 302
 				}
303 303
 			}
304 304
 
305
-			if ( ! file_exists( $fullpath ) ) {
306
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
307
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
305
+			if ( ! file_exists($fullpath)) {
306
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
307
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
308 308
 				}
309 309
 			}
310 310
 
311 311
 			// At this point then the domain association folder and file should be available.
312 312
 			// Proceed to verify/and or verify again.
313
-			$this->register_apple_pay_domain( $this->secret_key );
313
+			$this->register_apple_pay_domain($this->secret_key);
314 314
 
315 315
 			// No errors to this point, verification success!
316 316
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
317 317
 			$this->apple_pay_domain_set = true;
318 318
 
319
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
319
+			update_option('woocommerce_stripe_settings', $gateway_settings);
320 320
 
321
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
321
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
322 322
 
323
-		} catch ( Exception $e ) {
323
+		} catch (Exception $e) {
324 324
 			$gateway_settings['apple_pay_domain_set'] = 'no';
325 325
 
326
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
326
+			update_option('woocommerce_stripe_settings', $gateway_settings);
327 327
 
328
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
328
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
329 329
 		}
330 330
 	}
331 331
 
@@ -333,11 +333,11 @@  discard block
 block discarded – undo
333 333
 	 * Check if SSL is enabled and notify the user
334 334
 	 */
335 335
 	public function admin_notices() {
336
-		if ( 'no' === $this->enabled ) {
336
+		if ('no' === $this->enabled) {
337 337
 			return;
338 338
 		}
339 339
 
340
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
340
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
341 341
 			$allowed_html = array(
342 342
 				'a' => array(
343 343
 					'href' => array(),
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 				),
346 346
 			);
347 347
 
348
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
348
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
349 349
 		}
350 350
 
351 351
 		/**
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
 		 * when setting screen is displayed. So if domain verification is not set,
354 354
 		 * something went wrong so lets notify user.
355 355
 		 */
356
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
356
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
357 357
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
358
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
358
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
359 359
 		}
360 360
 	}
361 361
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 	 * Initialise Gateway Settings Form Fields
364 364
 	 */
365 365
 	public function init_form_fields() {
366
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
366
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
367 367
 	}
368 368
 
369 369
 	/**
@@ -371,59 +371,59 @@  discard block
 block discarded – undo
371 371
 	 */
372 372
 	public function payment_fields() {
373 373
 		$user                 = wp_get_current_user();
374
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
374
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
375 375
 		$total                = WC()->cart->total;
376 376
 		$user_email           = '';
377 377
 
378 378
 		// If paying from order, we need to get total from order not cart.
379
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
380
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
379
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
380
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
381 381
 			$total      = $order->get_total();
382 382
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
383 383
 		} else {
384
-			if ( $user->ID ) {
385
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
384
+			if ($user->ID) {
385
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
386 386
 				$user_email = $user_email ? $user_email : $user->user_email;
387 387
 			}
388 388
 		}
389 389
 
390
-		if ( is_add_payment_method_page() ) {
391
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
392
-			$total        = '';
390
+		if (is_add_payment_method_page()) {
391
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
392
+			$total = '';
393 393
 		} else {
394 394
 			$pay_button_text = '';
395 395
 		}
396 396
 
397 397
 		echo '<div
398 398
 			id="stripe-payment-data"
399
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
399
+			data-panel-label="' . esc_attr($pay_button_text) . '"
400 400
 			data-description=""
401
-			data-email="' . esc_attr( $user_email ) . '"
402
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
403
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
404
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
405
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
406
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
407
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', substr( get_locale(), 0, 2 ) ) ) . '"
408
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
409
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
410
-
411
-		if ( $this->description ) {
412
-			if ( $this->testmode ) {
401
+			data-email="' . esc_attr($user_email) . '"
402
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
403
+			data-name="' . esc_attr($this->statement_descriptor) . '"
404
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
405
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
406
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
407
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', substr(get_locale(), 0, 2))) . '"
408
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
409
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
410
+
411
+		if ($this->description) {
412
+			if ($this->testmode) {
413 413
 				/* translators: link to Stripe testing page */
414
-				$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
415
-				$this->description  = trim( $this->description );
414
+				$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
415
+				$this->description  = trim($this->description);
416 416
 			}
417
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
417
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
418 418
 		}
419 419
 
420
-		if ( $display_tokenization ) {
420
+		if ($display_tokenization) {
421 421
 			$this->tokenization_script();
422 422
 			$this->saved_payment_methods();
423 423
 		}
424 424
 
425
-		if ( ! $this->stripe_checkout ) {
426
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
425
+		if ( ! $this->stripe_checkout) {
426
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
427 427
 				$this->elements_form();
428 428
 			} else {
429 429
 				$this->form();
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 			}
432 432
 		}
433 433
 
434
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
434
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
435 435
 			$this->save_payment_method_checkbox();
436 436
 		}
437 437
 
@@ -446,12 +446,12 @@  discard block
 block discarded – undo
446 446
 	 */
447 447
 	public function elements_form() {
448 448
 		?>
449
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
450
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
449
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
450
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
451 451
 
452
-			<?php if ( $this->inline_cc_form ) { ?>
452
+			<?php if ($this->inline_cc_form) { ?>
453 453
 				<label for="card-element">
454
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
454
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
455 455
 				</label>
456 456
 
457 457
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 				</div>
460 460
 			<?php } else { ?>
461 461
 				<div class="form-row form-row-wide">
462
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
462
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
463 463
 
464 464
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
465 465
 					<!-- a Stripe Element will be inserted here. -->
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 				</div>
468 468
 
469 469
 				<div class="form-row form-row-first">
470
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
470
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
471 471
 
472 472
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
473 473
 					<!-- a Stripe Element will be inserted here. -->
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 				</div>
476 476
 
477 477
 				<div class="form-row form-row-last">
478
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
478
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
479 479
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
480 480
 				<!-- a Stripe Element will be inserted here. -->
481 481
 				</div>
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 
486 486
 			<!-- Used to display form errors -->
487 487
 			<div class="stripe-source-errors" role="alert"></div>
488
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
488
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
489 489
 			<div class="clear"></div>
490 490
 		</fieldset>
491 491
 		<?php
@@ -498,13 +498,13 @@  discard block
 block discarded – undo
498 498
 	 * @version 3.1.0
499 499
 	 */
500 500
 	public function admin_scripts() {
501
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
501
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
502 502
 			return;
503 503
 		}
504 504
 
505
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
505
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
506 506
 
507
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
507
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
508 508
 	}
509 509
 
510 510
 	/**
@@ -516,29 +516,29 @@  discard block
 block discarded – undo
516 516
 	 * @version 4.0.0
517 517
 	 */
518 518
 	public function payment_scripts() {
519
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
519
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
520 520
 			return;
521 521
 		}
522 522
 
523
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
523
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
524 524
 
525
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
526
-		wp_enqueue_style( 'stripe_paymentfonts' );
527
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
528
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
529
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
530
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true );
525
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
526
+		wp_enqueue_style('stripe_paymentfonts');
527
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
528
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
529
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
530
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true);
531 531
 
532 532
 		$stripe_params = array(
533 533
 			'key'                  => $this->publishable_key,
534
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
535
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
534
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
535
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
536 536
 		);
537 537
 
538 538
 		// If we're on the pay page we need to pass stripe.js the address of the order.
539
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
540
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
541
-			$order    = wc_get_order( $order_id );
539
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
540
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
541
+			$order    = wc_get_order($order_id);
542 542
 
543 543
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
544 544
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -550,38 +550,38 @@  discard block
 block discarded – undo
550 550
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
551 551
 		}
552 552
 
553
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
554
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
555
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
556
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
557
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
553
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
554
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
555
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
556
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
557
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
558 558
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
559
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
560
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
559
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
560
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
561 561
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
562
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
563
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
562
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
563
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
564 564
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
565
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
566
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
565
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
566
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
567 567
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
568
-		$stripe_params['is_change_payment_page']                  = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no';
568
+		$stripe_params['is_change_payment_page']                  = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no';
569 569
 		$stripe_params['is_add_payment_method_page']              = is_add_payment_method_page() ? 'yes' : 'no';
570
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
571
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
570
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
571
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
572 572
 
573 573
 		// merge localized messages to be use in JS
574
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
574
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
575 575
 
576
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
577
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
576
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
577
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
578 578
 
579
-		if ( $this->stripe_checkout ) {
580
-			wp_enqueue_script( 'stripe_checkout' );
579
+		if ($this->stripe_checkout) {
580
+			wp_enqueue_script('stripe_checkout');
581 581
 		}
582 582
 
583 583
 		$this->tokenization_script();
584
-		wp_enqueue_script( 'woocommerce_stripe' );
584
+		wp_enqueue_script('woocommerce_stripe');
585 585
 	}
586 586
 
587 587
 	/**
@@ -597,44 +597,44 @@  discard block
 block discarded – undo
597 597
 	 *
598 598
 	 * @return array|void
599 599
 	 */
600
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
600
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
601 601
 		try {
602
-			$order = wc_get_order( $order_id );
602
+			$order = wc_get_order($order_id);
603 603
 
604 604
 			// This comes from the create account checkbox in the checkout page.
605
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
605
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
606 606
 
607
-			if ( $create_account ) {
607
+			if ($create_account) {
608 608
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
609
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
609
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
610 610
 				$new_stripe_customer->create_customer();
611 611
 			}
612 612
 
613 613
 			$source_object   = $this->get_source_object();
614
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
614
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
615 615
 
616 616
 			// Check if we don't allow prepaid credit cards.
617
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
618
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
619
-					$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
620
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
617
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
618
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
619
+					$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
620
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
621 621
 				}
622 622
 			}
623 623
 
624
-			if ( empty( $prepared_source->source ) ) {
625
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
626
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
624
+			if (empty($prepared_source->source)) {
625
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
626
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
627 627
 			}
628 628
 
629 629
 			// Store source to order meta.
630
-			$this->save_source( $order, $prepared_source );
630
+			$this->save_source($order, $prepared_source);
631 631
 
632 632
 			// Result from Stripe API request.
633 633
 			$response = null;
634 634
 
635
-			if ( $order->get_total() > 0 ) {
635
+			if ($order->get_total() > 0) {
636 636
 				// This will throw exception if not valid.
637
-				$this->validate_minimum_order_amount( $order );
637
+				$this->validate_minimum_order_amount($order);
638 638
 
639 639
 				/*
640 640
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -643,89 +643,89 @@  discard block
 block discarded – undo
643 643
 				 * Note that if we need to save source, the original source must be first
644 644
 				 * attached to a customer in Stripe before it can be charged.
645 645
 				 */
646
-				if ( $this->is_3ds_required( $source_object ) ) {
647
-					$response = $this->create_3ds_source( $order, $source_object );
646
+				if ($this->is_3ds_required($source_object)) {
647
+					$response = $this->create_3ds_source($order, $source_object);
648 648
 
649
-					if ( ! empty( $response->error ) ) {
649
+					if ( ! empty($response->error)) {
650 650
 						$localized_message = $response->error->message;
651 651
 
652
-						$order->add_order_note( $localized_message );
652
+						$order->add_order_note($localized_message);
653 653
 
654
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
654
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
655 655
 					}
656 656
 
657 657
 					// Update order meta with 3DS source.
658
-					if ( WC_Stripe_Helper::is_pre_30() ) {
659
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
658
+					if (WC_Stripe_Helper::is_pre_30()) {
659
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
660 660
 					} else {
661
-						$order->update_meta_data( '_stripe_source_id', $response->id );
661
+						$order->update_meta_data('_stripe_source_id', $response->id);
662 662
 						$order->save();
663 663
 					}
664 664
 
665
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
665
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
666 666
 
667 667
 					return array(
668 668
 						'result'   => 'success',
669
-						'redirect' => esc_url_raw( $response->redirect->url ),
669
+						'redirect' => esc_url_raw($response->redirect->url),
670 670
 					);
671 671
 				}
672 672
 
673
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
673
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
674 674
 
675 675
 				// Make the request.
676
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
676
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
677 677
 
678
-				if ( ! empty( $response->error ) ) {
678
+				if ( ! empty($response->error)) {
679 679
 					// If it is an API error such connection or server, let's retry.
680
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
681
-						if ( $retry ) {
682
-							sleep( 5 );
683
-							return $this->process_payment( $order_id, false, $force_save_source );
680
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
681
+						if ($retry) {
682
+							sleep(5);
683
+							return $this->process_payment($order_id, false, $force_save_source);
684 684
 						} else {
685 685
 							$localized_message = 'API connection error and retries exhausted.';
686
-							$order->add_order_note( $localized_message );
687
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
686
+							$order->add_order_note($localized_message);
687
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
688 688
 						}
689 689
 					}
690 690
 
691 691
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
692
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
693
-						if ( WC_Stripe_Helper::is_pre_30() ) {
694
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
695
-							delete_post_meta( $order_id, '_stripe_customer_id' );
692
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
693
+						if (WC_Stripe_Helper::is_pre_30()) {
694
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
695
+							delete_post_meta($order_id, '_stripe_customer_id');
696 696
 						} else {
697
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
698
-							$order->delete_meta_data( '_stripe_customer_id' );
697
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
698
+							$order->delete_meta_data('_stripe_customer_id');
699 699
 							$order->save();
700 700
 						}
701 701
 
702
-						return $this->process_payment( $order_id, false, $force_save_source );
703
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
702
+						return $this->process_payment($order_id, false, $force_save_source);
703
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
704 704
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
705
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
705
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
706 706
 						$wc_token->delete();
707
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
708
-						$order->add_order_note( $localized_message );
709
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
707
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
708
+						$order->add_order_note($localized_message);
709
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
710 710
 					}
711 711
 
712 712
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
713 713
 
714
-					if ( 'card_error' === $response->error->type ) {
715
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
714
+					if ('card_error' === $response->error->type) {
715
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
716 716
 					} else {
717
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
717
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
718 718
 					}
719 719
 
720
-					$order->add_order_note( $localized_message );
720
+					$order->add_order_note($localized_message);
721 721
 
722
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
722
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
723 723
 				}
724 724
 
725
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
725
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
726 726
 
727 727
 				// Process valid response.
728
-				$this->process_response( $response, $order );
728
+				$this->process_response($response, $order);
729 729
 			} else {
730 730
 				$order->payment_complete();
731 731
 			}
@@ -736,17 +736,17 @@  discard block
 block discarded – undo
736 736
 			// Return thank you page redirect.
737 737
 			return array(
738 738
 				'result'   => 'success',
739
-				'redirect' => $this->get_return_url( $order ),
739
+				'redirect' => $this->get_return_url($order),
740 740
 			);
741 741
 
742
-		} catch ( WC_Stripe_Exception $e ) {
743
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
744
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
742
+		} catch (WC_Stripe_Exception $e) {
743
+			wc_add_notice($e->getLocalizedMessage(), 'error');
744
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
745 745
 
746
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
746
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
747 747
 
748
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
749
-				$this->send_failed_order_email( $order_id );
748
+			if ($order->has_status(array('pending', 'failed'))) {
749
+				$this->send_failed_order_email($order_id);
750 750
 			}
751 751
 
752 752
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bancontact.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_bancontact';
60
-		$this->method_title         = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_bancontact_supported_currencies', array(
144
+		return apply_filters('wc_stripe_bancontact_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['bancontact'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-bancontact-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,25 +241,25 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency                = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$order_id                = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
247
-		$return_url              = $this->get_stripe_return_url( $order );
247
+		$return_url              = $this->get_stripe_return_url($order);
248 248
 		$post_data               = array();
249
-		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency']   = strtolower( $currency );
249
+		$post_data['amount']     = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency']   = strtolower($currency);
251 251
 		$post_data['type']       = 'bancontact';
252
-		$post_data['owner']      = $this->get_owner_details( $order );
253
-		$post_data['redirect']   = array( 'return_url' => $return_url );
254
-		$post_data['bancontact'] = array( 'preferred_language' => substr( get_locale(), 0, 2 ) );
252
+		$post_data['owner']      = $this->get_owner_details($order);
253
+		$post_data['redirect']   = array('return_url' => $return_url);
254
+		$post_data['bancontact'] = array('preferred_language' => substr(get_locale(), 0, 2));
255 255
 
256
-		if ( ! empty( $this->statement_descriptor ) ) {
257
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
256
+		if ( ! empty($this->statement_descriptor)) {
257
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
258 258
 		}
259 259
 
260
-		WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' );
260
+		WC_Stripe_Logger::log('Info: Begin creating Bancontact source');
261 261
 
262
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' );
262
+		return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources');
263 263
 	}
264 264
 
265 265
 	/**
@@ -273,51 +273,51 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @return array|void
275 275
 	 */
276
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
276
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
277 277
 		try {
278
-			$order = wc_get_order( $order_id );
278
+			$order = wc_get_order($order_id);
279 279
 
280 280
 			// This will throw exception if not valid.
281
-			$this->validate_minimum_order_amount( $order );
281
+			$this->validate_minimum_order_amount($order);
282 282
 
283 283
 			// This comes from the create account checkbox in the checkout page.
284
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
284
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
285 285
 
286
-			if ( $create_account ) {
286
+			if ($create_account) {
287 287
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
288
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
288
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
289 289
 				$new_stripe_customer->create_customer();
290 290
 			}
291 291
 
292
-			$response = $this->create_source( $order );
292
+			$response = $this->create_source($order);
293 293
 
294
-			if ( ! empty( $response->error ) ) {
295
-				$order->add_order_note( $response->error->message );
294
+			if ( ! empty($response->error)) {
295
+				$order->add_order_note($response->error->message);
296 296
 
297
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
297
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
298 298
 			}
299 299
 
300
-			if ( WC_Stripe_Helper::is_pre_30() ) {
301
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
300
+			if (WC_Stripe_Helper::is_pre_30()) {
301
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
302 302
 			} else {
303
-				$order->update_meta_data( '_stripe_source_id', $response->id );
303
+				$order->update_meta_data('_stripe_source_id', $response->id);
304 304
 				$order->save();
305 305
 			}
306 306
 
307
-			WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' );
307
+			WC_Stripe_Logger::log('Info: Redirecting to Bancontact...');
308 308
 
309 309
 			return array(
310 310
 				'result'   => 'success',
311
-				'redirect' => esc_url_raw( $response->redirect->url ),
311
+				'redirect' => esc_url_raw($response->redirect->url),
312 312
 			);
313
-		} catch ( WC_Stripe_Exception $e ) {
314
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
315
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
313
+		} catch (WC_Stripe_Exception $e) {
314
+			wc_add_notice($e->getLocalizedMessage(), 'error');
315
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
316 316
 
317
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
317
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
318 318
 
319
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
320
-				$this->send_failed_order_email( $order_id );
319
+			if ($order->has_status(array('pending', 'failed'))) {
320
+				$this->send_failed_order_email($order_id);
321 321
 			}
322 322
 
323 323
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-p24.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_p24';
60
-		$this->method_title         = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe P24', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_p24_supported_currencies', array(
144
+		return apply_filters('wc_stripe_p24_supported_currencies', array(
145 145
 			'EUR',
146 146
 			'PLN',
147
-		) );
147
+		));
148 148
 	}
149 149
 
150 150
 	/**
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @return bool
156 156
 	 */
157 157
 	public function is_available() {
158
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
158
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
159 159
 			return false;
160 160
 		}
161 161
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
 		$icons_str .= $icons['p24'];
178 178
 
179
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
179
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
180 180
 	}
181 181
 
182 182
 	/**
@@ -187,19 +187,19 @@  discard block
 block discarded – undo
187 187
 	 * @access public
188 188
 	 */
189 189
 	public function payment_scripts() {
190
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
190
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
191 191
 			return;
192 192
 		}
193 193
 
194
-		wp_enqueue_style( 'stripe_paymentfonts' );
195
-		wp_enqueue_script( 'woocommerce_stripe' );
194
+		wp_enqueue_style('stripe_paymentfonts');
195
+		wp_enqueue_script('woocommerce_stripe');
196 196
 	}
197 197
 
198 198
 	/**
199 199
 	 * Initialize Gateway Settings Form Fields.
200 200
 	 */
201 201
 	public function init_form_fields() {
202
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' );
202
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php');
203 203
 	}
204 204
 
205 205
 	/**
@@ -210,25 +210,25 @@  discard block
 block discarded – undo
210 210
 		$total                = WC()->cart->total;
211 211
 
212 212
 		// If paying from order, we need to get total from order not cart.
213
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
214
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
213
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
214
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
215 215
 			$total = $order->get_total();
216 216
 		}
217 217
 
218
-		if ( is_add_payment_method_page() ) {
219
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
220
-			$total        = '';
218
+		if (is_add_payment_method_page()) {
219
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
220
+			$total = '';
221 221
 		} else {
222 222
 			$pay_button_text = '';
223 223
 		}
224 224
 
225 225
 		echo '<div
226 226
 			id="stripe-p24-payment-data"
227
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
228
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
227
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
228
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
229 229
 
230
-		if ( $this->description ) {
231
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
230
+		if ($this->description) {
231
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
232 232
 		}
233 233
 
234 234
 		echo '</div>';
@@ -242,20 +242,20 @@  discard block
 block discarded – undo
242 242
 	 * @param object $order
243 243
 	 * @return mixed
244 244
 	 */
245
-	public function create_source( $order ) {
245
+	public function create_source($order) {
246 246
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
247 247
 		$order_id              = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
248
-		$return_url            = $this->get_stripe_return_url( $order );
248
+		$return_url            = $this->get_stripe_return_url($order);
249 249
 		$post_data             = array();
250
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
251
-		$post_data['currency'] = strtolower( $currency );
250
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
251
+		$post_data['currency'] = strtolower($currency);
252 252
 		$post_data['type']     = 'p24';
253
-		$post_data['owner']    = $this->get_owner_details( $order );
254
-		$post_data['redirect'] = array( 'return_url' => $return_url );
253
+		$post_data['owner']    = $this->get_owner_details($order);
254
+		$post_data['redirect'] = array('return_url' => $return_url);
255 255
 
256
-		WC_Stripe_Logger::log( 'Info: Begin creating P24 source' );
256
+		WC_Stripe_Logger::log('Info: Begin creating P24 source');
257 257
 
258
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_p24_source', $post_data, $order ), 'sources' );
258
+		return WC_Stripe_API::request(apply_filters('wc_stripe_p24_source', $post_data, $order), 'sources');
259 259
 	}
260 260
 
261 261
 	/**
@@ -269,51 +269,51 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return array|void
271 271
 	 */
272
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
272
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
273 273
 		try {
274
-			$order = wc_get_order( $order_id );
274
+			$order = wc_get_order($order_id);
275 275
 
276 276
 			// This will throw exception if not valid.
277
-			$this->validate_minimum_order_amount( $order );
277
+			$this->validate_minimum_order_amount($order);
278 278
 
279 279
 			// This comes from the create account checkbox in the checkout page.
280
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
280
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
281 281
 
282
-			if ( $create_account ) {
282
+			if ($create_account) {
283 283
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
284
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
284
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
285 285
 				$new_stripe_customer->create_customer();
286 286
 			}
287 287
 
288
-			$response = $this->create_source( $order );
288
+			$response = $this->create_source($order);
289 289
 
290
-			if ( ! empty( $response->error ) ) {
291
-				$order->add_order_note( $response->error->message );
290
+			if ( ! empty($response->error)) {
291
+				$order->add_order_note($response->error->message);
292 292
 
293
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
293
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
294 294
 			}
295 295
 
296
-			if ( WC_Stripe_Helper::is_pre_30() ) {
297
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
296
+			if (WC_Stripe_Helper::is_pre_30()) {
297
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
298 298
 			} else {
299
-				$order->update_meta_data( '_stripe_source_id', $response->id );
299
+				$order->update_meta_data('_stripe_source_id', $response->id);
300 300
 				$order->save();
301 301
 			}
302 302
 
303
-			WC_Stripe_Logger::log( 'Info: Redirecting to P24...' );
303
+			WC_Stripe_Logger::log('Info: Redirecting to P24...');
304 304
 
305 305
 			return array(
306 306
 				'result'   => 'success',
307
-				'redirect' => esc_url_raw( $response->redirect->url ),
307
+				'redirect' => esc_url_raw($response->redirect->url),
308 308
 			);
309
-		} catch ( WC_Stripe_Exception $e ) {
310
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
311
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
309
+		} catch (WC_Stripe_Exception $e) {
310
+			wc_add_notice($e->getLocalizedMessage(), 'error');
311
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
312 312
 
313
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
313
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
314 314
 
315
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
316
-				$this->send_failed_order_email( $order_id );
315
+			if ($order->has_status(array('pending', 'failed'))) {
316
+				$this->send_failed_order_email($order_id);
317 317
 			}
318 318
 
319 319
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-alipay.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_alipay';
60
-		$this->method_title         = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Alipay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function get_environment_warning() {
127 127
 		if (
128
-			'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() )
128
+			'yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())
129 129
 		) {
130 130
 			/* translators: supported currency list */
131
-			$message = sprintf( __( 'Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), implode( ', ', $this->get_supported_currency() ) );
131
+			$message = sprintf(__('Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), implode(', ', $this->get_supported_currency()));
132 132
 
133 133
 			return $message;
134 134
 		}
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @return array
145 145
 	 */
146 146
 	public function get_supported_currency() {
147
-		return apply_filters( 'wc_stripe_alipay_supported_currencies', array(
147
+		return apply_filters('wc_stripe_alipay_supported_currencies', array(
148 148
 			'EUR',
149 149
 			'AUD',
150 150
 			'CAD',
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			'NZD',
155 155
 			'SGD',
156 156
 			'USD',
157
-		) );
157
+		));
158 158
 	}
159 159
 
160 160
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function is_available() {
168
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
168
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 		$icons_str .= $icons['alipay'];
188 188
 
189
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
189
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
190 190
 	}
191 191
 
192 192
 	/**
@@ -196,19 +196,19 @@  discard block
 block discarded – undo
196 196
 	 * @version 4.0.0
197 197
 	 */
198 198
 	public function payment_scripts() {
199
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
199
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
200 200
 			return;
201 201
 		}
202 202
 
203
-		wp_enqueue_style( 'stripe_paymentfonts' );
204
-		wp_enqueue_script( 'woocommerce_stripe' );
203
+		wp_enqueue_style('stripe_paymentfonts');
204
+		wp_enqueue_script('woocommerce_stripe');
205 205
 	}
206 206
 
207 207
 	/**
208 208
 	 * Initialize Gateway Settings Form Fields.
209 209
 	 */
210 210
 	public function init_form_fields() {
211
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' );
211
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php');
212 212
 	}
213 213
 
214 214
 	/**
@@ -219,25 +219,25 @@  discard block
 block discarded – undo
219 219
 		$total                = WC()->cart->total;
220 220
 
221 221
 		// If paying from order, we need to get total from order not cart.
222
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
223
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
222
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
223
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
224 224
 			$total = $order->get_total();
225 225
 		}
226 226
 
227
-		if ( is_add_payment_method_page() ) {
228
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
229
-			$total        = '';
227
+		if (is_add_payment_method_page()) {
228
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
229
+			$total = '';
230 230
 		} else {
231 231
 			$pay_button_text = '';
232 232
 		}
233 233
 
234 234
 		echo '<div
235 235
 			id="stripe-alipay-payment-data"
236
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
237
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
236
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
237
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
238 238
 
239
-		if ( $this->description ) {
240
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
239
+		if ($this->description) {
240
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
241 241
 		}
242 242
 
243 243
 		echo '</div>';
@@ -251,24 +251,24 @@  discard block
 block discarded – undo
251 251
 	 * @param object $order
252 252
 	 * @return mixed
253 253
 	 */
254
-	public function create_source( $order ) {
254
+	public function create_source($order) {
255 255
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
256 256
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
257
-		$return_url                        = $this->get_stripe_return_url( $order );
257
+		$return_url                        = $this->get_stripe_return_url($order);
258 258
 		$post_data                         = array();
259
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
260
-		$post_data['currency']             = strtolower( $currency );
259
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
260
+		$post_data['currency']             = strtolower($currency);
261 261
 		$post_data['type']                 = 'alipay';
262
-		$post_data['owner']                = $this->get_owner_details( $order );
263
-		$post_data['redirect']             = array( 'return_url' => $return_url );
262
+		$post_data['owner']                = $this->get_owner_details($order);
263
+		$post_data['redirect']             = array('return_url' => $return_url);
264 264
 
265
-		if ( ! empty( $this->statement_descriptor ) ) {
266
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
265
+		if ( ! empty($this->statement_descriptor)) {
266
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
267 267
 		}
268 268
 
269
-		WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' );
269
+		WC_Stripe_Logger::log('Info: Begin creating Alipay source');
270 270
 
271
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' );
271
+		return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources');
272 272
 	}
273 273
 
274 274
 	/**
@@ -282,53 +282,53 @@  discard block
 block discarded – undo
282 282
 	 *
283 283
 	 * @return array|void
284 284
 	 */
285
-	public function process_payment( $order_id, $retry = true, $force_save_save = false ) {
285
+	public function process_payment($order_id, $retry = true, $force_save_save = false) {
286 286
 		try {
287
-			$order = wc_get_order( $order_id );
287
+			$order = wc_get_order($order_id);
288 288
 
289 289
 			// This will throw exception if not valid.
290
-			$this->validate_minimum_order_amount( $order );
290
+			$this->validate_minimum_order_amount($order);
291 291
 
292 292
 			// This comes from the create account checkbox in the checkout page.
293
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
293
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
294 294
 
295
-			if ( $create_account ) {
295
+			if ($create_account) {
296 296
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
297
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
297
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
298 298
 				$new_stripe_customer->create_customer();
299 299
 			}
300 300
 
301
-			$response = $this->create_source( $order );
301
+			$response = $this->create_source($order);
302 302
 
303
-			if ( ! empty( $response->error ) ) {
304
-				$order->add_order_note( $response->error->message );
303
+			if ( ! empty($response->error)) {
304
+				$order->add_order_note($response->error->message);
305 305
 
306
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
306
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
307 307
 			}
308 308
 
309
-			if ( WC_Stripe_Helper::is_pre_30() ) {
310
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
309
+			if (WC_Stripe_Helper::is_pre_30()) {
310
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
311 311
 			} else {
312
-				$order->update_meta_data( '_stripe_source_id', $response->id );
312
+				$order->update_meta_data('_stripe_source_id', $response->id);
313 313
 				$order->save();
314 314
 			}
315 315
 
316
-			WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' );
316
+			WC_Stripe_Logger::log('Info: Redirecting to Alipay...');
317 317
 
318 318
 			return array(
319 319
 				'result'   => 'success',
320
-				'redirect' => esc_url_raw( $response->redirect->url ),
320
+				'redirect' => esc_url_raw($response->redirect->url),
321 321
 			);
322
-		} catch ( WC_Stripe_Exception $e ) {
323
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
324
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
322
+		} catch (WC_Stripe_Exception $e) {
323
+			wc_add_notice($e->getLocalizedMessage(), 'error');
324
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
325 325
 
326
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
326
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
327 327
 
328
-			$statuses = array( 'pending', 'failed' );
328
+			$statuses = array('pending', 'failed');
329 329
 
330
-			if ( $order->has_status( $statuses ) ) {
331
-				$this->send_failed_order_email( $order_id );
330
+			if ($order->has_status($statuses)) {
331
+				$this->send_failed_order_email($order_id);
332 332
 			}
333 333
 
334 334
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-giropay.php 1 patch
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_giropay';
60
-		$this->method_title         = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Giropay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_giropay_supported_currencies', array(
144
+		return apply_filters('wc_stripe_giropay_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['giropay'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total                = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-giropay-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,24 +241,24 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
247
-		$return_url                        = $this->get_stripe_return_url( $order );
247
+		$return_url                        = $this->get_stripe_return_url($order);
248 248
 		$post_data                         = array();
249
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency']             = strtolower( $currency );
249
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency']             = strtolower($currency);
251 251
 		$post_data['type']                 = 'giropay';
252
-		$post_data['owner']                = $this->get_owner_details( $order );
253
-		$post_data['redirect']             = array( 'return_url' => $return_url );
252
+		$post_data['owner']                = $this->get_owner_details($order);
253
+		$post_data['redirect']             = array('return_url' => $return_url);
254 254
 
255
-		if ( ! empty( $this->statement_descriptor ) ) {
256
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
255
+		if ( ! empty($this->statement_descriptor)) {
256
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
257 257
 		}
258 258
 
259
-		WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' );
259
+		WC_Stripe_Logger::log('Info: Begin creating Giropay source');
260 260
 
261
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_giropay_source', $post_data, $order ), 'sources' );
261
+		return WC_Stripe_API::request(apply_filters('wc_stripe_giropay_source', $post_data, $order), 'sources');
262 262
 	}
263 263
 
264 264
 	/**
@@ -272,51 +272,51 @@  discard block
 block discarded – undo
272 272
 	 *
273 273
 	 * @return array|void
274 274
 	 */
275
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
275
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
276 276
 		try {
277
-			$order = wc_get_order( $order_id );
277
+			$order = wc_get_order($order_id);
278 278
 
279 279
 			// This will throw exception if not valid.
280
-			$this->validate_minimum_order_amount( $order );
280
+			$this->validate_minimum_order_amount($order);
281 281
 
282 282
 			// This comes from the create account checkbox in the checkout page.
283
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
283
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
284 284
 
285
-			if ( $create_account ) {
285
+			if ($create_account) {
286 286
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
287
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
287
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
288 288
 				$new_stripe_customer->create_customer();
289 289
 			}
290 290
 
291
-			$response = $this->create_source( $order );
291
+			$response = $this->create_source($order);
292 292
 
293
-			if ( ! empty( $response->error ) ) {
294
-				$order->add_order_note( $response->error->message );
293
+			if ( ! empty($response->error)) {
294
+				$order->add_order_note($response->error->message);
295 295
 
296
-				throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
296
+				throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
297 297
 			}
298 298
 
299
-			if ( WC_Stripe_Helper::is_pre_30() ) {
300
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
299
+			if (WC_Stripe_Helper::is_pre_30()) {
300
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
301 301
 			} else {
302
-				$order->update_meta_data( '_stripe_source_id', $response->id );
302
+				$order->update_meta_data('_stripe_source_id', $response->id);
303 303
 				$order->save();
304 304
 			}
305 305
 
306
-			WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' );
306
+			WC_Stripe_Logger::log('Info: Redirecting to Giropay...');
307 307
 
308 308
 			return array(
309 309
 				'result'   => 'success',
310
-				'redirect' => esc_url_raw( $response->redirect->url ),
310
+				'redirect' => esc_url_raw($response->redirect->url),
311 311
 			);
312
-		} catch ( WC_Stripe_Exception $e ) {
313
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
314
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
312
+		} catch (WC_Stripe_Exception $e) {
313
+			wc_add_notice($e->getLocalizedMessage(), 'error');
314
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
315 315
 
316
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
316
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
317 317
 
318
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
319
-				$this->send_failed_order_email( $order_id );
318
+			if ($order->has_status(array('pending', 'failed'))) {
319
+				$this->send_failed_order_email($order_id);
320 320
 			}
321 321
 
322 322
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		$this->id                   = 'stripe_bitcoin';
67
-		$this->method_title         = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
67
+		$this->method_title         = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
68 68
 		/* translators: link */
69
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
69
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
70 70
 		$this->supports             = array(
71 71
 			'products',
72 72
 			'refunds',
@@ -78,29 +78,29 @@  discard block
 block discarded – undo
78 78
 		// Load the settings.
79 79
 		$this->init_settings();
80 80
 
81
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
82
-		$this->title                = $this->get_option( 'title' );
83
-		$this->description          = $this->get_option( 'description' );
84
-		$this->enabled              = $this->get_option( 'enabled' );
85
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
86
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
87
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
88
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
89
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
90
-
91
-		if ( $this->testmode ) {
92
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
93
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
81
+		$main_settings              = get_option('woocommerce_stripe_settings');
82
+		$this->title                = $this->get_option('title');
83
+		$this->description          = $this->get_option('description');
84
+		$this->enabled              = $this->get_option('enabled');
85
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
86
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
87
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
88
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
89
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
90
+
91
+		if ($this->testmode) {
92
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
93
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
94 94
 		}
95 95
 
96
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
97
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
98
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
99
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
100
-		add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) );
96
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
97
+		add_action('admin_notices', array($this, 'check_environment'));
98
+		add_action('admin_head', array($this, 'remove_admin_notice'));
99
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
100
+		add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page'));
101 101
 
102 102
 		// Customer Emails
103
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
103
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
104 104
 	}
105 105
 
106 106
 	/**
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 	 * @version 4.0.0
111 111
 	 */
112 112
 	public function check_environment() {
113
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
113
+		if ( ! current_user_can('manage_woocommerce')) {
114 114
 			return;
115 115
 		}
116 116
 
117 117
 		$environment_warning = $this->get_environment_warning();
118 118
 
119
-		if ( $environment_warning ) {
120
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
119
+		if ($environment_warning) {
120
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
121 121
 		}
122 122
 
123
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
124
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
125
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
123
+		foreach ((array) $this->notices as $notice_key => $notice) {
124
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
125
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
126 126
 			echo '</p></div>';
127 127
 		}
128 128
 	}
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	public function get_environment_warning() {
138 138
 		// Add deprecated notice to logs.
139
-		if ( 'yes' === $this->enabled ) {
140
-			WC_Stripe_Logger::log( 'DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.' );
139
+		if ('yes' === $this->enabled) {
140
+			WC_Stripe_Logger::log('DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.');
141 141
 		}
142 142
 
143
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
144
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
143
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
144
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
145 145
 
146 146
 			return $message;
147 147
 		}
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 	 * @return array
158 158
 	 */
159 159
 	public function get_supported_currency() {
160
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
160
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
161 161
 			'USD',
162
-		) );
162
+		));
163 163
 	}
164 164
 
165 165
 	/**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return bool
171 171
 	 */
172 172
 	public function is_available() {
173
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
173
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
174 174
 			return false;
175 175
 		}
176 176
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
 		$icons_str .= $icons['bitcoin'];
193 193
 
194
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
194
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
195 195
 	}
196 196
 
197 197
 	/**
@@ -202,19 +202,19 @@  discard block
 block discarded – undo
202 202
 	 * @access public
203 203
 	 */
204 204
 	public function payment_scripts() {
205
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
205
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
206 206
 			return;
207 207
 		}
208 208
 
209
-		wp_enqueue_style( 'stripe_paymentfonts' );
210
-		wp_enqueue_script( 'woocommerce_stripe' );
209
+		wp_enqueue_style('stripe_paymentfonts');
210
+		wp_enqueue_script('woocommerce_stripe');
211 211
 	}
212 212
 
213 213
 	/**
214 214
 	 * Initialize Gateway Settings Form Fields.
215 215
 	 */
216 216
 	public function init_form_fields() {
217
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
217
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
218 218
 	}
219 219
 
220 220
 	/**
@@ -225,25 +225,25 @@  discard block
 block discarded – undo
225 225
 		$total                = WC()->cart->total;
226 226
 
227 227
 		// If paying from order, we need to get total from order not cart.
228
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
229
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
228
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
229
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
230 230
 			$total = $order->get_total();
231 231
 		}
232 232
 
233
-		if ( is_add_payment_method_page() ) {
234
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
235
-			$total        = '';
233
+		if (is_add_payment_method_page()) {
234
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
235
+			$total = '';
236 236
 		} else {
237 237
 			$pay_button_text = '';
238 238
 		}
239 239
 
240 240
 		echo '<div
241 241
 			id="stripe-bitcoin-payment-data"
242
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
243
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
242
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
243
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
244 244
 
245
-		if ( $this->description ) {
246
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
245
+		if ($this->description) {
246
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
247 247
 		}
248 248
 
249 249
 		echo '</div>';
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @param int $order_id
256 256
 	 */
257
-	public function thankyou_page( $order_id ) {
258
-		$this->get_instructions( $order_id );
257
+	public function thankyou_page($order_id) {
258
+		$this->get_instructions($order_id);
259 259
 	}
260 260
 
261 261
 	/**
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 * @param bool $sent_to_admin
268 268
 	 * @param bool $plain_text
269 269
 	 */
270
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
270
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
271 271
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
272 272
 
273 273
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
274 274
 
275
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
276
-			$this->get_instructions( $order_id, $plain_text );
275
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
276
+			$this->get_instructions($order_id, $plain_text);
277 277
 		}
278 278
 	}
279 279
 
@@ -284,38 +284,38 @@  discard block
 block discarded – undo
284 284
 	 * @version 4.0.0
285 285
 	 * @param int $order_id
286 286
 	 */
287
-	public function get_instructions( $order_id, $plain_text = false ) {
288
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
287
+	public function get_instructions($order_id, $plain_text = false) {
288
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
289 289
 
290
-		if ( $plain_text ) {
291
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
290
+		if ($plain_text) {
291
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
292 292
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
293
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
293
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
294 294
 			echo $data['amount'] . "\n\n";
295 295
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
296
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
296
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
297 297
 			echo $data['address'] . "\n\n";
298 298
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
299
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
299
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
300 300
 			echo $data['uri'] . "\n\n";
301 301
 		} else {
302 302
 			?>
303
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
303
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
304 304
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
305 305
 			<li class="woocommerce-order-overview__order order">
306
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
306
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
307 307
 				<strong><?php echo $data['amount']; ?></strong>
308 308
 			</li>
309 309
 			<li class="woocommerce-order-overview__order order">
310
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
310
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
311 311
 				<strong><?php echo $data['address']; ?></strong>
312 312
 			</li>
313 313
 			<li class="woocommerce-order-overview__order order">
314
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
314
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
315 315
 				<strong>
316 316
 				<?php
317 317
 				/* translators: link */
318
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
318
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
319 319
 				?>
320 320
 				</strong>
321 321
 			</li>
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 * @param object $order
333 333
 	 * @param object $source_object
334 334
 	 */
335
-	public function save_instructions( $order, $source_object ) {
335
+	public function save_instructions($order, $source_object) {
336 336
 		$data = array(
337 337
 			'amount'  => $source_object->bitcoin->amount,
338 338
 			'address' => $source_object->bitcoin->address,
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
343 343
 
344
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
344
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
345 345
 	}
346 346
 
347 347
 	/**
@@ -355,38 +355,38 @@  discard block
 block discarded – undo
355 355
 	 *
356 356
 	 * @return array|void
357 357
 	 */
358
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
358
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
359 359
 		try {
360
-			$order = wc_get_order( $order_id );
360
+			$order = wc_get_order($order_id);
361 361
 
362 362
 			// This comes from the create account checkbox in the checkout page.
363
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
363
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
364 364
 
365
-			if ( $create_account ) {
365
+			if ($create_account) {
366 366
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
367
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
367
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
368 368
 				$new_stripe_customer->create_customer();
369 369
 			}
370 370
 
371
-			$prepared_source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), $force_save_source );
371
+			$prepared_source = $this->prepare_source($this->get_source_object(), get_current_user_id(), $force_save_source);
372 372
 
373
-			if ( empty( $prepared_source->source ) ) {
374
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
375
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
373
+			if (empty($prepared_source->source)) {
374
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
375
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
376 376
 			}
377 377
 
378 378
 			// Store source to order meta.
379
-			$this->save_source( $order, $prepared_source );
379
+			$this->save_source($order, $prepared_source);
380 380
 
381 381
 			// This will throw exception if not valid.
382
-			$this->validate_minimum_order_amount( $order );
382
+			$this->validate_minimum_order_amount($order);
383 383
 
384
-			$this->save_instructions( $order, $this->get_source_object() );
384
+			$this->save_instructions($order, $this->get_source_object());
385 385
 
386 386
 			// Mark as on-hold (we're awaiting the payment)
387
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
387
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
388 388
 
389
-			wc_reduce_stock_levels( $order_id );
389
+			wc_reduce_stock_levels($order_id);
390 390
 
391 391
 			// Remove cart
392 392
 			WC()->cart->empty_cart();
@@ -394,16 +394,16 @@  discard block
 block discarded – undo
394 394
 			// Return thankyou redirect
395 395
 			return array(
396 396
 				'result'    => 'success',
397
-				'redirect'  => $this->get_return_url( $order ),
397
+				'redirect'  => $this->get_return_url($order),
398 398
 			);
399
-		} catch ( WC_Stripe_Exception $e ) {
400
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
401
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
399
+		} catch (WC_Stripe_Exception $e) {
400
+			wc_add_notice($e->getLocalizedMessage(), 'error');
401
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
402 402
 
403
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
403
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
404 404
 
405
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
406
-				$this->send_failed_order_email( $order_id );
405
+			if ($order->has_status(array('pending', 'failed'))) {
406
+				$this->send_failed_order_email($order_id);
407 407
 			}
408 408
 
409 409
 			return array(
Please login to merge, or discard this patch.