Completed
Push — master ( b790b0...129907 )
by Roy
02:04
created
includes/payment-methods/class-wc-gateway-stripe-sofort.php 1 patch
Spacing   +79 added lines, -79 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_sofort';
60
-		$this->method_title         = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SOFORT', '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 = __( 'SOFORT 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 = __('SOFORT 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_sofort_supported_currencies', array(
144
+		return apply_filters('wc_stripe_sofort_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['sofort'];
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-sofort-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-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-sofort-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,28 +241,28 @@  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
 		$bank_country          = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
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']     = 'sofort';
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
 		$post_data['sofort']   = array(
255 255
 			'country'            => $bank_country,
256 256
 			'preferred_language' => $this->get_locale(),
257 257
 		);
258 258
 
259
-		if ( ! empty( $this->statement_descriptor ) ) {
260
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
259
+		if ( ! empty($this->statement_descriptor)) {
260
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
261 261
 		}
262 262
 
263
-		WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' );
263
+		WC_Stripe_Logger::log('Info: Begin creating SOFORT source');
264 264
 
265
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' );
265
+		return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources');
266 266
 	}
267 267
 
268 268
 	/**
@@ -276,59 +276,59 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @return array|void
278 278
 	 */
279
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
279
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
280 280
 		try {
281
-			$order = wc_get_order( $order_id );
281
+			$order = wc_get_order($order_id);
282 282
 
283 283
 			// This will throw exception if not valid.
284
-			$this->validate_minimum_order_amount( $order );
284
+			$this->validate_minimum_order_amount($order);
285 285
 
286 286
 			// This comes from the create account checkbox in the checkout page.
287
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
287
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
288 288
 
289
-			if ( $create_account ) {
289
+			if ($create_account) {
290 290
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
291
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
291
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
292 292
 				$new_stripe_customer->create_customer();
293 293
 			}
294 294
 
295
-			$response = $this->create_source( $order );
295
+			$response = $this->create_source($order);
296 296
 
297
-			if ( ! empty( $response->error ) ) {
298
-				$order->add_order_note( $response->error->message );
297
+			if ( ! empty($response->error)) {
298
+				$order->add_order_note($response->error->message);
299 299
 
300 300
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
301 301
 
302
-				if ( 'invalid_sofort_country' === $response->error->code ) {
303
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
302
+				if ('invalid_sofort_country' === $response->error->code) {
303
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
304 304
 				} else {
305
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
305
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
306 306
 				}
307 307
 
308
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
308
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
309 309
 			}
310 310
 
311
-			if ( WC_Stripe_Helper::is_pre_30() ) {
312
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
311
+			if (WC_Stripe_Helper::is_pre_30()) {
312
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
313 313
 			} else {
314
-				$order->update_meta_data( '_stripe_source_id', $response->id );
314
+				$order->update_meta_data('_stripe_source_id', $response->id);
315 315
 				$order->save();
316 316
 			}
317 317
 
318
-			WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' );
318
+			WC_Stripe_Logger::log('Info: Redirecting to SOFORT...');
319 319
 
320 320
 			return array(
321 321
 				'result'   => 'success',
322
-				'redirect' => esc_url_raw( $response->redirect->url ),
322
+				'redirect' => esc_url_raw($response->redirect->url),
323 323
 			);
324
-		} catch ( WC_Stripe_Exception $e ) {
325
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
326
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
324
+		} catch (WC_Stripe_Exception $e) {
325
+			wc_add_notice($e->getLocalizedMessage(), 'error');
326
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
327 327
 
328
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
328
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
329 329
 
330
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
331
-				$this->send_failed_order_email( $order_id );
330
+			if ($order->has_status(array('pending', 'failed'))) {
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-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' => $this->get_locale() );
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' => $this->get_locale());
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/deprecated/class-wc-stripe-apple-pay.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6 6
 /**
7 7
  * DEPRECATED DO NOT USE!!
8 8
  */
9
-if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) {
9
+if ( ! class_exists('WC_Stripe_Apple_Pay')) {
10 10
 	class WC_Stripe_Apple_Pay {
11 11
 		/**
12 12
 		 * This Instance.
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
 		}
21 21
 
22 22
 		public static function instance() {
23
-			WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0' );
23
+			WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0');
24 24
 			return self::$_this;
25 25
 		}
26 26
 
27
-		public function __get( $var ) {
27
+		public function __get($var) {
28 28
 			return null;
29 29
 		}
30 30
 
31
-		public function __call( $name, $arguments ) {
31
+		public function __call($name, $arguments) {
32 32
 			return null;
33 33
 		}
34 34
 	}
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,37 +355,37 @@  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( get_current_user_id(), $force_save_source );
371
+			$prepared_source = $this->prepare_source(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
-			$this->save_source_to_order( $order, $prepared_source );
378
+			$this->save_source_to_order($order, $prepared_source);
379 379
 
380 380
 			// This will throw exception if not valid.
381
-			$this->validate_minimum_order_amount( $order );
381
+			$this->validate_minimum_order_amount($order);
382 382
 
383
-			$this->save_instructions( $order, $this->get_source_object( $prepared_source->source ) );
383
+			$this->save_instructions($order, $this->get_source_object($prepared_source->source));
384 384
 
385 385
 			// Mark as on-hold (we're awaiting the payment).
386
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
386
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
387 387
 
388
-			wc_reduce_stock_levels( $order_id );
388
+			wc_reduce_stock_levels($order_id);
389 389
 
390 390
 			// Remove cart.
391 391
 			WC()->cart->empty_cart();
@@ -393,16 +393,16 @@  discard block
 block discarded – undo
393 393
 			// Return thankyou redirect.
394 394
 			return array(
395 395
 				'result'    => 'success',
396
-				'redirect'  => $this->get_return_url( $order ),
396
+				'redirect'  => $this->get_return_url($order),
397 397
 			);
398
-		} catch ( WC_Stripe_Exception $e ) {
399
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
400
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
398
+		} catch (WC_Stripe_Exception $e) {
399
+			wc_add_notice($e->getLocalizedMessage(), 'error');
400
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
401 401
 
402
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
402
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
403 403
 
404
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
405
-				$this->send_failed_order_email( $order_id );
404
+			if ($order->has_status(array('pending', 'failed'))) {
405
+				$this->send_failed_order_email($order_id);
406 406
 			}
407 407
 
408 408
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sepa.php 1 patch
Spacing   +105 added lines, -105 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
 
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 	public function __construct() {
66 66
 		$this->retry_interval       = 1;
67 67
 		$this->id                   = 'stripe_sepa';
68
-		$this->method_title         = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
68
+		$this->method_title         = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
69 69
 		/* translators: link */
70
-		$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
+		$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'));
71 71
 		$this->supports             = array(
72 72
 			'products',
73 73
 			'refunds',
@@ -92,25 +92,25 @@  discard block
 block discarded – undo
92 92
 		// Load the settings.
93 93
 		$this->init_settings();
94 94
 
95
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
96
-		$this->title                = $this->get_option( 'title' );
97
-		$this->description          = $this->get_option( 'description' );
98
-		$this->enabled              = $this->get_option( 'enabled' );
99
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
100
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
101
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
102
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
103
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
104
-
105
-		if ( $this->testmode ) {
106
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
107
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
95
+		$main_settings              = get_option('woocommerce_stripe_settings');
96
+		$this->title                = $this->get_option('title');
97
+		$this->description          = $this->get_option('description');
98
+		$this->enabled              = $this->get_option('enabled');
99
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
100
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
101
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
102
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
103
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
104
+
105
+		if ($this->testmode) {
106
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
107
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
108 108
 		}
109 109
 
110
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
111
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
112
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
113
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
110
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
111
+		add_action('admin_notices', array($this, 'check_environment'));
112
+		add_action('admin_head', array($this, 'remove_admin_notice'));
113
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
114 114
 	}
115 115
 
116 116
 	/**
@@ -120,19 +120,19 @@  discard block
 block discarded – undo
120 120
 	 * @version 4.0.0
121 121
 	 */
122 122
 	public function check_environment() {
123
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
123
+		if ( ! current_user_can('manage_woocommerce')) {
124 124
 			return;
125 125
 		}
126 126
 
127 127
 		$environment_warning = $this->get_environment_warning();
128 128
 
129
-		if ( $environment_warning ) {
130
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
129
+		if ($environment_warning) {
130
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
131 131
 		}
132 132
 
133
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
134
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
135
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
133
+		foreach ((array) $this->notices as $notice_key => $notice) {
134
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
135
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
136 136
 			echo '</p></div>';
137 137
 		}
138 138
 	}
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
 	 * @version 4.0.0
146 146
 	 */
147 147
 	public function get_environment_warning() {
148
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
149
-			$message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
148
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
149
+			$message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
150 150
 
151 151
 			return $message;
152 152
 		}
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
 	 * @return array
163 163
 	 */
164 164
 	public function get_supported_currency() {
165
-		return apply_filters( 'wc_stripe_sepa_supported_currencies', array(
165
+		return apply_filters('wc_stripe_sepa_supported_currencies', array(
166 166
 			'EUR',
167
-		) );
167
+		));
168 168
 	}
169 169
 
170 170
 	/**
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
 	 * @return bool
176 176
 	 */
177 177
 	public function is_available() {
178
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
178
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
179 179
 			return false;
180 180
 		}
181 181
 
182
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
182
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
183 183
 			return false;
184 184
 		}
185 185
 
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 
201 201
 		$icons_str .= $icons['sepa'];
202 202
 
203
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
203
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
204 204
 	}
205 205
 
206 206
 	/**
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
 	 * @access public
212 212
 	 */
213 213
 	public function payment_scripts() {
214
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
214
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
215 215
 			return;
216 216
 		}
217 217
 
218
-		wp_enqueue_style( 'stripe_paymentfonts' );
219
-		wp_enqueue_script( 'woocommerce_stripe' );
218
+		wp_enqueue_style('stripe_paymentfonts');
219
+		wp_enqueue_script('woocommerce_stripe');
220 220
 	}
221 221
 
222 222
 	/**
223 223
 	 * Initialize Gateway Settings Form Fields.
224 224
 	 */
225 225
 	public function init_form_fields() {
226
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
226
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
227 227
 	}
228 228
 
229 229
 	/**
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	 */
236 236
 	public function mandate_display() {
237 237
 		/* translators: statement descriptor */
238
-		printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) );
238
+		printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor));
239 239
 	}
240 240
 
241 241
 	/**
@@ -246,24 +246,24 @@  discard block
 block discarded – undo
246 246
 	 */
247 247
 	public function form() {
248 248
 		?>
249
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
250
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
249
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
250
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
251 251
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
252 252
 			<p class="form-row form-row-wide">
253 253
 				<label for="stripe-sepa-owner">
254
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
254
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
255 255
 				</label>
256 256
 				<input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
257 257
 			</p>
258 258
 			<p class="form-row form-row-wide">
259 259
 				<label for="stripe-sepa-iban">
260
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
260
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
261 261
 				</label>
262 262
 				<input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
263 263
 			</p>
264 264
 			<!-- Used to display form errors -->
265 265
 			<div class="stripe-source-errors" role="alert"></div>
266
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
266
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
267 267
 			<div class="clear"></div>
268 268
 		</fieldset>
269 269
 		<?php
@@ -275,42 +275,42 @@  discard block
 block discarded – undo
275 275
 	public function payment_fields() {
276 276
 		$user                 = wp_get_current_user();
277 277
 		$total                = WC()->cart->total;
278
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
278
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
279 279
 
280 280
 		// If paying from order, we need to get total from order not cart.
281
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
282
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
281
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
282
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
283 283
 			$total = $order->get_total();
284 284
 		}
285 285
 
286
-		if ( is_add_payment_method_page() ) {
287
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
288
-			$total        = '';
286
+		if (is_add_payment_method_page()) {
287
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
288
+			$total = '';
289 289
 		} else {
290 290
 			$pay_button_text = '';
291 291
 		}
292 292
 
293 293
 		echo '<div
294 294
 			id="stripe-sepa_debit-payment-data"
295
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
296
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
295
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
296
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
297 297
 
298
-		if ( $this->description ) {
299
-			if ( $this->testmode ) {
300
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
301
-				$this->description  = trim( $this->description );
298
+		if ($this->description) {
299
+			if ($this->testmode) {
300
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
301
+				$this->description  = trim($this->description);
302 302
 			}
303
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
303
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
304 304
 		}
305 305
 
306
-		if ( $display_tokenization ) {
306
+		if ($display_tokenization) {
307 307
 			$this->tokenization_script();
308 308
 			$this->saved_payment_methods();
309 309
 		}
310 310
 
311 311
 		$this->form();
312 312
 
313
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
313
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
314 314
 			$this->save_payment_method_checkbox();
315 315
 		}
316 316
 
@@ -328,95 +328,95 @@  discard block
 block discarded – undo
328 328
 	 *
329 329
 	 * @return array|void
330 330
 	 */
331
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
331
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
332 332
 		try {
333
-			$order = wc_get_order( $order_id );
333
+			$order = wc_get_order($order_id);
334 334
 
335 335
 			// This comes from the create account checkbox in the checkout page.
336
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
336
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
337 337
 
338
-			if ( $create_account ) {
338
+			if ($create_account) {
339 339
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
340
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
340
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
341 341
 				$new_stripe_customer->create_customer();
342 342
 			}
343 343
 
344
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
344
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
345 345
 
346
-			$this->save_source_to_order( $order, $prepared_source );
346
+			$this->save_source_to_order($order, $prepared_source);
347 347
 
348 348
 			// Result from Stripe API request.
349 349
 			$response = null;
350 350
 
351
-			if ( $order->get_total() > 0 ) {
351
+			if ($order->get_total() > 0) {
352 352
 				// This will throw exception if not valid.
353
-				$this->validate_minimum_order_amount( $order );
353
+				$this->validate_minimum_order_amount($order);
354 354
 
355
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
355
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
356 356
 
357 357
 				// Make the request.
358
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
358
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
359 359
 
360
-				if ( ! empty( $response->error ) ) {
360
+				if ( ! empty($response->error)) {
361 361
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
362
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
363
-						if ( WC_Stripe_Helper::is_pre_30() ) {
364
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
365
-							delete_post_meta( $order_id, '_stripe_customer_id' );
362
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
363
+						if (WC_Stripe_Helper::is_pre_30()) {
364
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
365
+							delete_post_meta($order_id, '_stripe_customer_id');
366 366
 						} else {
367
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
368
-							$order->delete_meta_data( '_stripe_customer_id' );
367
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
368
+							$order->delete_meta_data('_stripe_customer_id');
369 369
 							$order->save();
370 370
 						}
371 371
 
372
-						return $this->process_payment( $order_id, false, $force_save_source );
373
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
372
+						return $this->process_payment($order_id, false, $force_save_source);
373
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
374 374
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
375
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
375
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
376 376
 						$wc_token->delete();
377
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
378
-						$order->add_order_note( $localized_message );
379
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
377
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
378
+						$order->add_order_note($localized_message);
379
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
380 380
 					}
381 381
 
382 382
 					// We want to retry.
383
-					if ( $this->is_retryable_error( $response->error ) ) {
384
-						if ( $retry ) {
383
+					if ($this->is_retryable_error($response->error)) {
384
+						if ($retry) {
385 385
 							// Don't do anymore retries after this.
386
-							if ( 5 <= $this->retry_interval ) {
386
+							if (5 <= $this->retry_interval) {
387 387
 
388
-								return $this->process_payment( $order_id, false, $force_save_source );
388
+								return $this->process_payment($order_id, false, $force_save_source);
389 389
 							}
390 390
 
391
-							sleep( $this->retry_interval );
391
+							sleep($this->retry_interval);
392 392
 
393 393
 							$this->retry_interval++;
394 394
 
395
-							return $this->process_payment( $order_id, true, $force_save_source );
395
+							return $this->process_payment($order_id, true, $force_save_source);
396 396
 						} else {
397
-							$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
398
-							$order->add_order_note( $localized_message );
399
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
397
+							$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
398
+							$order->add_order_note($localized_message);
399
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
400 400
 						}
401 401
 					}
402 402
 
403 403
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
404 404
 
405
-					if ( 'card_error' === $response->error->type ) {
406
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
405
+					if ('card_error' === $response->error->type) {
406
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
407 407
 					} else {
408
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
408
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
409 409
 					}
410 410
 
411
-					$order->add_order_note( $localized_message );
411
+					$order->add_order_note($localized_message);
412 412
 
413
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
413
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
414 414
 				}
415 415
 
416
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
416
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
417 417
 
418 418
 				// Process valid response.
419
-				$this->process_response( $response, $order );
419
+				$this->process_response($response, $order);
420 420
 			} else {
421 421
 				$order->payment_complete();
422 422
 			}
@@ -427,17 +427,17 @@  discard block
 block discarded – undo
427 427
 			// Return thank you page redirect.
428 428
 			return array(
429 429
 				'result'   => 'success',
430
-				'redirect' => $this->get_return_url( $order ),
430
+				'redirect' => $this->get_return_url($order),
431 431
 			);
432 432
 
433
-		} catch ( WC_Stripe_Exception $e ) {
434
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
435
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
433
+		} catch (WC_Stripe_Exception $e) {
434
+			wc_add_notice($e->getLocalizedMessage(), 'error');
435
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
436 436
 
437
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
437
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
438 438
 
439
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
440
-				$this->send_failed_order_email( $order_id );
439
+			if ($order->has_status(array('pending', 'failed'))) {
440
+				$this->send_failed_order_email($order_id);
441 441
 			}
442 442
 
443 443
 			return array(
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +174 added lines, -174 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
 
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public function __construct() {
34 34
 		$this->retry_interval = 2;
35
-		$stripe_settings      = get_option( 'woocommerce_stripe_settings', array() );
36
-		$this->testmode       = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false;
37
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
35
+		$stripe_settings      = get_option('woocommerce_stripe_settings', array());
36
+		$this->testmode       = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false;
37
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
38 38
 	}
39 39
 
40 40
 	/**
@@ -44,24 +44,24 @@  discard block
 block discarded – undo
44 44
 	 * @version 4.0.0
45 45
 	 */
46 46
 	public function check_for_webhook() {
47
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
48
-			|| ! isset( $_GET['wc-api'] )
49
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
47
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
48
+			|| ! isset($_GET['wc-api'])
49
+			|| ('wc_stripe' !== $_GET['wc-api'])
50 50
 		) {
51 51
 			return;
52 52
 		}
53 53
 
54
-		$request_body    = file_get_contents( 'php://input' );
55
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
54
+		$request_body    = file_get_contents('php://input');
55
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
56 56
 
57 57
 		// Validate it to make sure it is legit.
58
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
59
-			$this->process_webhook( $request_body );
60
-			status_header( 200 );
58
+		if ($this->is_valid_request($request_headers, $request_body)) {
59
+			$this->process_webhook($request_body);
60
+			status_header(200);
61 61
 			exit;
62 62
 		} else {
63
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
64
-			status_header( 400 );
63
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
64
+			status_header(400);
65 65
 			exit;
66 66
 		}
67 67
 	}
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 	 * @param string $request_body The request body from Stripe.
77 77
 	 * @return bool
78 78
 	 */
79
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
80
-		if ( null === $request_headers || null === $request_body ) {
79
+	public function is_valid_request($request_headers = null, $request_body = null) {
80
+		if (null === $request_headers || null === $request_body) {
81 81
 			return false;
82 82
 		}
83 83
 
84
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
84
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
85 85
 			return false;
86 86
 		}
87 87
 
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 * @version 4.0.0
98 98
 	 */
99 99
 	public function get_request_headers() {
100
-		if ( ! function_exists( 'getallheaders' ) ) {
100
+		if ( ! function_exists('getallheaders')) {
101 101
 			$headers = [];
102
-			foreach ( $_SERVER as $name => $value ) {
103
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
104
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
102
+			foreach ($_SERVER as $name => $value) {
103
+				if ('HTTP_' === substr($name, 0, 5)) {
104
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
105 105
 				}
106 106
 			}
107 107
 
@@ -120,30 +120,30 @@  discard block
 block discarded – undo
120 120
 	 * @param object $notification
121 121
 	 * @param bool $retry
122 122
 	 */
123
-	public function process_webhook_payment( $notification, $retry = true ) {
123
+	public function process_webhook_payment($notification, $retry = true) {
124 124
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
125
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
125
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
126 126
 			return;
127 127
 		}
128 128
 
129
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
129
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
130 130
 
131
-		if ( ! $order ) {
132
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
131
+		if ( ! $order) {
132
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
133 133
 			return;
134 134
 		}
135 135
 
136 136
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
137 137
 		$source_id = $notification->data->object->id;
138 138
 
139
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
139
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
140 140
 
141 141
 		try {
142
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
142
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
143 143
 				return;
144 144
 			}
145 145
 
146
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
146
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
147 147
 				return;
148 148
 			}
149 149
 
@@ -151,95 +151,95 @@  discard block
 block discarded – undo
151 151
 			$response = null;
152 152
 
153 153
 			// This will throw exception if not valid.
154
-			$this->validate_minimum_order_amount( $order );
154
+			$this->validate_minimum_order_amount($order);
155 155
 
156
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
156
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
157 157
 
158 158
 			// Prep source object.
159 159
 			$source_object           = new stdClass();
160 160
 			$source_object->token_id = '';
161
-			$source_object->customer = $this->get_stripe_customer_id( $order );
161
+			$source_object->customer = $this->get_stripe_customer_id($order);
162 162
 			$source_object->source   = $source_id;
163 163
 
164 164
 			// Make the request.
165
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
165
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
166 166
 			$headers  = $response['headers'];
167 167
 			$response = $response['body'];
168 168
 
169
-			if ( ! empty( $response->error ) ) {
169
+			if ( ! empty($response->error)) {
170 170
 				// We want to retry.
171
-				if ( $this->is_retryable_error( $response->error ) ) {
172
-					if ( $retry ) {
171
+				if ($this->is_retryable_error($response->error)) {
172
+					if ($retry) {
173 173
 						// Don't do anymore retries after this.
174
-						if ( 5 <= $this->retry_interval ) {
174
+						if (5 <= $this->retry_interval) {
175 175
 
176
-							return $this->process_webhook_payment( $notification, false );
176
+							return $this->process_webhook_payment($notification, false);
177 177
 						}
178 178
 
179
-						sleep( $this->retry_interval );
179
+						sleep($this->retry_interval);
180 180
 
181 181
 						$this->retry_interval++;
182
-						return $this->process_webhook_payment( $notification, true );
182
+						return $this->process_webhook_payment($notification, true);
183 183
 					} else {
184
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
185
-						$order->add_order_note( $localized_message );
186
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
184
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
185
+						$order->add_order_note($localized_message);
186
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
187 187
 					}
188 188
 				}
189 189
 
190 190
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
191
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
192
-					if ( WC_Stripe_Helper::is_pre_30() ) {
193
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
194
-						delete_post_meta( $order_id, '_stripe_customer_id' );
191
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
192
+					if (WC_Stripe_Helper::is_pre_30()) {
193
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
194
+						delete_post_meta($order_id, '_stripe_customer_id');
195 195
 					} else {
196
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
197
-						$order->delete_meta_data( '_stripe_customer_id' );
196
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
197
+						$order->delete_meta_data('_stripe_customer_id');
198 198
 						$order->save();
199 199
 					}
200 200
 
201
-					return $this->process_webhook_payment( $notification, false );
201
+					return $this->process_webhook_payment($notification, false);
202 202
 
203
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
203
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
204 204
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
205
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
205
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
206 206
 					$wc_token->delete();
207
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
208
-					$order->add_order_note( $message );
209
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
207
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
208
+					$order->add_order_note($message);
209
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
210 210
 				}
211 211
 
212 212
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
213 213
 
214
-				if ( 'card_error' === $response->error->type ) {
215
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
214
+				if ('card_error' === $response->error->type) {
215
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
216 216
 				} else {
217
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
217
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
218 218
 				}
219 219
 
220
-				$order->add_order_note( $localized_message );
220
+				$order->add_order_note($localized_message);
221 221
 
222
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
222
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
223 223
 			}
224 224
 
225 225
 			// To prevent double processing the order on WC side.
226
-			if ( ! $this->is_original_request( $headers ) ) {
226
+			if ( ! $this->is_original_request($headers)) {
227 227
 				return;
228 228
 			}
229 229
 
230
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
230
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
231 231
 
232
-			$this->process_response( $response, $order );
232
+			$this->process_response($response, $order);
233 233
 
234
-		} catch ( WC_Stripe_Exception $e ) {
235
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
234
+		} catch (WC_Stripe_Exception $e) {
235
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
236 236
 
237
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
237
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
238 238
 
239
-			$statuses = array( 'pending', 'failed' );
239
+			$statuses = array('pending', 'failed');
240 240
 
241
-			if ( $order->has_status( $statuses ) ) {
242
-				$this->send_failed_order_email( $order_id );
241
+			if ($order->has_status($statuses)) {
242
+				$this->send_failed_order_email($order_id);
243 243
 			}
244 244
 		}
245 245
 	}
@@ -252,21 +252,21 @@  discard block
 block discarded – undo
252 252
 	 * @since 4.0.0
253 253
 	 * @param object $notification
254 254
 	 */
255
-	public function process_webhook_dispute( $notification ) {
256
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
255
+	public function process_webhook_dispute($notification) {
256
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
257 257
 
258
-		if ( ! $order ) {
259
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
258
+		if ( ! $order) {
259
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
260 260
 			return;
261 261
 		}
262 262
 
263 263
 		/* translators: 1) The URL to the order. */
264
-		$order->update_status( 'on-hold', sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ) );
264
+		$order->update_status('on-hold', sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order)));
265 265
 
266
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
266
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
267 267
 
268 268
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
269
-		$this->send_failed_order_email( $order_id );
269
+		$this->send_failed_order_email($order_id);
270 270
 	}
271 271
 
272 272
 	/**
@@ -277,41 +277,41 @@  discard block
 block discarded – undo
277 277
 	 * @version 4.0.0
278 278
 	 * @param object $notification
279 279
 	 */
280
-	public function process_webhook_capture( $notification ) {
281
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
280
+	public function process_webhook_capture($notification) {
281
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
282 282
 
283
-		if ( ! $order ) {
284
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
283
+		if ( ! $order) {
284
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
285 285
 			return;
286 286
 		}
287 287
 
288 288
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
289 289
 
290
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
291
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
292
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
290
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
291
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
292
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
293 293
 
294
-			if ( $charge && 'no' === $captured ) {
295
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
294
+			if ($charge && 'no' === $captured) {
295
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
296 296
 
297 297
 				// Store other data such as fees
298
-				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 );
298
+				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);
299 299
 
300
-				if ( isset( $notification->data->object->balance_transaction ) ) {
301
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
300
+				if (isset($notification->data->object->balance_transaction)) {
301
+					$this->update_fees($order, $notification->data->object->balance_transaction);
302 302
 				}
303 303
 
304
-				if ( is_callable( array( $order, 'save' ) ) ) {
304
+				if (is_callable(array($order, 'save'))) {
305 305
 					$order->save();
306 306
 				}
307 307
 
308 308
 				/* translators: transaction id */
309
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
309
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
310 310
 
311 311
 				// Check and see if capture is partial.
312
-				if ( $this->is_partial_capture( $notification ) ) {
313
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
314
-					$order->add_order_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
312
+				if ($this->is_partial_capture($notification)) {
313
+					$order->set_total($this->get_partial_amount_to_charge($notification));
314
+					$order->add_order_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
315 315
 					$order->save();
316 316
 				}
317 317
 			}
@@ -326,38 +326,38 @@  discard block
 block discarded – undo
326 326
 	 * @version 4.0.0
327 327
 	 * @param object $notification
328 328
 	 */
329
-	public function process_webhook_charge_succeeded( $notification ) {
329
+	public function process_webhook_charge_succeeded($notification) {
330 330
 		// The following payment methods are synchronous so does not need to be handle via webhook.
331
-		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 ) ) {
331
+		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)) {
332 332
 			return;
333 333
 		}
334 334
 
335
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
335
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
336 336
 
337
-		if ( ! $order ) {
338
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
337
+		if ( ! $order) {
338
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
339 339
 			return;
340 340
 		}
341 341
 
342 342
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
343 343
 
344
-		if ( 'on-hold' !== $order->get_status() ) {
344
+		if ('on-hold' !== $order->get_status()) {
345 345
 			return;
346 346
 		}
347 347
 
348 348
 		// Store other data such as fees
349
-		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 );
349
+		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);
350 350
 
351
-		if ( isset( $notification->data->object->balance_transaction ) ) {
352
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
351
+		if (isset($notification->data->object->balance_transaction)) {
352
+			$this->update_fees($order, $notification->data->object->balance_transaction);
353 353
 		}
354 354
 
355
-		if ( is_callable( array( $order, 'save' ) ) ) {
355
+		if (is_callable(array($order, 'save'))) {
356 356
 			$order->save();
357 357
 		}
358 358
 
359 359
 		/* translators: transaction id */
360
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
360
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
361 361
 	}
362 362
 
363 363
 	/**
@@ -368,23 +368,23 @@  discard block
 block discarded – undo
368 368
 	 * @version 4.0.0
369 369
 	 * @param object $notification
370 370
 	 */
371
-	public function process_webhook_charge_failed( $notification ) {
372
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
371
+	public function process_webhook_charge_failed($notification) {
372
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
373 373
 
374
-		if ( ! $order ) {
375
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
374
+		if ( ! $order) {
375
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
376 376
 			return;
377 377
 		}
378 378
 
379 379
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
380 380
 
381
-		if ( 'on-hold' !== $order->get_status() ) {
381
+		if ('on-hold' !== $order->get_status()) {
382 382
 			return;
383 383
 		}
384 384
 
385
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
385
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
386 386
 
387
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
387
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
388 388
 	}
389 389
 
390 390
 	/**
@@ -395,23 +395,23 @@  discard block
 block discarded – undo
395 395
 	 * @version 4.0.0
396 396
 	 * @param object $notification
397 397
 	 */
398
-	public function process_webhook_source_canceled( $notification ) {
399
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
398
+	public function process_webhook_source_canceled($notification) {
399
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
400 400
 
401
-		if ( ! $order ) {
402
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
401
+		if ( ! $order) {
402
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
403 403
 			return;
404 404
 		}
405 405
 
406 406
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
407 407
 
408
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
408
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
409 409
 			return;
410 410
 		}
411 411
 
412
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
412
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
413 413
 
414
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
414
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
415 415
 	}
416 416
 
417 417
 	/**
@@ -422,42 +422,42 @@  discard block
 block discarded – undo
422 422
 	 * @version 4.0.0
423 423
 	 * @param object $notification
424 424
 	 */
425
-	public function process_webhook_refund( $notification ) {
426
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
425
+	public function process_webhook_refund($notification) {
426
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
427 427
 
428
-		if ( ! $order ) {
429
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
428
+		if ( ! $order) {
429
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
430 430
 			return;
431 431
 		}
432 432
 
433 433
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
434 434
 
435
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
436
-			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
437
-			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
438
-			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
435
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
436
+			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
437
+			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
438
+			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
439 439
 
440 440
 			// If the refund ID matches, don't continue to prevent double refunding.
441
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
441
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
442 442
 				return;
443 443
 			}
444 444
 
445 445
 			// Only refund captured charge.
446
-			if ( $charge ) {
447
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
446
+			if ($charge) {
447
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
448 448
 
449 449
 				// Create the refund.
450
-				$refund = wc_create_refund( array(
450
+				$refund = wc_create_refund(array(
451 451
 					'order_id'       => $order_id,
452
-					'amount'         => $this->get_refund_amount( $notification ),
452
+					'amount'         => $this->get_refund_amount($notification),
453 453
 					'reason'         => $reason,
454
-				) );
454
+				));
455 455
 
456
-				if ( is_wp_error( $refund ) ) {
457
-					WC_Stripe_Logger::log( $refund->get_error_message() );
456
+				if (is_wp_error($refund)) {
457
+					WC_Stripe_Logger::log($refund->get_error_message());
458 458
 				}
459 459
 
460
-				$order->add_order_note( $reason );
460
+				$order->add_order_note($reason);
461 461
 			}
462 462
 		}
463 463
 	}
@@ -468,21 +468,21 @@  discard block
 block discarded – undo
468 468
 	 * @since 4.0.6
469 469
 	 * @param object $notification
470 470
 	 */
471
-	public function process_review_opened( $notification ) {
472
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
471
+	public function process_review_opened($notification) {
472
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
473 473
 
474
-		if ( ! $order ) {
475
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
474
+		if ( ! $order) {
475
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
476 476
 			return;
477 477
 		}
478 478
 
479 479
 		/* translators: 1) The URL to the order. 2) The reason type. */
480
-		$message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason );
480
+		$message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason);
481 481
 
482
-		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
483
-			$order->update_status( 'on-hold', $message );
482
+		if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
483
+			$order->update_status('on-hold', $message);
484 484
 		} else {
485
-			$order->add_order_note( $message );
485
+			$order->add_order_note($message);
486 486
 		}
487 487
 	}
488 488
 
@@ -492,25 +492,25 @@  discard block
 block discarded – undo
492 492
 	 * @since 4.0.6
493 493
 	 * @param object $notification
494 494
 	 */
495
-	public function process_review_closed( $notification ) {
496
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
495
+	public function process_review_closed($notification) {
496
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
497 497
 
498
-		if ( ! $order ) {
499
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
498
+		if ( ! $order) {
499
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
500 500
 			return;
501 501
 		}
502 502
 
503 503
 		/* translators: 1) The reason type. */
504
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
504
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
505 505
 
506
-		if ( 'on-hold' === $order->get_status() ) {
507
-			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
508
-				$order->update_status( 'processing', $message );
506
+		if ('on-hold' === $order->get_status()) {
507
+			if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
508
+				$order->update_status('processing', $message);
509 509
 			} else {
510
-				$order->add_order_note( $message );
510
+				$order->add_order_note($message);
511 511
 			}
512 512
 		} else {
513
-			$order->add_order_note( $message );
513
+			$order->add_order_note($message);
514 514
 		}
515 515
 	}
516 516
 
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	 * @version 4.0.0
522 522
 	 * @param object $notification
523 523
 	 */
524
-	public function is_partial_capture( $notification ) {
524
+	public function is_partial_capture($notification) {
525 525
 		return 0 < $notification->data->object->amount_refunded;
526 526
 	}
527 527
 
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
 	 * @version 4.0.0
533 533
 	 * @param object $notification
534 534
 	 */
535
-	public function get_refund_amount( $notification ) {
536
-		if ( $this->is_partial_capture( $notification ) ) {
535
+	public function get_refund_amount($notification) {
536
+		if ($this->is_partial_capture($notification)) {
537 537
 			$amount = $notification->data->object->amount_refunded / 100;
538 538
 
539
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
539
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
540 540
 				$amount = $notification->data->object->amount_refunded;
541 541
 			}
542 542
 
@@ -553,12 +553,12 @@  discard block
 block discarded – undo
553 553
 	 * @version 4.0.0
554 554
 	 * @param object $notification
555 555
 	 */
556
-	public function get_partial_amount_to_charge( $notification ) {
557
-		if ( $this->is_partial_capture( $notification ) ) {
558
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
556
+	public function get_partial_amount_to_charge($notification) {
557
+		if ($this->is_partial_capture($notification)) {
558
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
559 559
 
560
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
561
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
560
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
561
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
562 562
 			}
563 563
 
564 564
 			return $amount;
@@ -574,44 +574,44 @@  discard block
 block discarded – undo
574 574
 	 * @version 4.0.0
575 575
 	 * @param string $request_body
576 576
 	 */
577
-	public function process_webhook( $request_body ) {
578
-		$notification = json_decode( $request_body );
577
+	public function process_webhook($request_body) {
578
+		$notification = json_decode($request_body);
579 579
 
580
-		switch ( $notification->type ) {
580
+		switch ($notification->type) {
581 581
 			case 'source.chargeable':
582
-				$this->process_webhook_payment( $notification );
582
+				$this->process_webhook_payment($notification);
583 583
 				break;
584 584
 
585 585
 			case 'source.canceled':
586
-				$this->process_webhook_source_canceled( $notification );
586
+				$this->process_webhook_source_canceled($notification);
587 587
 				break;
588 588
 
589 589
 			case 'charge.succeeded':
590
-				$this->process_webhook_charge_succeeded( $notification );
590
+				$this->process_webhook_charge_succeeded($notification);
591 591
 				break;
592 592
 
593 593
 			case 'charge.failed':
594
-				$this->process_webhook_charge_failed( $notification );
594
+				$this->process_webhook_charge_failed($notification);
595 595
 				break;
596 596
 
597 597
 			case 'charge.captured':
598
-				$this->process_webhook_capture( $notification );
598
+				$this->process_webhook_capture($notification);
599 599
 				break;
600 600
 
601 601
 			case 'charge.dispute.created':
602
-				$this->process_webhook_dispute( $notification );
602
+				$this->process_webhook_dispute($notification);
603 603
 				break;
604 604
 
605 605
 			case 'charge.refunded':
606
-				$this->process_webhook_refund( $notification );
606
+				$this->process_webhook_refund($notification);
607 607
 				break;
608 608
 
609 609
 			case 'review.opened':
610
-				$this->process_review_opened( $notification );
610
+				$this->process_review_opened($notification);
611 611
 				break;
612 612
 
613 613
 			case 'review.closed':
614
-				$this->process_review_closed( $notification );
614
+				$this->process_review_closed($notification);
615 615
 				break;
616 616
 
617 617
 		}
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +29 added lines, -29 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
 	/**
@@ -96,16 +96,16 @@  discard block
 block discarded – undo
96 96
 	 * @param bool $with_headers To get the response with headers.
97 97
 	 * @return array|WP_Error
98 98
 	 */
99
-	public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) {
100
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
99
+	public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) {
100
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
101 101
 
102 102
 		$headers = self::get_headers();
103 103
 
104
-		if ( 'charges' === $api && 'POST' === $method ) {
105
-			$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
106
-			$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
104
+		if ('charges' === $api && 'POST' === $method) {
105
+			$customer = ! empty($request['customer']) ? $request['customer'] : '';
106
+			$source   = ! empty($request['source']) ? $request['source'] : $customer;
107 107
 
108
-			$headers['Idempotency-Key'] = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request );
108
+			$headers['Idempotency-Key'] = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request);
109 109
 		}
110 110
 
111 111
 		$response = wp_safe_remote_post(
@@ -113,21 +113,21 @@  discard block
 block discarded – undo
113 113
 			array(
114 114
 				'method'  => $method,
115 115
 				'headers' => $headers,
116
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
116
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
117 117
 				'timeout' => 70,
118 118
 			)
119 119
 		);
120 120
 
121
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
122
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
123
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
121
+		if (is_wp_error($response) || empty($response['body'])) {
122
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
123
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
124 124
 		}
125 125
 
126
-		if ( $with_headers ) {
127
-			return array( 'headers' => wp_remote_retrieve_headers( $response ), 'body' => json_decode( $response['body'] ) );
126
+		if ($with_headers) {
127
+			return array('headers' => wp_remote_retrieve_headers($response), 'body' => json_decode($response['body']));
128 128
 		}
129 129
 
130
-		return json_decode( $response['body'] );
130
+		return json_decode($response['body']);
131 131
 	}
132 132
 
133 133
 	/**
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @version 4.0.0
138 138
 	 * @param string $api
139 139
 	 */
140
-	public static function retrieve( $api ) {
141
-		WC_Stripe_Logger::log( "{$api}" );
140
+	public static function retrieve($api) {
141
+		WC_Stripe_Logger::log("{$api}");
142 142
 
143 143
 		$response = wp_safe_remote_get(
144 144
 			self::ENDPOINT . $api,
@@ -149,11 +149,11 @@  discard block
 block discarded – undo
149 149
 			)
150 150
 		);
151 151
 
152
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
153
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
154
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
152
+		if (is_wp_error($response) || empty($response['body'])) {
153
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
154
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
155 155
 		}
156 156
 
157
-		return json_decode( $response['body'] );
157
+		return json_decode($response['body']);
158 158
 	}
159 159
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$this->retry_interval = 1;
25 25
 
26
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
28
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
29
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
30
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
31
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
26
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
27
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
28
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
29
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
30
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
31
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
32 32
 	}
33 33
 
34 34
 	/**
@@ -49,25 +49,25 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function process_redirect_payment( $order_id, $retry = true ) {
52
+	public function process_redirect_payment($order_id, $retry = true) {
53 53
 		try {
54
-			$source = wc_clean( $_GET['source'] );
54
+			$source = wc_clean($_GET['source']);
55 55
 
56
-			if ( empty( $source ) ) {
56
+			if (empty($source)) {
57 57
 				return;
58 58
 			}
59 59
 
60
-			if ( empty( $order_id ) ) {
60
+			if (empty($order_id)) {
61 61
 				return;
62 62
 			}
63 63
 
64
-			$order = wc_get_order( $order_id );
64
+			$order = wc_get_order($order_id);
65 65
 
66
-			if ( ! is_object( $order ) ) {
66
+			if ( ! is_object($order)) {
67 67
 				return;
68 68
 			}
69 69
 
70
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
70
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
71 71
 				return;
72 72
 			}
73 73
 
@@ -75,129 +75,129 @@  discard block
 block discarded – undo
75 75
 			$response = null;
76 76
 
77 77
 			// This will throw exception if not valid.
78
-			$this->validate_minimum_order_amount( $order );
78
+			$this->validate_minimum_order_amount($order);
79 79
 
80
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
80
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
81 81
 
82 82
 			/**
83 83
 			 * First check if the source is chargeable at this time. If not,
84 84
 			 * webhook will take care of it later.
85 85
 			 */
86
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
86
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
87 87
 
88
-			if ( ! empty( $source_info->error ) ) {
89
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
88
+			if ( ! empty($source_info->error)) {
89
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
90 90
 			}
91 91
 
92
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
93
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
92
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
93
+				throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
94 94
 			}
95 95
 
96 96
 			// If already consumed, then ignore request.
97
-			if ( 'consumed' === $source_info->status ) {
97
+			if ('consumed' === $source_info->status) {
98 98
 				return;
99 99
 			}
100 100
 
101 101
 			// If not chargeable, then ignore request.
102
-			if ( 'chargeable' !== $source_info->status ) {
102
+			if ('chargeable' !== $source_info->status) {
103 103
 				return;
104 104
 			}
105 105
 
106 106
 			// Prep source object.
107 107
 			$source_object           = new stdClass();
108 108
 			$source_object->token_id = '';
109
-			$source_object->customer = $this->get_stripe_customer_id( $order );
109
+			$source_object->customer = $this->get_stripe_customer_id($order);
110 110
 			$source_object->source   = $source_info->id;
111 111
 
112 112
 			/* If we're doing a retry and source is chargeable, we need to pass
113 113
 			 * a different idempotency key and retry for success.
114 114
 			 */
115
-			if ( 1 < $this->retry_interval && 'chargeable' === $source_info->status ) {
116
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
115
+			if (1 < $this->retry_interval && 'chargeable' === $source_info->status) {
116
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
117 117
 			}
118 118
 
119 119
 			// Make the request.
120
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
120
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
121 121
 			$headers  = $response['headers'];
122 122
 			$response = $response['body'];
123 123
 
124
-			if ( ! empty( $response->error ) ) {
124
+			if ( ! empty($response->error)) {
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
 				// We want to retry.
149
-				if ( $this->is_retryable_error( $response->error ) ) {
150
-					if ( $retry ) {
149
+				if ($this->is_retryable_error($response->error)) {
150
+					if ($retry) {
151 151
 						// Don't do anymore retries after this.
152
-						if ( 5 <= $this->retry_interval ) {
153
-							return $this->process_redirect_payment( $order_id, false );
152
+						if (5 <= $this->retry_interval) {
153
+							return $this->process_redirect_payment($order_id, false);
154 154
 						}
155 155
 
156
-						sleep( $this->retry_interval );
156
+						sleep($this->retry_interval);
157 157
 
158 158
 						$this->retry_interval++;
159
-						return $this->process_redirect_payment( $order_id, true );
159
+						return $this->process_redirect_payment($order_id, true);
160 160
 					} else {
161
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
162
-						$order->add_order_note( $localized_message );
163
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
161
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
162
+						$order->add_order_note($localized_message);
163
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
164 164
 					}
165 165
 				}
166 166
 
167 167
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
168 168
 
169
-				if ( 'card_error' === $response->error->type ) {
170
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
169
+				if ('card_error' === $response->error->type) {
170
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
171 171
 				} else {
172
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
172
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
173 173
 				}
174 174
 
175
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
175
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
176 176
 			}
177 177
 
178 178
 			// To prevent double processing the order on WC side.
179
-			if ( ! $this->is_original_request( $headers ) ) {
179
+			if ( ! $this->is_original_request($headers)) {
180 180
 				return;
181 181
 			}
182 182
 
183
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
183
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
184 184
 
185
-			$this->process_response( $response, $order );
185
+			$this->process_response($response, $order);
186 186
 
187
-		} catch ( WC_Stripe_Exception $e ) {
188
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
187
+		} catch (WC_Stripe_Exception $e) {
188
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
189 189
 
190
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
190
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
191 191
 
192 192
 			/* translators: error message */
193
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
193
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
194 194
 
195
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
196
-				$this->send_failed_order_email( $order_id );
195
+			if ($order->has_status(array('pending', 'failed'))) {
196
+				$this->send_failed_order_email($order_id);
197 197
 			}
198 198
 
199
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
200
-			wp_safe_redirect( wc_get_checkout_url() );
199
+			wc_add_notice($e->getLocalizedMessage(), 'error');
200
+			wp_safe_redirect(wc_get_checkout_url());
201 201
 			exit;
202 202
 		}
203 203
 	}
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
 	 * @version 4.0.0
210 210
 	 */
211 211
 	public function maybe_process_redirect_order() {
212
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
212
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
213 213
 			return;
214 214
 		}
215 215
 
216
-		$order_id = wc_clean( $_GET['order_id'] );
216
+		$order_id = wc_clean($_GET['order_id']);
217 217
 
218
-		$this->process_redirect_payment( $order_id );
218
+		$this->process_redirect_payment($order_id);
219 219
 	}
220 220
 
221 221
 	/**
@@ -225,52 +225,52 @@  discard block
 block discarded – undo
225 225
 	 * @version 4.0.0
226 226
 	 * @param  int $order_id
227 227
 	 */
228
-	public function capture_payment( $order_id ) {
229
-		$order = wc_get_order( $order_id );
228
+	public function capture_payment($order_id) {
229
+		$order = wc_get_order($order_id);
230 230
 
231
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
232
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
233
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
231
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
232
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
233
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
234 234
 
235
-			if ( $charge && 'no' === $captured ) {
235
+			if ($charge && 'no' === $captured) {
236 236
 				$order_total = $order->get_total();
237 237
 
238
-				if ( 0 < $order->get_total_refunded() ) {
238
+				if (0 < $order->get_total_refunded()) {
239 239
 					$order_total = $order_total - $order->get_total_refunded();
240 240
 				}
241 241
 
242
-				$result = WC_Stripe_API::request( array(
243
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
242
+				$result = WC_Stripe_API::request(array(
243
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
244 244
 					'expand[]' => 'balance_transaction',
245
-				), 'charges/' . $charge . '/capture' );
245
+				), 'charges/' . $charge . '/capture');
246 246
 
247
-				if ( ! empty( $result->error ) ) {
247
+				if ( ! empty($result->error)) {
248 248
 					/* translators: error message */
249
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
249
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
250 250
 				} else {
251 251
 					/* translators: transaction id */
252
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
253
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
252
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
253
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
254 254
 
255 255
 					// Store other data such as fees
256
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
256
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
257 257
 
258
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
258
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
259 259
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
260 260
 						// values are in the local currency of the Stripe account, not from WC.
261
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
262
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
263
-						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 );
264
-						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 );
261
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
262
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
263
+						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);
264
+						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);
265 265
 					}
266 266
 
267
-					if ( is_callable( array( $order, 'save' ) ) ) {
267
+					if (is_callable(array($order, 'save'))) {
268 268
 						$order->save();
269 269
 					}
270 270
 				}
271 271
 
272 272
 				// This hook fires when admin manually changes order status to processing or completed.
273
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
273
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
274 274
 			}
275 275
 		}
276 276
 	}
@@ -282,14 +282,14 @@  discard block
 block discarded – undo
282 282
 	 * @version 4.0.0
283 283
 	 * @param  int $order_id
284 284
 	 */
285
-	public function cancel_payment( $order_id ) {
286
-		$order = wc_get_order( $order_id );
285
+	public function cancel_payment($order_id) {
286
+		$order = wc_get_order($order_id);
287 287
 
288
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
289
-			$this->process_refund( $order_id );
288
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
289
+			$this->process_refund($order_id);
290 290
 
291 291
 			// This hook fires when admin manually changes order status to cancel.
292
-			do_action( 'woocommerce_stripe_process_manual_cancel', $order );
292
+			do_action('woocommerce_stripe_process_manual_cancel', $order);
293 293
 		}
294 294
 	}
295 295
 
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 	 * @version 4.0.0
301 301
 	 */
302 302
 	public function validate_checkout() {
303
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
304
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
303
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
304
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
305 305
 		}
306 306
 
307 307
 		/*
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 		 * i.e. wp_send_json( 'success' ); // On successful validation.
310 310
 		 * i.e. For errors follow WC https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-checkout.php#L918-L938
311 311
 		 */
312
-		do_action( 'wc_stripe_validate_modal_checkout_action', $_POST['required_fields'], $_POST['all_fields'] );
312
+		do_action('wc_stripe_validate_modal_checkout_action', $_POST['required_fields'], $_POST['all_fields']);
313 313
 	}
314 314
 }
315 315
 
Please login to merge, or discard this patch.
includes/class-wc-stripe-apple-pay-registration.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @since 4.0.6
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if ( ! defined('ABSPATH')) {
9 9
 	exit;
10 10
 }
11 11
 
@@ -60,21 +60,21 @@  discard block
 block discarded – undo
60 60
 	public $apple_pay_verify_notice;
61 61
 
62 62
 	public function __construct() {
63
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
64
-		$this->stripe_enabled          = $this->get_option( 'enabled' );
65
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
66
-		$this->apple_pay_domain_set    = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
63
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
64
+		$this->stripe_enabled          = $this->get_option('enabled');
65
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
66
+		$this->apple_pay_domain_set    = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
67 67
 		$this->apple_pay_verify_notice = '';
68
-		$this->testmode                = 'yes' === $this->get_option( 'testmode', 'no' );
69
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
68
+		$this->testmode                = 'yes' === $this->get_option('testmode', 'no');
69
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
70 70
 
71
-		if ( empty( $this->stripe_settings ) ) {
71
+		if (empty($this->stripe_settings)) {
72 72
 			return;
73 73
 		}
74 74
 
75 75
 		$this->init_apple_pay();
76 76
 
77
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
77
+		add_action('admin_notices', array($this, 'admin_notices'));
78 78
 	}
79 79
 
80 80
 	/**
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
 	 * @param string default
86 86
 	 * @return string $setting_value
87 87
 	 */
88
-	public function get_option( $setting = '', $default = '' ) {
89
-		if ( empty( $this->stripe_settings ) ) {
88
+	public function get_option($setting = '', $default = '') {
89
+		if (empty($this->stripe_settings)) {
90 90
 			return $default;
91 91
 		}
92 92
 
93
-		if ( ! empty( $this->stripe_settings[ $setting ] ) ) {
94
-			return $this->stripe_settings[ $setting ];
93
+		if ( ! empty($this->stripe_settings[$setting])) {
94
+			return $this->stripe_settings[$setting];
95 95
 		}
96 96
 
97 97
 		return $default;
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 	public function init_apple_pay() {
107 107
 		if (
108 108
 			is_admin() &&
109
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
110
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
111
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
109
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
110
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
111
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
112 112
 			$this->payment_request
113 113
 		) {
114 114
 			$this->process_apple_pay_verification();
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 	 * @version 3.1.0
123 123
 	 * @param string $secret_key
124 124
 	 */
125
-	private function register_apple_pay_domain( $secret_key = '' ) {
126
-		if ( empty( $secret_key ) ) {
127
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
125
+	private function register_apple_pay_domain($secret_key = '') {
126
+		if (empty($secret_key)) {
127
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
128 128
 		}
129 129
 
130 130
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -138,23 +138,23 @@  discard block
 block discarded – undo
138 138
 			'Authorization' => 'Bearer ' . $secret_key,
139 139
 		);
140 140
 
141
-		$response = wp_remote_post( $endpoint, array(
141
+		$response = wp_remote_post($endpoint, array(
142 142
 			'headers' => $headers,
143
-			'body'    => http_build_query( $data ),
144
-		) );
143
+			'body'    => http_build_query($data),
144
+		));
145 145
 
146
-		if ( is_wp_error( $response ) ) {
146
+		if (is_wp_error($response)) {
147 147
 			/* translators: error message */
148
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
148
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
149 149
 		}
150 150
 
151
-		if ( 200 !== $response['response']['code'] ) {
152
-			$parsed_response = json_decode( $response['body'] );
151
+		if (200 !== $response['response']['code']) {
152
+			$parsed_response = json_decode($response['body']);
153 153
 
154 154
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
155 155
 
156 156
 			/* translators: error message */
157
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
157
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
158 158
 		}
159 159
 	}
160 160
 
@@ -166,45 +166,45 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	public function process_apple_pay_verification() {
168 168
 		try {
169
-			$path     = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] );
169
+			$path     = untrailingslashit($_SERVER['DOCUMENT_ROOT']);
170 170
 			$dir      = '.well-known';
171 171
 			$file     = 'apple-developer-merchantid-domain-association';
172 172
 			$fullpath = $path . '/' . $dir . '/' . $file;
173 173
 
174
-			if ( $this->apple_pay_domain_set && file_exists( $fullpath ) ) {
174
+			if ($this->apple_pay_domain_set && file_exists($fullpath)) {
175 175
 				return;
176 176
 			}
177 177
 
178
-			if ( ! file_exists( $path . '/' . $dir ) ) {
179
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine
180
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
178
+			if ( ! file_exists($path . '/' . $dir)) {
179
+				if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine
180
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
181 181
 				}
182 182
 			}
183 183
 
184
-			if ( ! file_exists( $fullpath ) ) {
185
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine
186
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
184
+			if ( ! file_exists($fullpath)) {
185
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine
186
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
187 187
 				}
188 188
 			}
189 189
 
190 190
 			// At this point then the domain association folder and file should be available.
191 191
 			// Proceed to verify/and or verify again.
192
-			$this->register_apple_pay_domain( $this->secret_key );
192
+			$this->register_apple_pay_domain($this->secret_key);
193 193
 
194 194
 			// No errors to this point, verification success!
195 195
 			$this->stripe_settings['apple_pay_domain_set'] = 'yes';
196 196
 			$this->apple_pay_domain_set = true;
197 197
 
198
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
198
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
199 199
 
200
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
200
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
201 201
 
202
-		} catch ( Exception $e ) {
202
+		} catch (Exception $e) {
203 203
 			$this->stripe_settings['apple_pay_domain_set'] = 'no';
204 204
 
205
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
205
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
206 206
 
207
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
207
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
208 208
 		}
209 209
 	}
210 210
 
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 	 * @since 4.0.6
215 215
 	 */
216 216
 	public function admin_notices() {
217
-		if ( ! $this->stripe_enabled ) {
217
+		if ( ! $this->stripe_enabled) {
218 218
 			return;
219 219
 		}
220 220
 
221
-		if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) {
221
+		if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) {
222 222
 			$allowed_html = array(
223 223
 				'a' => array(
224 224
 					'href' => array(),
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 				),
227 227
 			);
228 228
 
229
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
229
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
230 230
 		}
231 231
 
232 232
 		/**
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 		 * when setting screen is displayed. So if domain verification is not set,
235 235
 		 * something went wrong so lets notify user.
236 236
 		 */
237
-		if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) {
237
+		if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) {
238 238
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
239
-			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>';
239
+			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>';
240 240
 		}
241 241
 	}
242 242
 }
Please login to merge, or discard this patch.