Completed
Push — master ( bf7249...8ab9d7 )
by Matty
02:35
created
includes/class-wc-stripe-customer.php 1 patch
Spacing   +86 added lines, -86 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,10 +32,10 @@  discard block
 block discarded – undo
32 32
 	 * Constructor
33 33
 	 * @param int $user_id The WP user ID
34 34
 	 */
35
-	public function __construct( $user_id = 0 ) {
36
-		if ( $user_id ) {
37
-			$this->set_user_id( $user_id );
38
-			$this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) );
35
+	public function __construct($user_id = 0) {
36
+		if ($user_id) {
37
+			$this->set_user_id($user_id);
38
+			$this->set_id(get_user_meta($user_id, '_stripe_customer_id', true));
39 39
 		}
40 40
 	}
41 41
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * Set Stripe customer ID.
52 52
 	 * @param [type] $id [description]
53 53
 	 */
54
-	public function set_id( $id ) {
55
-		$this->id = wc_clean( $id );
54
+	public function set_id($id) {
55
+		$this->id = wc_clean($id);
56 56
 	}
57 57
 
58 58
 	/**
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
 	 * @return int
61 61
 	 */
62 62
 	public function get_user_id() {
63
-		return absint( $this->user_id );
63
+		return absint($this->user_id);
64 64
 	}
65 65
 
66 66
 	/**
67 67
 	 * Set User ID used by WordPress.
68 68
 	 * @param int $user_id
69 69
 	 */
70
-	public function set_user_id( $user_id ) {
71
-		$this->user_id = absint( $user_id );
70
+	public function set_user_id($user_id) {
71
+		$this->user_id = absint($user_id);
72 72
 	}
73 73
 
74 74
 	/**
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
 	 * @return WP_User
77 77
 	 */
78 78
 	protected function get_user() {
79
-		return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false;
79
+		return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false;
80 80
 	}
81 81
 
82 82
 	/**
83 83
 	 * Store data from the Stripe API about this customer
84 84
 	 */
85
-	public function set_customer_data( $data ) {
85
+	public function set_customer_data($data) {
86 86
 		$this->customer_data = $data;
87 87
 	}
88 88
 
@@ -90,14 +90,14 @@  discard block
 block discarded – undo
90 90
 	 * Get data from the Stripe API about this customer
91 91
 	 */
92 92
 	public function get_customer_data() {
93
-		$this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() );
93
+		$this->customer_data = get_transient('stripe_customer_' . $this->get_id());
94 94
 
95
-		if ( empty( $this->customer_data ) && $this->get_id() && false === $this->customer_data ) {
96
-			$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() );
95
+		if (empty($this->customer_data) && $this->get_id() && false === $this->customer_data) {
96
+			$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id());
97 97
 
98
-			if ( empty( $response->error ) ) {
99
-				$this->set_customer_data( $response );
100
-				set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 );
98
+			if (empty($response->error)) {
99
+				$this->set_customer_data($response);
100
+				set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48);
101 101
 			}
102 102
 		}
103 103
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 		$data   = $this->get_customer_data();
113 113
 		$source = '';
114 114
 
115
-		if ( $data ) {
115
+		if ($data) {
116 116
 			$source = $data->default_source;
117 117
 		}
118 118
 
@@ -124,13 +124,13 @@  discard block
 block discarded – undo
124 124
 	 * @param array $args
125 125
 	 * @return WP_Error|int
126 126
 	 */
127
-	public function create_customer( $args = array() ) {
128
-		$billing_email = filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL );
127
+	public function create_customer($args = array()) {
128
+		$billing_email = filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL);
129 129
 		$user = $this->get_user();
130 130
 
131
-		if ( $user ) {
132
-			$billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true );
133
-			$billing_last_name  = get_user_meta( $user->ID, 'billing_last_name', true );
131
+		if ($user) {
132
+			$billing_first_name = get_user_meta($user->ID, 'billing_first_name', true);
133
+			$billing_last_name  = get_user_meta($user->ID, 'billing_last_name', true);
134 134
 
135 135
 			$defaults = array(
136 136
 				'email'       => $user->user_email,
@@ -138,31 +138,31 @@  discard block
 block discarded – undo
138 138
 			);
139 139
 		} else {
140 140
 			$defaults = array(
141
-				'email'       => ! empty( $billing_email ) ? $billing_email : '',
141
+				'email'       => ! empty($billing_email) ? $billing_email : '',
142 142
 				'description' => '',
143 143
 			);
144 144
 		}
145 145
 
146 146
 		$metadata = array();
147 147
 
148
-		$defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
148
+		$defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user);
149 149
 
150
-		$args     = wp_parse_args( $args, $defaults );
151
-		$response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' );
150
+		$args     = wp_parse_args($args, $defaults);
151
+		$response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers');
152 152
 
153
-		if ( ! empty( $response->error ) ) {
154
-			throw new Exception( $response->error->message );
153
+		if ( ! empty($response->error)) {
154
+			throw new Exception($response->error->message);
155 155
 		}
156 156
 
157
-		$this->set_id( $response->id );
157
+		$this->set_id($response->id);
158 158
 		$this->clear_cache();
159
-		$this->set_customer_data( $response );
159
+		$this->set_customer_data($response);
160 160
 
161
-		if ( $this->get_user_id() ) {
162
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id );
161
+		if ($this->get_user_id()) {
162
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id);
163 163
 		}
164 164
 
165
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
165
+		do_action('woocommerce_stripe_add_customer', $args, $response);
166 166
 
167 167
 		return $response->id;
168 168
 	}
@@ -173,72 +173,72 @@  discard block
 block discarded – undo
173 173
 	 * @param bool $retry
174 174
 	 * @return WP_Error|int
175 175
 	 */
176
-	public function add_source( $source_id, $retry = true ) {
177
-		if ( ! $this->get_id() ) {
176
+	public function add_source($source_id, $retry = true) {
177
+		if ( ! $this->get_id()) {
178 178
 			$this->create_customer();
179 179
 		}
180 180
 
181
-		$response = WC_Stripe_API::request( array(
181
+		$response = WC_Stripe_API::request(array(
182 182
 			'source' => $source_id,
183
-		), 'customers/' . $this->get_id() . '/sources' );
183
+		), 'customers/' . $this->get_id() . '/sources');
184 184
 
185
-		if ( ! empty( $response->error ) ) {
185
+		if ( ! empty($response->error)) {
186 186
 			// It is possible the WC user once was linked to a customer on Stripe
187 187
 			// but no longer exists. Instead of failing, lets try to create a
188 188
 			// new customer.
189
-			if ( preg_match( '/No such customer/i', $response->error->message ) ) {
190
-				delete_user_meta( $this->get_user_id(), '_stripe_customer_id' );
189
+			if (preg_match('/No such customer/i', $response->error->message)) {
190
+				delete_user_meta($this->get_user_id(), '_stripe_customer_id');
191 191
 				$this->create_customer();
192
-				return $this->add_source( $source_id, false );
192
+				return $this->add_source($source_id, false);
193 193
 			} else {
194 194
 				return $response;
195 195
 			}
196
-		} elseif ( empty( $response->id ) ) {
197
-			return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) );
196
+		} elseif (empty($response->id)) {
197
+			return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe'));
198 198
 		}
199 199
 
200 200
 		// Add token to WooCommerce.
201
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
202
-			if ( ! empty( $response->type ) ) {
203
-				switch ( $response->type ) {
201
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
202
+			if ( ! empty($response->type)) {
203
+				switch ($response->type) {
204 204
 					case 'alipay':
205 205
 						break;
206 206
 					case 'sepa_debit':
207 207
 						$wc_token = new WC_Payment_Token_SEPA();
208
-						$wc_token->set_token( $response->id );
209
-						$wc_token->set_gateway_id( 'stripe_sepa' );
210
-						$wc_token->set_last4( $response->sepa_debit->last4 );
208
+						$wc_token->set_token($response->id);
209
+						$wc_token->set_gateway_id('stripe_sepa');
210
+						$wc_token->set_last4($response->sepa_debit->last4);
211 211
 						break;
212 212
 					default:
213
-						if ( 'source' === $response->object && 'card' === $response->type ) {
213
+						if ('source' === $response->object && 'card' === $response->type) {
214 214
 							$wc_token = new WC_Payment_Token_CC();
215
-							$wc_token->set_token( $response->id );
216
-							$wc_token->set_gateway_id( 'stripe' );
217
-							$wc_token->set_card_type( strtolower( $response->card->brand ) );
218
-							$wc_token->set_last4( $response->card->last4 );
219
-							$wc_token->set_expiry_month( $response->card->exp_month );
220
-							$wc_token->set_expiry_year( $response->card->exp_year );
215
+							$wc_token->set_token($response->id);
216
+							$wc_token->set_gateway_id('stripe');
217
+							$wc_token->set_card_type(strtolower($response->card->brand));
218
+							$wc_token->set_last4($response->card->last4);
219
+							$wc_token->set_expiry_month($response->card->exp_month);
220
+							$wc_token->set_expiry_year($response->card->exp_year);
221 221
 						}
222 222
 						break;
223 223
 				}
224 224
 			} else {
225 225
 				// Legacy.
226 226
 				$wc_token = new WC_Payment_Token_CC();
227
-				$wc_token->set_token( $response->id );
228
-				$wc_token->set_gateway_id( 'stripe' );
229
-				$wc_token->set_card_type( strtolower( $response->brand ) );
230
-				$wc_token->set_last4( $response->last4 );
231
-				$wc_token->set_expiry_month( $response->exp_month );
232
-				$wc_token->set_expiry_year( $response->exp_year );
227
+				$wc_token->set_token($response->id);
228
+				$wc_token->set_gateway_id('stripe');
229
+				$wc_token->set_card_type(strtolower($response->brand));
230
+				$wc_token->set_last4($response->last4);
231
+				$wc_token->set_expiry_month($response->exp_month);
232
+				$wc_token->set_expiry_year($response->exp_year);
233 233
 			}
234 234
 
235
-			$wc_token->set_user_id( $this->get_user_id() );
235
+			$wc_token->set_user_id($this->get_user_id());
236 236
 			$wc_token->save();
237 237
 		}
238 238
 
239 239
 		$this->clear_cache();
240 240
 
241
-		do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id );
241
+		do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id);
242 242
 
243 243
 		return $response->id;
244 244
 	}
@@ -250,38 +250,38 @@  discard block
 block discarded – undo
250 250
 	 * @return array
251 251
 	 */
252 252
 	public function get_sources() {
253
-		$sources = get_transient( 'stripe_sources_' . $this->get_id() );
253
+		$sources = get_transient('stripe_sources_' . $this->get_id());
254 254
 
255
-		if ( false === $sources ) {
256
-			$response = WC_Stripe_API::request( array(
255
+		if (false === $sources) {
256
+			$response = WC_Stripe_API::request(array(
257 257
 				'limit'       => 100,
258
-			), 'customers/' . $this->get_id() . '/sources', 'GET' );
258
+			), 'customers/' . $this->get_id() . '/sources', 'GET');
259 259
 
260
-			if ( ! empty( $response->error ) ) {
260
+			if ( ! empty($response->error)) {
261 261
 				return array();
262 262
 			}
263 263
 
264
-			if ( is_array( $response->data ) ) {
264
+			if (is_array($response->data)) {
265 265
 				$sources = $response->data;
266 266
 			}
267 267
 
268
-			set_transient( 'stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24 );
268
+			set_transient('stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24);
269 269
 		}
270 270
 
271
-		return empty( $sources ) ? array() : $sources;
271
+		return empty($sources) ? array() : $sources;
272 272
 	}
273 273
 
274 274
 	/**
275 275
 	 * Delete a source from stripe.
276 276
 	 * @param string $source_id
277 277
 	 */
278
-	public function delete_source( $source_id ) {
279
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' );
278
+	public function delete_source($source_id) {
279
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE');
280 280
 
281 281
 		$this->clear_cache();
282 282
 
283
-		if ( empty( $response->error ) ) {
284
-			do_action( 'wc_stripe_delete_source', $this->get_id(), $response );
283
+		if (empty($response->error)) {
284
+			do_action('wc_stripe_delete_source', $this->get_id(), $response);
285 285
 
286 286
 			return true;
287 287
 		}
@@ -293,15 +293,15 @@  discard block
 block discarded – undo
293 293
 	 * Set default source in Stripe
294 294
 	 * @param string $source_id
295 295
 	 */
296
-	public function set_default_source( $source_id ) {
297
-		$response = WC_Stripe_API::request( array(
298
-			'default_source' => sanitize_text_field( $source_id ),
299
-		), 'customers/' . $this->get_id(), 'POST' );
296
+	public function set_default_source($source_id) {
297
+		$response = WC_Stripe_API::request(array(
298
+			'default_source' => sanitize_text_field($source_id),
299
+		), 'customers/' . $this->get_id(), 'POST');
300 300
 
301 301
 		$this->clear_cache();
302 302
 
303
-		if ( empty( $response->error ) ) {
304
-			do_action( 'wc_stripe_set_default_source', $this->get_id(), $response );
303
+		if (empty($response->error)) {
304
+			do_action('wc_stripe_set_default_source', $this->get_id(), $response);
305 305
 
306 306
 			return true;
307 307
 		}
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
 	 * Deletes caches for this users cards.
314 314
 	 */
315 315
 	public function clear_cache() {
316
-		delete_transient( 'stripe_sources_' . $this->get_id() );
317
-		delete_transient( 'stripe_customer_' . $this->get_id() );
316
+		delete_transient('stripe_sources_' . $this->get_id());
317
+		delete_transient('stripe_customer_' . $this->get_id());
318 318
 		$this->customer_data = array();
319 319
 	}
320 320
 }
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +90 added lines, -90 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
 	}
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @version 4.0.0
136 136
 	 */
137 137
 	public function get_environment_warning() {
138
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
139
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
138
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
139
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
140 140
 
141 141
 			return $message;
142 142
 		}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 * @return array
153 153
 	 */
154 154
 	public function get_supported_currency() {
155
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
155
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
156 156
 			'USD',
157
-		) );
157
+		));
158 158
 	}
159 159
 
160 160
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function is_available() {
168
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
168
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 	 * @return array
181 181
 	 */
182 182
 	public function payment_icons() {
183
-		return apply_filters( 'wc_stripe_payment_icons', array(
183
+		return apply_filters('wc_stripe_payment_icons', array(
184 184
 			'bitcoin' => '<i class="stripe-pf stripe-pf-bitcoin stripe-pf-right" alt="Bitcoin" aria-hidden="true"></i>',
185
-		) );
185
+		));
186 186
 	}
187 187
 
188 188
 	/**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 
200 200
 		$icons_str .= $icons['bitcoin'];
201 201
 
202
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
202
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
203 203
 	}
204 204
 
205 205
 	/**
@@ -210,19 +210,19 @@  discard block
 block discarded – undo
210 210
 	 * @access public
211 211
 	 */
212 212
 	public function payment_scripts() {
213
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
213
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
214 214
 			return;
215 215
 		}
216 216
 
217
-		wp_enqueue_style( 'stripe_paymentfonts' );
218
-		wp_enqueue_script( 'woocommerce_stripe' );
217
+		wp_enqueue_style('stripe_paymentfonts');
218
+		wp_enqueue_script('woocommerce_stripe');
219 219
 	}
220 220
 
221 221
 	/**
222 222
 	 * Initialize Gateway Settings Form Fields.
223 223
 	 */
224 224
 	public function init_form_fields() {
225
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
225
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
226 226
 	}
227 227
 
228 228
 	/**
@@ -233,25 +233,25 @@  discard block
 block discarded – undo
233 233
 		$total                = WC()->cart->total;
234 234
 
235 235
 		// If paying from order, we need to get total from order not cart.
236
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
237
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
236
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
237
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
238 238
 			$total = $order->get_total();
239 239
 		}
240 240
 
241
-		if ( is_add_payment_method_page() ) {
242
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
243
-			$total        = '';
241
+		if (is_add_payment_method_page()) {
242
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
243
+			$total = '';
244 244
 		} else {
245 245
 			$pay_button_text = '';
246 246
 		}
247 247
 
248 248
 		echo '<div
249 249
 			id="stripe-bitcoin-payment-data"
250
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
251
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
250
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
251
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
252 252
 
253
-		if ( $this->description ) {
254
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
253
+		if ($this->description) {
254
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
255 255
 		}
256 256
 
257 257
 		echo '</div>';
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
 	 *
263 263
 	 * @param int $order_id
264 264
 	 */
265
-	public function thankyou_page( $order_id ) {
266
-		$this->get_instructions( $order_id );
265
+	public function thankyou_page($order_id) {
266
+		$this->get_instructions($order_id);
267 267
 	}
268 268
 
269 269
 	/**
@@ -275,13 +275,13 @@  discard block
 block discarded – undo
275 275
 	 * @param bool $sent_to_admin
276 276
 	 * @param bool $plain_text
277 277
 	 */
278
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
278
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
279 279
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
280 280
 
281 281
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
282 282
 
283
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
284
-			$this->get_instructions( $order_id, $plain_text );
283
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
284
+			$this->get_instructions($order_id, $plain_text);
285 285
 		}
286 286
 	}
287 287
 
@@ -292,38 +292,38 @@  discard block
 block discarded – undo
292 292
 	 * @version 4.0.0
293 293
 	 * @param int $order_id
294 294
 	 */
295
-	public function get_instructions( $order_id, $plain_text = false ) {
296
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
295
+	public function get_instructions($order_id, $plain_text = false) {
296
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
297 297
 
298
-		if ( $plain_text ) {
299
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
298
+		if ($plain_text) {
299
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
300 300
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
301
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
301
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
302 302
 			echo $data['amount'] . "\n\n";
303 303
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
304
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
304
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
305 305
 			echo $data['address'] . "\n\n";
306 306
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
307
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
307
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
308 308
 			echo $data['uri'] . "\n\n";
309 309
 		} else {
310 310
 			?>
311
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
311
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
312 312
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
313 313
 			<li class="woocommerce-order-overview__order order">
314
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
314
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
315 315
 				<strong><?php echo $data['amount']; ?></strong>
316 316
 			</li>
317 317
 			<li class="woocommerce-order-overview__order order">
318
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
318
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
319 319
 				<strong><?php echo $data['address']; ?></strong>
320 320
 			</li>
321 321
 			<li class="woocommerce-order-overview__order order">
322
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
322
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
323 323
 				<strong>
324 324
 				<?php
325 325
 				/* translators: link */
326
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
326
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
327 327
 				?>
328 328
 				</strong>
329 329
 			</li>
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 	 * @param object $order
341 341
 	 * @param object $source_object
342 342
 	 */
343
-	public function save_instructions( $order, $source_object ) {
343
+	public function save_instructions($order, $source_object) {
344 344
 		$data = array(
345 345
 			'amount'  => $source_object->bitcoin->amount,
346 346
 			'address' => $source_object->bitcoin->address,
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 
350 350
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
351 351
 
352
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
352
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
353 353
 	}
354 354
 
355 355
 	/**
@@ -363,40 +363,40 @@  discard block
 block discarded – undo
363 363
 	 *
364 364
 	 * @return array|void
365 365
 	 */
366
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
366
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
367 367
 		try {
368
-			$order = wc_get_order( $order_id );
369
-			$source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( stripslashes( $_POST['stripe_source'] ) ) : false;
368
+			$order = wc_get_order($order_id);
369
+			$source_object = ! empty($_POST['stripe_source']) ? json_decode(stripslashes($_POST['stripe_source'])) : false;
370 370
 
371 371
 			// This comes from the create account checkbox in the checkout page.
372
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
372
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
373 373
 
374
-			if ( $create_account ) {
374
+			if ($create_account) {
375 375
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
376
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
376
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
377 377
 				$new_stripe_customer->create_customer();
378 378
 			}
379 379
 
380
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
380
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
381 381
 
382
-			if ( empty( $prepared_source->source ) ) {
383
-				$error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
384
-				throw new Exception( $error_msg );
382
+			if (empty($prepared_source->source)) {
383
+				$error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
384
+				throw new Exception($error_msg);
385 385
 			}
386 386
 
387 387
 			// Store source to order meta.
388
-			$this->save_source( $order, $prepared_source );
388
+			$this->save_source($order, $prepared_source);
389 389
 
390 390
 
391 391
 			// This will throw exception if not valid.
392
-			$this->validate_minimum_order_amount( $order );
392
+			$this->validate_minimum_order_amount($order);
393 393
 
394
-			$this->save_instructions( $order, $source_object );
394
+			$this->save_instructions($order, $source_object);
395 395
 
396 396
 			// Mark as on-hold (we're awaiting the payment)
397
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
397
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
398 398
 
399
-			wc_reduce_stock_levels( $order_id );
399
+			wc_reduce_stock_levels($order_id);
400 400
 
401 401
 			// Remove cart
402 402
 			WC()->cart->empty_cart();
@@ -404,16 +404,16 @@  discard block
 block discarded – undo
404 404
 			// Return thankyou redirect
405 405
 			return array(
406 406
 				'result'    => 'success',
407
-				'redirect'  => $this->get_return_url( $order ),
407
+				'redirect'  => $this->get_return_url($order),
408 408
 			);
409
-		} catch ( Exception $e ) {
410
-			wc_add_notice( $e->getMessage(), 'error' );
411
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
409
+		} catch (Exception $e) {
410
+			wc_add_notice($e->getMessage(), 'error');
411
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
412 412
 
413
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
413
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
414 414
 
415
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
416
-				$this->send_failed_order_email( $order_id );
415
+			if ($order->has_status(array('pending', 'failed'))) {
416
+				$this->send_failed_order_email($order_id);
417 417
 			}
418 418
 
419 419
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sepa.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
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sepa';
60
-		$this->method_title         = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SEPA Direct Debit', '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',
@@ -84,25 +84,25 @@  discard block
 block discarded – undo
84 84
 		// Load the settings.
85 85
 		$this->init_settings();
86 86
 
87
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
88
-		$this->title                = $this->get_option( 'title' );
89
-		$this->description          = $this->get_option( 'description' );
90
-		$this->enabled              = $this->get_option( 'enabled' );
91
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
92
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
93
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
94
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
95
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
96
-
97
-		if ( $this->testmode ) {
98
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
99
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
87
+		$main_settings              = get_option('woocommerce_stripe_settings');
88
+		$this->title                = $this->get_option('title');
89
+		$this->description          = $this->get_option('description');
90
+		$this->enabled              = $this->get_option('enabled');
91
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
92
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
93
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
94
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
95
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
96
+
97
+		if ($this->testmode) {
98
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
99
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
100 100
 		}
101 101
 
102
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
103
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
104
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
105
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
102
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
103
+		add_action('admin_notices', array($this, 'check_environment'));
104
+		add_action('admin_head', array($this, 'remove_admin_notice'));
105
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,19 +112,19 @@  discard block
 block discarded – undo
112 112
 	 * @version 4.0.0
113 113
 	 */
114 114
 	public function check_environment() {
115
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
115
+		if ( ! current_user_can('manage_woocommerce')) {
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$environment_warning = $this->get_environment_warning();
120 120
 
121
-		if ( $environment_warning ) {
122
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
121
+		if ($environment_warning) {
122
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
123 123
 		}
124 124
 
125
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
126
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
127
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
125
+		foreach ((array) $this->notices as $notice_key => $notice) {
126
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
127
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
128 128
 			echo '</p></div>';
129 129
 		}
130 130
 	}
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @version 4.0.0
138 138
 	 */
139 139
 	public function get_environment_warning() {
140
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
141
-			$message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
140
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
141
+			$message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
142 142
 
143 143
 			return $message;
144 144
 		}
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	 * @return array
155 155
 	 */
156 156
 	public function get_supported_currency() {
157
-		return apply_filters( 'wc_stripe_sepa_supported_currencies', array(
157
+		return apply_filters('wc_stripe_sepa_supported_currencies', array(
158 158
 			'EUR',
159
-		) );
159
+		));
160 160
 	}
161 161
 
162 162
 	/**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 * @return bool
168 168
 	 */
169 169
 	public function is_available() {
170
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
170
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
171 171
 			return false;
172 172
 		}
173 173
 
@@ -182,9 +182,9 @@  discard block
 block discarded – undo
182 182
 	 * @return array
183 183
 	 */
184 184
 	public function payment_icons() {
185
-		return apply_filters( 'wc_stripe_payment_icons', array(
185
+		return apply_filters('wc_stripe_payment_icons', array(
186 186
 			'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
187
-		) );
187
+		));
188 188
 	}
189 189
 
190 190
 	/**
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 
202 202
 		$icons_str .= $icons['sepa'];
203 203
 
204
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
204
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
205 205
 	}
206 206
 
207 207
 	/**
@@ -212,19 +212,19 @@  discard block
 block discarded – undo
212 212
 	 * @access public
213 213
 	 */
214 214
 	public function payment_scripts() {
215
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
215
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
216 216
 			return;
217 217
 		}
218 218
 
219
-		wp_enqueue_style( 'stripe_paymentfonts' );
220
-		wp_enqueue_script( 'woocommerce_stripe' );
219
+		wp_enqueue_style('stripe_paymentfonts');
220
+		wp_enqueue_script('woocommerce_stripe');
221 221
 	}
222 222
 
223 223
 	/**
224 224
 	 * Initialize Gateway Settings Form Fields.
225 225
 	 */
226 226
 	public function init_form_fields() {
227
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
227
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
228 228
 	}
229 229
 
230 230
 	/**
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 	 */
237 237
 	public function mandate_display() {
238 238
 		/* translators: statement descriptor */
239
-		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
+		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));
240 240
 	}
241 241
 
242 242
 	/**
@@ -247,24 +247,24 @@  discard block
 block discarded – undo
247 247
 	 */
248 248
 	public function form() {
249 249
 		?>
250
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
251
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
250
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
251
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
252 252
 			<p class="wc-stripe-sepa-mandate"><?php $this->mandate_display(); ?></p>
253 253
 			<p class="form-row form-row-wide validate-required">
254 254
 				<label for="stripe-sepa-owner">
255
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?>
255
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?>
256 256
 				</label>
257 257
 				<input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" />
258 258
 			</p>
259 259
 			<p class="form-row form-row-wide validate-required">
260 260
 				<label for="stripe-sepa-iban">
261
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?>
261
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?>
262 262
 				</label>
263 263
 				<input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" />
264 264
 			</p>
265 265
 			<!-- Used to display form errors -->
266 266
 			<div class="stripe-source-errors" role="alert"></div>
267
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
267
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
268 268
 			<div class="clear"></div>
269 269
 		</fieldset>
270 270
 		<?php
@@ -276,42 +276,42 @@  discard block
 block discarded – undo
276 276
 	public function payment_fields() {
277 277
 		$user                 = wp_get_current_user();
278 278
 		$total                = WC()->cart->total;
279
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
279
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
280 280
 
281 281
 		// If paying from order, we need to get total from order not cart.
282
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
283
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
282
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
283
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
284 284
 			$total = $order->get_total();
285 285
 		}
286 286
 
287
-		if ( is_add_payment_method_page() ) {
288
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
289
-			$total        = '';
287
+		if (is_add_payment_method_page()) {
288
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
289
+			$total = '';
290 290
 		} else {
291 291
 			$pay_button_text = '';
292 292
 		}
293 293
 
294 294
 		echo '<div
295 295
 			id="stripe-sepa_debit-payment-data"
296
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
297
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
296
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
297
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
298 298
 
299
-		if ( $this->description ) {
300
-			if ( $this->testmode ) {
301
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
302
-				$this->description  = trim( $this->description );
299
+		if ($this->description) {
300
+			if ($this->testmode) {
301
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
302
+				$this->description  = trim($this->description);
303 303
 			}
304
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
304
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
305 305
 		}
306 306
 
307
-		if ( $display_tokenization ) {
307
+		if ($display_tokenization) {
308 308
 			$this->tokenization_script();
309 309
 			$this->saved_payment_methods();
310 310
 		}
311 311
 
312 312
 		$this->form();
313 313
 
314
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
314
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
315 315
 			$this->save_payment_method_checkbox();
316 316
 		}
317 317
 
@@ -329,76 +329,76 @@  discard block
 block discarded – undo
329 329
 	 *
330 330
 	 * @return array|void
331 331
 	 */
332
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
332
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
333 333
 		try {
334
-			$order = wc_get_order( $order_id );
334
+			$order = wc_get_order($order_id);
335 335
 
336 336
 			// This comes from the create account checkbox in the checkout page.
337
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
337
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
338 338
 
339
-			if ( $create_account ) {
339
+			if ($create_account) {
340 340
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
341
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
341
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
342 342
 				$new_stripe_customer->create_customer();
343 343
 			}
344 344
 
345
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
345
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
346 346
 
347 347
 			// Store source to order meta.
348
-			$this->save_source( $order, $prepared_source );
348
+			$this->save_source($order, $prepared_source);
349 349
 
350 350
 			// Result from Stripe API request.
351 351
 			$response = null;
352 352
 
353
-			if ( $order->get_total() > 0 ) {
353
+			if ($order->get_total() > 0) {
354 354
 				// This will throw exception if not valid.
355
-				$this->validate_minimum_order_amount( $order );
355
+				$this->validate_minimum_order_amount($order);
356 356
 
357
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
357
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
358 358
 
359 359
 				// Make the request.
360
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
360
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
361 361
 
362
-				if ( ! empty( $response->error ) ) {
362
+				if ( ! empty($response->error)) {
363 363
 					// If it is an API error such connection or server, let's retry.
364
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
365
-						if ( $retry ) {
366
-							sleep( 5 );
367
-							return $this->process_payment( $order_id, false, $force_save_source );
364
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
365
+						if ($retry) {
366
+							sleep(5);
367
+							return $this->process_payment($order_id, false, $force_save_source);
368 368
 						} else {
369 369
 							$message = 'API connection error and retries exhausted.';
370
-							$order->add_order_note( $message );
371
-							throw new Exception( $message );
370
+							$order->add_order_note($message);
371
+							throw new Exception($message);
372 372
 						}
373 373
 					}
374 374
 
375 375
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
376
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
377
-						delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' );
376
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
377
+						delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id');
378 378
 
379
-						return $this->process_payment( $order_id, false, $force_save_source );
380
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
379
+						return $this->process_payment($order_id, false, $force_save_source);
380
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
381 381
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
382
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
382
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
383 383
 						$wc_token->delete();
384
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
385
-						$order->add_order_note( $message );
386
-						throw new Exception( $message );
384
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
385
+						$order->add_order_note($message);
386
+						throw new Exception($message);
387 387
 					}
388 388
 
389 389
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
390 390
 
391
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
391
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
392 392
 
393
-					$order->add_order_note( $message );
393
+					$order->add_order_note($message);
394 394
 
395
-					throw new Exception( $message );
395
+					throw new Exception($message);
396 396
 				}
397 397
 
398
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
398
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
399 399
 
400 400
 				// Process valid response.
401
-				$this->process_response( $response, $order );
401
+				$this->process_response($response, $order);
402 402
 			} else {
403 403
 				$order->payment_complete();
404 404
 			}
@@ -409,17 +409,17 @@  discard block
 block discarded – undo
409 409
 			// Return thank you page redirect.
410 410
 			return array(
411 411
 				'result'   => 'success',
412
-				'redirect' => $this->get_return_url( $order ),
412
+				'redirect' => $this->get_return_url($order),
413 413
 			);
414 414
 
415
-		} catch ( Exception $e ) {
416
-			wc_add_notice( $e->getMessage(), 'error' );
417
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
415
+		} catch (Exception $e) {
416
+			wc_add_notice($e->getMessage(), 'error');
417
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
418 418
 
419
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
419
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
420 420
 
421
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
422
-				$this->send_failed_order_email( $order_id );
421
+			if ($order->has_status(array('pending', 'failed'))) {
422
+				$this->send_failed_order_email($order_id);
423 423
 			}
424 424
 
425 425
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bancontact.php 1 patch
Spacing   +78 added lines, -78 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
 
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 	 * @return array
170 170
 	 */
171 171
 	public function payment_icons() {
172
-		return apply_filters( 'wc_stripe_payment_icons', array(
172
+		return apply_filters('wc_stripe_payment_icons', array(
173 173
 			'bancontact' => '<i class="stripe-pf stripe-pf-bancontact-mister-cash stripe-pf-right" alt="Bancontact" aria-hidden="true"></i>',
174
-		) );
174
+		));
175 175
 	}
176 176
 
177 177
 	/**
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 		$icons_str .= $icons['bancontact'];
190 190
 
191
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
191
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
192 192
 	}
193 193
 
194 194
 	/**
@@ -199,19 +199,19 @@  discard block
 block discarded – undo
199 199
 	 * @access public
200 200
 	 */
201 201
 	public function payment_scripts() {
202
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
202
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
203 203
 			return;
204 204
 		}
205 205
 
206
-		wp_enqueue_style( 'stripe_paymentfonts' );
207
-		wp_enqueue_script( 'woocommerce_stripe' );
206
+		wp_enqueue_style('stripe_paymentfonts');
207
+		wp_enqueue_script('woocommerce_stripe');
208 208
 	}
209 209
 
210 210
 	/**
211 211
 	 * Initialize Gateway Settings Form Fields.
212 212
 	 */
213 213
 	public function init_form_fields() {
214
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' );
214
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php');
215 215
 	}
216 216
 
217 217
 	/**
@@ -222,25 +222,25 @@  discard block
 block discarded – undo
222 222
 		$total = WC()->cart->total;
223 223
 
224 224
 		// If paying from order, we need to get total from order not cart.
225
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
226
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
225
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
226
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
227 227
 			$total = $order->get_total();
228 228
 		}
229 229
 
230
-		if ( is_add_payment_method_page() ) {
231
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
232
-			$total        = '';
230
+		if (is_add_payment_method_page()) {
231
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
232
+			$total = '';
233 233
 		} else {
234 234
 			$pay_button_text = '';
235 235
 		}
236 236
 
237 237
 		echo '<div
238 238
 			id="stripe-bancontact-payment-data"
239
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
240
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
239
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
240
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
241 241
 
242
-		if ( $this->description ) {
243
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
242
+		if ($this->description) {
243
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
244 244
 		}
245 245
 
246 246
 		echo '</div>';
@@ -254,24 +254,24 @@  discard block
 block discarded – undo
254 254
 	 * @param object $order
255 255
 	 * @return mixed
256 256
 	 */
257
-	public function create_source( $order ) {
257
+	public function create_source($order) {
258 258
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
259 259
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
260
-		$return_url                        = $this->get_stripe_return_url( $order );
260
+		$return_url                        = $this->get_stripe_return_url($order);
261 261
 		$post_data                         = array();
262
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
263
-		$post_data['currency']             = strtolower( $currency );
262
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
263
+		$post_data['currency']             = strtolower($currency);
264 264
 		$post_data['type']                 = 'bancontact';
265
-		$post_data['owner']                = $this->get_owner_details( $order );
266
-		$post_data['redirect']             = array( 'return_url' => $return_url );
265
+		$post_data['owner']                = $this->get_owner_details($order);
266
+		$post_data['redirect']             = array('return_url' => $return_url);
267 267
 
268
-		if ( ! empty( $this->statement_descriptor ) ) {
269
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
268
+		if ( ! empty($this->statement_descriptor)) {
269
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
270 270
 		}
271 271
 
272
-		WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' );
272
+		WC_Stripe_Logger::log('Info: Begin creating Bancontact source');
273 273
 
274
-		return WC_Stripe_API::request( $post_data, 'sources' );
274
+		return WC_Stripe_API::request($post_data, 'sources');
275 275
 	}
276 276
 
277 277
 	/**
@@ -285,51 +285,51 @@  discard block
 block discarded – undo
285 285
 	 *
286 286
 	 * @return array|void
287 287
 	 */
288
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
288
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
289 289
 		try {
290
-			$order = wc_get_order( $order_id );
290
+			$order = wc_get_order($order_id);
291 291
 
292 292
 			// This will throw exception if not valid.
293
-			$this->validate_minimum_order_amount( $order );
293
+			$this->validate_minimum_order_amount($order);
294 294
 
295 295
 			// This comes from the create account checkbox in the checkout page.
296
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
296
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
297 297
 
298
-			if ( $create_account ) {
298
+			if ($create_account) {
299 299
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
300
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
300
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
301 301
 				$new_stripe_customer->create_customer();
302 302
 			}
303 303
 
304
-			$response = $this->create_source( $order );
304
+			$response = $this->create_source($order);
305 305
 
306
-			if ( ! empty( $response->error ) ) {
307
-				$order->add_order_note( $response->error->message );
306
+			if ( ! empty($response->error)) {
307
+				$order->add_order_note($response->error->message);
308 308
 
309
-				throw new Exception( $response->error->message );
309
+				throw new Exception($response->error->message);
310 310
 			}
311 311
 
312
-			if ( WC_Stripe_Helper::is_pre_30() ) {
313
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
312
+			if (WC_Stripe_Helper::is_pre_30()) {
313
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
314 314
 			} else {
315
-				$order->update_meta_data( '_stripe_source_id', $response->id );
315
+				$order->update_meta_data('_stripe_source_id', $response->id);
316 316
 				$order->save();
317 317
 			}
318 318
 
319
-			WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' );
319
+			WC_Stripe_Logger::log('Info: Redirecting to Bancontact...');
320 320
 
321 321
 			return array(
322 322
 				'result'   => 'success',
323
-				'redirect' => esc_url_raw( $response->redirect->url ),
323
+				'redirect' => esc_url_raw($response->redirect->url),
324 324
 			);
325
-		} catch ( Exception $e ) {
326
-			wc_add_notice( $e->getMessage(), 'error' );
327
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
325
+		} catch (Exception $e) {
326
+			wc_add_notice($e->getMessage(), 'error');
327
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
328 328
 
329
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
329
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
330 330
 
331
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
332
-				$this->send_failed_order_email( $order_id );
331
+			if ($order->has_status(array('pending', 'failed'))) {
332
+				$this->send_failed_order_email($order_id);
333 333
 			}
334 334
 
335 335
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sofort.php 1 patch
Spacing   +87 added lines, -87 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
 
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 	 * @return array
170 170
 	 */
171 171
 	public function payment_icons() {
172
-		return apply_filters( 'wc_stripe_payment_icons', array(
172
+		return apply_filters('wc_stripe_payment_icons', array(
173 173
 			'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
174
-		) );
174
+		));
175 175
 	}
176 176
 
177 177
 	/**
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 		$icons_str .= $icons['sofort'];
190 190
 
191
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
191
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
192 192
 	}
193 193
 
194 194
 	/**
@@ -199,19 +199,19 @@  discard block
 block discarded – undo
199 199
 	 * @access public
200 200
 	 */
201 201
 	public function payment_scripts() {
202
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
202
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
203 203
 			return;
204 204
 		}
205 205
 
206
-		wp_enqueue_style( 'stripe_paymentfonts' );
207
-		wp_enqueue_script( 'woocommerce_stripe' );
206
+		wp_enqueue_style('stripe_paymentfonts');
207
+		wp_enqueue_script('woocommerce_stripe');
208 208
 	}
209 209
 
210 210
 	/**
211 211
 	 * Initialize Gateway Settings Form Fields.
212 212
 	 */
213 213
 	public function init_form_fields() {
214
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' );
214
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php');
215 215
 	}
216 216
 
217 217
 	/**
@@ -230,24 +230,24 @@  discard block
 block discarded – undo
230 230
 			'IT' => 'Italy',
231 231
 		);
232 232
 		?>
233
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
234
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
233
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
234
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
235 235
 			<label for="stripe-bank-country">
236
-				<?php _e( 'Country origin of your bank.', 'woocommerce-gateway-stripe' ); ?>
236
+				<?php _e('Country origin of your bank.', 'woocommerce-gateway-stripe'); ?>
237 237
 			</label>
238 238
 			<br />
239 239
 			<p class="form-row form-row-wide validate-required">
240 240
 			<select id="stripe-bank-country" class="wc-enhanced-select" name="stripe_sofort_bank_country">
241
-				<option value="-1"><?php esc_html_e( 'Choose Bank Country', 'woocommerce-gateway-stripe' ); ?></option>
242
-				<?php foreach ( $supported_countries as $code => $country ) { ?>
243
-				<option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $country ); ?></option>
241
+				<option value="-1"><?php esc_html_e('Choose Bank Country', 'woocommerce-gateway-stripe'); ?></option>
242
+				<?php foreach ($supported_countries as $code => $country) { ?>
243
+				<option value="<?php echo esc_attr($code); ?>"><?php echo esc_html($country); ?></option>
244 244
 				<?php } ?>
245 245
 			</select>
246 246
 			</p>
247 247
 
248 248
 			<!-- Used to display form errors -->
249 249
 			<div class="stripe-source-errors" role="alert"></div>
250
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
250
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
251 251
 			<div class="clear"></div>
252 252
 		</fieldset>
253 253
 		<?php
@@ -261,25 +261,25 @@  discard block
 block discarded – undo
261 261
 		$total                = WC()->cart->total;
262 262
 
263 263
 		// If paying from order, we need to get total from order not cart.
264
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
265
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
264
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
265
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
266 266
 			$total = $order->get_total();
267 267
 		}
268 268
 
269
-		if ( is_add_payment_method_page() ) {
270
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
271
-			$total        = '';
269
+		if (is_add_payment_method_page()) {
270
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
271
+			$total = '';
272 272
 		} else {
273 273
 			$pay_button_text = '';
274 274
 		}
275 275
 
276 276
 		echo '<div
277 277
 			id="stripe-sofort-payment-data"
278
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
279
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
278
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
279
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
280 280
 
281
-		if ( $this->description ) {
282
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
281
+		if ($this->description) {
282
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
283 283
 		}
284 284
 
285 285
 		$this->form();
@@ -295,26 +295,26 @@  discard block
 block discarded – undo
295 295
 	 * @param object $order
296 296
 	 * @return mixed
297 297
 	 */
298
-	public function create_source( $order ) {
298
+	public function create_source($order) {
299 299
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
300 300
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
301
-		$bank_country                      = wc_clean( $_POST['stripe_sofort_bank_country'] );
302
-		$return_url                        = $this->get_stripe_return_url( $order );
301
+		$bank_country                      = wc_clean($_POST['stripe_sofort_bank_country']);
302
+		$return_url                        = $this->get_stripe_return_url($order);
303 303
 		$post_data                         = array();
304
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
305
-		$post_data['currency']             = strtolower( $currency );
304
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
305
+		$post_data['currency']             = strtolower($currency);
306 306
 		$post_data['type']                 = 'sofort';
307
-		$post_data['owner']                = $this->get_owner_details( $order );
308
-		$post_data['redirect']             = array( 'return_url' => $return_url );
309
-		$post_data['sofort']               = array( 'country' => $bank_country );
307
+		$post_data['owner']                = $this->get_owner_details($order);
308
+		$post_data['redirect']             = array('return_url' => $return_url);
309
+		$post_data['sofort']               = array('country' => $bank_country);
310 310
 
311
-		if ( ! empty( $this->statement_descriptor ) ) {
312
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
311
+		if ( ! empty($this->statement_descriptor)) {
312
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
313 313
 		}
314 314
 
315
-		WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' );
315
+		WC_Stripe_Logger::log('Info: Begin creating SOFORT source');
316 316
 
317
-		return WC_Stripe_API::request( $post_data, 'sources' );
317
+		return WC_Stripe_API::request($post_data, 'sources');
318 318
 	}
319 319
 
320 320
 	/**
@@ -328,51 +328,51 @@  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 will throw exception if not valid.
336
-			$this->validate_minimum_order_amount( $order );
336
+			$this->validate_minimum_order_amount($order);
337 337
 
338 338
 			// This comes from the create account checkbox in the checkout page.
339
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
339
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
340 340
 
341
-			if ( $create_account ) {
341
+			if ($create_account) {
342 342
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
343
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
343
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
344 344
 				$new_stripe_customer->create_customer();
345 345
 			}
346 346
 
347
-			$response = $this->create_source( $order );
347
+			$response = $this->create_source($order);
348 348
 
349
-			if ( ! empty( $response->error ) ) {
350
-				$order->add_order_note( $response->error->message );
349
+			if ( ! empty($response->error)) {
350
+				$order->add_order_note($response->error->message);
351 351
 
352
-				throw new Exception( $response->error->message );
352
+				throw new Exception($response->error->message);
353 353
 			}
354 354
 
355
-			if ( WC_Stripe_Helper::is_pre_30() ) {
356
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
355
+			if (WC_Stripe_Helper::is_pre_30()) {
356
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
357 357
 			} else {
358
-				$order->update_meta_data( '_stripe_source_id', $response->id );
358
+				$order->update_meta_data('_stripe_source_id', $response->id);
359 359
 				$order->save();
360 360
 			}
361 361
 
362
-			WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' );
362
+			WC_Stripe_Logger::log('Info: Redirecting to SOFORT...');
363 363
 
364 364
 			return array(
365 365
 				'result'   => 'success',
366
-				'redirect' => esc_url_raw( $response->redirect->url ),
366
+				'redirect' => esc_url_raw($response->redirect->url),
367 367
 			);
368
-		} catch ( Exception $e ) {
369
-			wc_add_notice( $e->getMessage(), 'error' );
370
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
368
+		} catch (Exception $e) {
369
+			wc_add_notice($e->getMessage(), 'error');
370
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
371 371
 
372
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
372
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
373 373
 
374
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
375
-				$this->send_failed_order_email( $order_id );
374
+			if ($order->has_status(array('pending', 'failed'))) {
375
+				$this->send_failed_order_email($order_id);
376 376
 			}
377 377
 
378 378
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   3.1.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -42,30 +42,30 @@  discard block
 block discarded – undo
42 42
 	 * @version 4.0.0
43 43
 	 */
44 44
 	public function __construct() {
45
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
45
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
46 46
 		$this->publishable_key         = $this->get_publishable_key();
47
-		$this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout'];
48
-		$this->total_label             = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
47
+		$this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout'];
48
+		$this->total_label             = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
49 49
 
50 50
 		// If both site title and statement descriptor is not set. Fallback.
51
-		if ( empty( $this->total_label ) ) {
51
+		if (empty($this->total_label)) {
52 52
 			$this->total_label = $_SERVER['SERVER_NAME'];
53 53
 		}
54 54
 
55
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
55
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
56 56
 
57 57
 		// Checks if Stripe Gateway is enabled.
58
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
58
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
59 59
 			return;
60 60
 		}
61 61
 
62 62
 		// Checks if Payment Request is enabled.
63
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
63
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
64 64
 			return;
65 65
 		}
66 66
 
67 67
 		// Don't load for change payment method page.
68
-		if ( isset( $_GET['change_payment_method'] ) ) {
68
+		if (isset($_GET['change_payment_method'])) {
69 69
 			return;
70 70
 		}
71 71
 
@@ -79,38 +79,38 @@  discard block
 block discarded – undo
79 79
 	 * @version 4.0.0
80 80
 	 */
81 81
 	protected function init() {
82
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
83
-		add_action( 'wp', array( $this, 'set_session' ) );
82
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
83
+		add_action('wp', array($this, 'set_session'));
84 84
 
85 85
 		/*
86 86
 		 * In order to display the Payment Request button in the correct position,
87 87
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
88 88
 		 * CSS is used to position the button.
89 89
 		 */
90
-		if ( WC_Stripe_Helper::is_pre_30() ) {
91
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
92
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
90
+		if (WC_Stripe_Helper::is_pre_30()) {
91
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
92
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
93 93
 		} else {
94
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
95
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
94
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
95
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
96 96
 		}
97 97
 
98
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
99
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
98
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
99
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
100 100
 
101
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
102
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
103
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
104
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
105
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
106
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
107
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
108
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
101
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
102
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
103
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
104
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
105
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
106
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
107
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
108
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
109 109
 
110
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
111
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
110
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
111
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
112 112
 
113
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 );
113
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3);
114 114
 	}
115 115
 
116 116
 	/**
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
 	 * @since 4.0.0
121 121
 	 */
122 122
 	public function set_session() {
123
-		if ( ! is_user_logged_in() ) {
123
+		if ( ! is_user_logged_in()) {
124 124
 			$wc_session = new WC_Session_Handler();
125 125
 
126
-			if ( ! $wc_session->has_session() ) {
127
-				$wc_session->set_customer_session_cookie( true );
126
+			if ( ! $wc_session->has_session()) {
127
+				$wc_session->set_customer_session_cookie(true);
128 128
 			}
129 129
 		}
130 130
 	}
@@ -135,15 +135,15 @@  discard block
 block discarded – undo
135 135
 	 * @return string
136 136
 	 */
137 137
 	protected function get_publishable_key() {
138
-		if ( empty( $this->stripe_settings ) ) {
138
+		if (empty($this->stripe_settings)) {
139 139
 			return '';
140 140
 		}
141 141
 
142
-		if ( empty( $this->stripe_settings['testmode'] ) ) {
142
+		if (empty($this->stripe_settings['testmode'])) {
143 143
 			return '';
144 144
 		}
145 145
 
146
-		if ( empty( $this->stripe_settings['test_publishable_key'] ) ) {
146
+		if (empty($this->stripe_settings['test_publishable_key'])) {
147 147
 			return '';
148 148
 		}
149 149
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 * @return string
159 159
 	 */
160 160
 	public function get_button_type() {
161
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
161
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
162 162
 	}
163 163
 
164 164
 	/**
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 * @return string
170 170
 	 */
171 171
 	public function get_button_theme() {
172
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
172
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
173 173
 	}
174 174
 
175 175
 	/**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 * @return string
181 181
 	 */
182 182
 	public function get_button_height() {
183
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
183
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
184 184
 	}
185 185
 
186 186
 	/**
@@ -190,40 +190,40 @@  discard block
 block discarded – undo
190 190
 	 * @version 4.0.0
191 191
 	 */
192 192
 	public function get_product_data() {
193
-		if ( ! is_product() ) {
193
+		if ( ! is_product()) {
194 194
 			return false;
195 195
 		}
196 196
 
197 197
 		global $post;
198 198
 
199
-		$product = wc_get_product( $post->ID );
199
+		$product = wc_get_product($post->ID);
200 200
 
201 201
 		$data  = array();
202 202
 		$items = array();
203 203
 
204 204
 		$items[] = array(
205 205
 			'label'  => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(),
206
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
206
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
207 207
 		);
208 208
 
209
-		if ( wc_tax_enabled() ) {
209
+		if (wc_tax_enabled()) {
210 210
 			$items[] = array(
211
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
211
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
212 212
 				'amount'  => 0,
213 213
 				'pending' => true,
214 214
 			);
215 215
 		}
216 216
 
217
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
217
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
218 218
 			$items[] = array(
219
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
219
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
220 220
 				'amount'  => 0,
221 221
 				'pending' => true,
222 222
 			);
223 223
 
224
-			$data['shippingOptions']  = array(
224
+			$data['shippingOptions'] = array(
225 225
 				'id'     => 'pending',
226
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
226
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
227 227
 				'detail' => '',
228 228
 				'amount' => 0,
229 229
 			);
@@ -232,13 +232,13 @@  discard block
 block discarded – undo
232 232
 		$data['displayItems'] = $items;
233 233
 		$data['total'] = array(
234 234
 			'label'   => $this->total_label,
235
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
235
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
236 236
 			'pending' => true,
237 237
 		);
238 238
 
239
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
240
-		$data['currency']        = strtolower( get_woocommerce_currency() );
241
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
239
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
240
+		$data['currency']        = strtolower(get_woocommerce_currency());
241
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
242 242
 
243 243
 		return $data;
244 244
 	}
@@ -247,25 +247,25 @@  discard block
 block discarded – undo
247 247
 	 * Filters the gateway title to reflect Payment Request type
248 248
 	 *
249 249
 	 */
250
-	public function filter_gateway_title( $title, $id ) {
250
+	public function filter_gateway_title($title, $id) {
251 251
 		global $post;
252 252
 
253
-		if ( ! is_object( $post ) ) {
253
+		if ( ! is_object($post)) {
254 254
 			return $title;
255 255
 		}
256 256
 
257
-		if ( WC_Stripe_Helper::is_pre_30() ) {
258
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
257
+		if (WC_Stripe_Helper::is_pre_30()) {
258
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
259 259
 		} else {
260
-			$order        = wc_get_order( $post->ID );
261
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
260
+			$order        = wc_get_order($post->ID);
261
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
262 262
 		}
263 263
 
264
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
264
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
265 265
 			return $method_title;
266 266
 		}
267 267
 
268
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
268
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
269 269
 			return $method_title;
270 270
 		}
271 271
 
@@ -278,10 +278,10 @@  discard block
 block discarded – undo
278 278
 	 * @since 3.1.4
279 279
 	 * @version 4.0.0
280 280
 	 */
281
-	public function postal_code_validation( $valid, $postcode, $country ) {
281
+	public function postal_code_validation($valid, $postcode, $country) {
282 282
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
283 283
 
284
-		if ( ! isset( $gateways['stripe'] ) ) {
284
+		if ( ! isset($gateways['stripe'])) {
285 285
 			return $valid;
286 286
 		}
287 287
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
292 292
 		 * Note that this only works with shipping providers that don't validate full postal codes.
293 293
 		 */
294
-		if ( 'GB' === $country || 'CA' === $country ) {
294
+		if ('GB' === $country || 'CA' === $country) {
295 295
 			return true;
296 296
 		}
297 297
 
@@ -307,27 +307,27 @@  discard block
 block discarded – undo
307 307
 	 * @param array $posted_data The posted data from checkout form.
308 308
 	 * @param object $order
309 309
 	 */
310
-	public function add_order_meta( $order_id, $posted_data, $order ) {
311
-		if ( empty( $_POST['payment_request_type'] ) ) {
310
+	public function add_order_meta($order_id, $posted_data, $order) {
311
+		if (empty($_POST['payment_request_type'])) {
312 312
 			return;
313 313
 		}
314 314
 
315
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
315
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
316 316
 
317
-		if ( 'apple_pay' === $payment_request_type ) {
318
-			if ( WC_Stripe_Helper::is_pre_30() ) {
319
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
317
+		if ('apple_pay' === $payment_request_type) {
318
+			if (WC_Stripe_Helper::is_pre_30()) {
319
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
320 320
 			} else {
321
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
321
+				$order->set_payment_method_title('Apple Pay (Stripe)');
322 322
 				$order->save();
323 323
 			}
324 324
 		}
325 325
 
326
-		if ( 'payment_request_api' === $payment_request_type ) {
327
-			if ( WC_Stripe_Helper::is_pre_30() ) {
328
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
326
+		if ('payment_request_api' === $payment_request_type) {
327
+			if (WC_Stripe_Helper::is_pre_30()) {
328
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
329 329
 			} else {
330
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
330
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
331 331
 				$order->save();
332 332
 			}
333 333
 		}
@@ -341,11 +341,11 @@  discard block
 block discarded – undo
341 341
 	 * @return array
342 342
 	 */
343 343
 	public function supported_product_types() {
344
-		return apply_filters( 'wc_stripe_payment_request_supported_types', array(
344
+		return apply_filters('wc_stripe_payment_request_supported_types', array(
345 345
 			'simple',
346 346
 			'variable',
347 347
 			'variation',
348
-		) );
348
+		));
349 349
 	}
350 350
 
351 351
 	/**
@@ -356,15 +356,15 @@  discard block
 block discarded – undo
356 356
 	 * @return bool
357 357
 	 */
358 358
 	public function allowed_items_in_cart() {
359
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
360
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
359
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
360
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
361 361
 
362
-			if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
362
+			if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
363 363
 				return false;
364 364
 			}
365 365
 
366 366
 			// Pre Orders compatbility where we don't support charge upon release.
367
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) {
367
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) {
368 368
 				return false;
369 369
 			}
370 370
 		}
@@ -379,71 +379,71 @@  discard block
 block discarded – undo
379 379
 	 * @version 4.0.0
380 380
 	 */
381 381
 	public function scripts() {
382
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
382
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
383 383
 			return;
384 384
 		}
385 385
 
386
-		if ( is_product() ) {
386
+		if (is_product()) {
387 387
 			global $post;
388 388
 
389
-			$product = wc_get_product( $post->ID );
389
+			$product = wc_get_product($post->ID);
390 390
 
391
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
391
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
392 392
 				return;
393 393
 			}
394 394
 
395
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
395
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
396 396
 				return;
397 397
 			}
398 398
 		}
399 399
 
400
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
400
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
401 401
 
402
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
403
-		wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true );
402
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
403
+		wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true);
404 404
 
405 405
 		wp_localize_script(
406 406
 			'wc_stripe_payment_request',
407 407
 			'wc_stripe_payment_request_params',
408 408
 			array(
409
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
409
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
410 410
 				'stripe'   => array(
411 411
 					'key'                => $this->get_publishable_key(),
412
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
412
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
413 413
 				),
414 414
 				'nonce'    => array(
415
-					'payment'                        => wp_create_nonce( 'wc-stripe-payment-request' ),
416
-					'shipping'                       => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
417
-					'update_shipping'                => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
418
-					'checkout'                       => wp_create_nonce( 'woocommerce-process_checkout' ),
419
-					'add_to_cart'                    => wp_create_nonce( 'wc-stripe-add-to-cart' ),
420
-					'get_selected_product_data'      => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
421
-					'log_errors'                     => wp_create_nonce( 'wc-stripe-log-errors' ),
422
-					'clear_cart'                     => wp_create_nonce( 'wc-stripe-clear-cart' ),
415
+					'payment'                        => wp_create_nonce('wc-stripe-payment-request'),
416
+					'shipping'                       => wp_create_nonce('wc-stripe-payment-request-shipping'),
417
+					'update_shipping'                => wp_create_nonce('wc-stripe-update-shipping-method'),
418
+					'checkout'                       => wp_create_nonce('woocommerce-process_checkout'),
419
+					'add_to_cart'                    => wp_create_nonce('wc-stripe-add-to-cart'),
420
+					'get_selected_product_data'      => wp_create_nonce('wc-stripe-get-selected-product-data'),
421
+					'log_errors'                     => wp_create_nonce('wc-stripe-log-errors'),
422
+					'clear_cart'                     => wp_create_nonce('wc-stripe-clear-cart'),
423 423
 				),
424 424
 				'i18n'     => array(
425
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
425
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
426 426
 					/* translators: Do not translate the [option] placeholder */
427
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
427
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
428 428
 				),
429 429
 				'checkout' => array(
430 430
 					'url'            => wc_get_checkout_url(),
431
-					'currency_code'  => strtolower( get_woocommerce_currency() ),
432
-					'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
431
+					'currency_code'  => strtolower(get_woocommerce_currency()),
432
+					'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
433 433
 					'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
434 434
 				),
435 435
 				'button' => array(
436 436
 					'type'   => $this->get_button_type(),
437 437
 					'theme'  => $this->get_button_theme(),
438 438
 					'height' => $this->get_button_height(),
439
-					'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US.
439
+					'locale' => substr(get_locale(), 0, 2), // Default format is en_US.
440 440
 				),
441 441
 				'is_product_page' => is_product(),
442 442
 				'product'         => $this->get_product_data(),
443 443
 			)
444 444
 		);
445 445
 
446
-		wp_enqueue_script( 'wc_stripe_payment_request' );
446
+		wp_enqueue_script('wc_stripe_payment_request');
447 447
 	}
448 448
 
449 449
 	/**
@@ -455,35 +455,35 @@  discard block
 block discarded – undo
455 455
 	public function display_payment_request_button_html() {
456 456
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
457 457
 
458
-		if ( ! isset( $gateways['stripe'] ) ) {
458
+		if ( ! isset($gateways['stripe'])) {
459 459
 			return;
460 460
 		}
461 461
 
462
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
462
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
463 463
 			return;
464 464
 		}
465 465
 
466
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
466
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
467 467
 			return;
468 468
 		}
469 469
 
470
-		if ( is_product() ) {
470
+		if (is_product()) {
471 471
 			global $post;
472 472
 
473
-			$product = wc_get_product( $post->ID );
473
+			$product = wc_get_product($post->ID);
474 474
 
475
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
475
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
476 476
 				return;
477 477
 			}
478 478
 
479 479
 			// Pre Orders charge upon release not supported.
480
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
481
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
480
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
481
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
482 482
 				return;
483 483
 			}
484 484
 		} else {
485
-			if ( ! $this->allowed_items_in_cart() ) {
486
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
485
+			if ( ! $this->allowed_items_in_cart()) {
486
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
487 487
 				return;
488 488
 			}
489 489
 		}
@@ -505,40 +505,40 @@  discard block
 block discarded – undo
505 505
 	public function display_payment_request_button_separator_html() {
506 506
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
507 507
 
508
-		if ( ! isset( $gateways['stripe'] ) ) {
508
+		if ( ! isset($gateways['stripe'])) {
509 509
 			return;
510 510
 		}
511 511
 
512
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
512
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
513 513
 			return;
514 514
 		}
515 515
 
516
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
516
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
517 517
 			return;
518 518
 		}
519 519
 
520
-		if ( is_product() ) {
520
+		if (is_product()) {
521 521
 			global $post;
522 522
 
523
-			$product = wc_get_product( $post->ID );
523
+			$product = wc_get_product($post->ID);
524 524
 
525
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
525
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
526 526
 				return;
527 527
 			}
528 528
 
529 529
 			// Pre Orders charge upon release not supported.
530
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
531
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
530
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
531
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
532 532
 				return;
533 533
 			}
534 534
 		} else {
535
-			if ( ! $this->allowed_items_in_cart() ) {
536
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
535
+			if ( ! $this->allowed_items_in_cart()) {
536
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
537 537
 				return;
538 538
 			}
539 539
 		}
540 540
 		?>
541
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p>
541
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p>
542 542
 		<?php
543 543
 	}
544 544
 
@@ -549,11 +549,11 @@  discard block
 block discarded – undo
549 549
 	 * @version 4.0.0
550 550
 	 */
551 551
 	public function ajax_log_errors() {
552
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
552
+		check_ajax_referer('wc-stripe-log-errors', 'security');
553 553
 
554
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
554
+		$errors = wc_clean(stripslashes($_POST['errors']));
555 555
 
556
-		WC_Stripe_Logger::log( $errors );
556
+		WC_Stripe_Logger::log($errors);
557 557
 
558 558
 		exit;
559 559
 	}
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 	 * @version 4.0.0
566 566
 	 */
567 567
 	public function ajax_clear_cart() {
568
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
568
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
569 569
 
570 570
 		WC()->cart->empty_cart();
571 571
 		exit;
@@ -575,10 +575,10 @@  discard block
 block discarded – undo
575 575
 	 * Get cart details.
576 576
 	 */
577 577
 	public function ajax_get_cart_details() {
578
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
578
+		check_ajax_referer('wc-stripe-payment-request', 'security');
579 579
 
580
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
581
-			define( 'WOOCOMMERCE_CART', true );
580
+		if ( ! defined('WOOCOMMERCE_CART')) {
581
+			define('WOOCOMMERCE_CART', true);
582 582
 		}
583 583
 
584 584
 		WC()->cart->calculate_totals();
@@ -591,14 +591,14 @@  discard block
 block discarded – undo
591 591
 		$data = array(
592 592
 			'shipping_required' => WC()->cart->needs_shipping(),
593 593
 			'order_data'        => array(
594
-				'currency'        => strtolower( $currency ),
595
-				'country_code'    => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
594
+				'currency'        => strtolower($currency),
595
+				'country_code'    => substr(get_option('woocommerce_default_country'), 0, 2),
596 596
 			),
597 597
 		);
598 598
 
599 599
 		$data['order_data'] += $this->build_display_items();
600 600
 
601
-		wp_send_json( $data );
601
+		wp_send_json($data);
602 602
 	}
603 603
 
604 604
 	/**
@@ -609,47 +609,47 @@  discard block
 block discarded – undo
609 609
 	 * @see WC_Shipping::get_packages().
610 610
 	 */
611 611
 	public function ajax_get_shipping_options() {
612
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
612
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
613 613
 
614 614
 		try {
615 615
 			// Set the shipping package.
616
-			$posted = filter_input_array( INPUT_POST, array(
616
+			$posted = filter_input_array(INPUT_POST, array(
617 617
 				'country'   => FILTER_SANITIZE_STRING,
618 618
 				'state'     => FILTER_SANITIZE_STRING,
619 619
 				'postcode'  => FILTER_SANITIZE_STRING,
620 620
 				'city'      => FILTER_SANITIZE_STRING,
621 621
 				'address'   => FILTER_SANITIZE_STRING,
622 622
 				'address_2' => FILTER_SANITIZE_STRING,
623
-			) );
623
+			));
624 624
 
625
-			$this->calculate_shipping( $posted );
625
+			$this->calculate_shipping($posted);
626 626
 
627 627
 			// Set the shipping options.
628 628
 			$data     = array();
629 629
 			$packages = WC()->shipping->get_packages();
630 630
 
631
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
632
-				foreach ( $packages as $package_key => $package ) {
633
-					if ( empty( $package['rates'] ) ) {
634
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
631
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
632
+				foreach ($packages as $package_key => $package) {
633
+					if (empty($package['rates'])) {
634
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
635 635
 					}
636 636
 
637
-					foreach ( $package['rates'] as $key => $rate ) {
637
+					foreach ($package['rates'] as $key => $rate) {
638 638
 						$data['shipping_options'][] = array(
639 639
 							'id'       => $rate->id,
640 640
 							'label'    => $rate->label,
641 641
 							'detail'   => '',
642
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
642
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($rate->cost),
643 643
 						);
644 644
 					}
645 645
 				}
646 646
 			} else {
647
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
647
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
648 648
 			}
649 649
 
650
-			if ( isset( $data[0] ) ) {
650
+			if (isset($data[0])) {
651 651
 				// Auto select the first shipping method.
652
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
652
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
653 653
 			}
654 654
 
655 655
 			WC()->cart->calculate_totals();
@@ -657,12 +657,12 @@  discard block
 block discarded – undo
657 657
 			$data += $this->build_display_items();
658 658
 			$data['result'] = 'success';
659 659
 
660
-			wp_send_json( $data );
661
-		} catch ( Exception $e ) {
660
+			wp_send_json($data);
661
+		} catch (Exception $e) {
662 662
 			$data += $this->build_display_items();
663 663
 			$data['result'] = 'invalid_shipping_address';
664 664
 
665
-			wp_send_json( $data );
665
+			wp_send_json($data);
666 666
 		}
667 667
 	}
668 668
 
@@ -670,22 +670,22 @@  discard block
 block discarded – undo
670 670
 	 * Update shipping method.
671 671
 	 */
672 672
 	public function ajax_update_shipping_method() {
673
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
673
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
674 674
 
675
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
676
-			define( 'WOOCOMMERCE_CART', true );
675
+		if ( ! defined('WOOCOMMERCE_CART')) {
676
+			define('WOOCOMMERCE_CART', true);
677 677
 		}
678 678
 
679
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
680
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
679
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
680
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
681 681
 
682
-		if ( is_array( $shipping_method ) ) {
683
-			foreach ( $shipping_method as $i => $value ) {
684
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
682
+		if (is_array($shipping_method)) {
683
+			foreach ($shipping_method as $i => $value) {
684
+				$chosen_shipping_methods[$i] = wc_clean($value);
685 685
 			}
686 686
 		}
687 687
 
688
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
688
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
689 689
 
690 690
 		WC()->cart->calculate_totals();
691 691
 
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 		$data += $this->build_display_items();
694 694
 		$data['result'] = 'success';
695 695
 
696
-		wp_send_json( $data );
696
+		wp_send_json($data);
697 697
 	}
698 698
 
699 699
 	/**
@@ -704,31 +704,31 @@  discard block
 block discarded – undo
704 704
 	 * @return array $data
705 705
 	 */
706 706
 	public function ajax_get_selected_product_data() {
707
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
707
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
708 708
 
709
-		$product_id = absint( $_POST['product_id'] );
710
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
709
+		$product_id = absint($_POST['product_id']);
710
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
711 711
 
712
-		$product = wc_get_product( $product_id );
712
+		$product = wc_get_product($product_id);
713 713
 
714
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
715
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
714
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
715
+			$attributes = array_map('wc_clean', $_POST['attributes']);
716 716
 
717
-			if ( WC_Stripe_Helper::is_pre_30() ) {
718
-				$variation_id = $product->get_matching_variation( $attributes );
717
+			if (WC_Stripe_Helper::is_pre_30()) {
718
+				$variation_id = $product->get_matching_variation($attributes);
719 719
 			} else {
720
-				$data_store = WC_Data_Store::load( 'product' );
721
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
720
+				$data_store = WC_Data_Store::load('product');
721
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
722 722
 			}
723 723
 
724
-			if ( ! empty( $variation_id ) ) {
725
-				$product = wc_get_product( $variation_id );
724
+			if ( ! empty($variation_id)) {
725
+				$product = wc_get_product($variation_id);
726 726
 			}
727
-		} elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
728
-			$product = wc_get_product( $product_id );
727
+		} elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
728
+			$product = wc_get_product($product_id);
729 729
 		}
730 730
 
731
-		$total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() );
731
+		$total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price());
732 732
 
733 733
 		$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
734 734
 
@@ -736,28 +736,28 @@  discard block
 block discarded – undo
736 736
 		$items = array();
737 737
 
738 738
 		$items[] = array(
739
-			'label'  => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label,
740
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
739
+			'label'  => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label,
740
+			'amount' => WC_Stripe_Helper::get_stripe_amount($total),
741 741
 		);
742 742
 
743
-		if ( wc_tax_enabled() ) {
743
+		if (wc_tax_enabled()) {
744 744
 			$items[] = array(
745
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
745
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
746 746
 				'amount'  => 0,
747 747
 				'pending' => true,
748 748
 			);
749 749
 		}
750 750
 
751
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
751
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
752 752
 			$items[] = array(
753
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
753
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
754 754
 				'amount'  => 0,
755 755
 				'pending' => true,
756 756
 			);
757 757
 
758
-			$data['shippingOptions']  = array(
758
+			$data['shippingOptions'] = array(
759 759
 				'id'     => 'pending',
760
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
760
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
761 761
 				'detail' => '',
762 762
 				'amount' => 0,
763 763
 			);
@@ -766,15 +766,15 @@  discard block
 block discarded – undo
766 766
 		$data['displayItems'] = $items;
767 767
 		$data['total'] = array(
768 768
 			'label'   => $this->total_label,
769
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
769
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
770 770
 			'pending' => true,
771 771
 		);
772 772
 
773
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
774
-		$data['currency']        = strtolower( get_woocommerce_currency() );
775
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
773
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
774
+		$data['currency']        = strtolower(get_woocommerce_currency());
775
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
776 776
 
777
-		wp_send_json( $data );
777
+		wp_send_json($data);
778 778
 	}
779 779
 
780 780
 	/**
@@ -785,37 +785,37 @@  discard block
 block discarded – undo
785 785
 	 * @return array $data
786 786
 	 */
787 787
 	public function ajax_add_to_cart() {
788
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
788
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
789 789
 
790
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
791
-			define( 'WOOCOMMERCE_CART', true );
790
+		if ( ! defined('WOOCOMMERCE_CART')) {
791
+			define('WOOCOMMERCE_CART', true);
792 792
 		}
793 793
 
794 794
 		WC()->shipping->reset_shipping();
795 795
 
796
-		$product_id = absint( $_POST['product_id'] );
797
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
796
+		$product_id = absint($_POST['product_id']);
797
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
798 798
 
799
-		$product = wc_get_product( $product_id );
799
+		$product = wc_get_product($product_id);
800 800
 
801 801
 		// First empty the cart to prevent wrong calculation.
802 802
 		WC()->cart->empty_cart();
803 803
 
804
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
805
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
804
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
805
+			$attributes = array_map('wc_clean', $_POST['attributes']);
806 806
 
807
-			if ( WC_Stripe_Helper::is_pre_30() ) {
808
-				$variation_id = $product->get_matching_variation( $attributes );
807
+			if (WC_Stripe_Helper::is_pre_30()) {
808
+				$variation_id = $product->get_matching_variation($attributes);
809 809
 			} else {
810
-				$data_store = WC_Data_Store::load( 'product' );
811
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
810
+				$data_store = WC_Data_Store::load('product');
811
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
812 812
 			}
813 813
 
814
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
814
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
815 815
 		}
816 816
 
817
-		if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
818
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
817
+		if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
818
+			WC()->cart->add_to_cart($product->get_id(), $qty);
819 819
 		}
820 820
 
821 821
 		WC()->cart->calculate_totals();
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 		$data += $this->build_display_items();
825 825
 		$data['result'] = 'success';
826 826
 
827
-		wp_send_json( $data );
827
+		wp_send_json($data);
828 828
 	}
829 829
 
830 830
 	/**
@@ -837,31 +837,31 @@  discard block
 block discarded – undo
837 837
 	 * @version 4.0.0
838 838
 	 */
839 839
 	public function normalize_state() {
840
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
841
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
842
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
843
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
840
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
841
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
842
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
843
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
844 844
 
845
-		if ( $billing_state && $billing_country ) {
846
-			$valid_states = WC()->countries->get_states( $billing_country );
845
+		if ($billing_state && $billing_country) {
846
+			$valid_states = WC()->countries->get_states($billing_country);
847 847
 
848 848
 			// Valid states found for country.
849
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
850
-				foreach ( $valid_states as $state_abbr => $state ) {
851
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
849
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
850
+				foreach ($valid_states as $state_abbr => $state) {
851
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
852 852
 						$_POST['billing_state'] = $state_abbr;
853 853
 					}
854 854
 				}
855 855
 			}
856 856
 		}
857 857
 
858
-		if ( $shipping_state && $shipping_country ) {
859
-			$valid_states = WC()->countries->get_states( $shipping_country );
858
+		if ($shipping_state && $shipping_country) {
859
+			$valid_states = WC()->countries->get_states($shipping_country);
860 860
 
861 861
 			// Valid states found for country.
862
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
863
-				foreach ( $valid_states as $state_abbr => $state ) {
864
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
862
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
863
+				foreach ($valid_states as $state_abbr => $state) {
864
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
865 865
 						$_POST['shipping_state'] = $state_abbr;
866 866
 					}
867 867
 				}
@@ -876,19 +876,19 @@  discard block
 block discarded – undo
876 876
 	 * @version 4.0.0
877 877
 	 */
878 878
 	public function ajax_create_order() {
879
-		if ( WC()->cart->is_empty() ) {
880
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
879
+		if (WC()->cart->is_empty()) {
880
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
881 881
 		}
882 882
 
883
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
884
-			define( 'WOOCOMMERCE_CHECKOUT', true );
883
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
884
+			define('WOOCOMMERCE_CHECKOUT', true);
885 885
 		}
886 886
 
887 887
 		$this->normalize_state();
888 888
 
889 889
 		WC()->checkout()->process_checkout();
890 890
 
891
-		die( 0 );
891
+		die(0);
892 892
 	}
893 893
 
894 894
 	/**
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 	 * @version 4.0.0
899 899
 	 * @param array $address
900 900
 	 */
901
-	protected function calculate_shipping( $address = array() ) {
901
+	protected function calculate_shipping($address = array()) {
902 902
 		global $states;
903 903
 
904 904
 		$country   = $address['country'];
@@ -915,28 +915,28 @@  discard block
 block discarded – undo
915 915
 		 * In some versions of Chrome, state can be a full name. So we need
916 916
 		 * to convert that to abbreviation as WC is expecting that.
917 917
 		 */
918
-		if ( 2 < strlen( $state ) ) {
919
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
918
+		if (2 < strlen($state)) {
919
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
920 920
 		}
921 921
 
922 922
 		WC()->shipping->reset_shipping();
923 923
 
924
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
925
-			$postcode = wc_format_postcode( $postcode, $country );
924
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
925
+			$postcode = wc_format_postcode($postcode, $country);
926 926
 		}
927 927
 
928
-		if ( $country ) {
929
-			WC()->customer->set_location( $country, $state, $postcode, $city );
930
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
928
+		if ($country) {
929
+			WC()->customer->set_location($country, $state, $postcode, $city);
930
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
931 931
 		} else {
932 932
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
933 933
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
934 934
 		}
935 935
 
936
-		if ( WC_Stripe_Helper::is_pre_30() ) {
937
-			WC()->customer->calculated_shipping( true );
936
+		if (WC_Stripe_Helper::is_pre_30()) {
937
+			WC()->customer->calculated_shipping(true);
938 938
 		} else {
939
-			WC()->customer->set_calculated_shipping( true );
939
+			WC()->customer->set_calculated_shipping(true);
940 940
 			WC()->customer->save();
941 941
 		}
942 942
 
@@ -953,17 +953,17 @@  discard block
 block discarded – undo
953 953
 		$packages[0]['destination']['address']   = $address_1;
954 954
 		$packages[0]['destination']['address_2'] = $address_2;
955 955
 
956
-		foreach ( WC()->cart->get_cart() as $item ) {
957
-			if ( $item['data']->needs_shipping() ) {
958
-				if ( isset( $item['line_total'] ) ) {
956
+		foreach (WC()->cart->get_cart() as $item) {
957
+			if ($item['data']->needs_shipping()) {
958
+				if (isset($item['line_total'])) {
959 959
 					$packages[0]['contents_cost'] += $item['line_total'];
960 960
 				}
961 961
 			}
962 962
 		}
963 963
 
964
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
964
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
965 965
 
966
-		WC()->shipping->calculate_shipping( $packages );
966
+		WC()->shipping->calculate_shipping($packages);
967 967
 	}
968 968
 
969 969
 	/**
@@ -972,19 +972,19 @@  discard block
 block discarded – undo
972 972
 	 * @since 3.1.0
973 973
 	 * @version 4.0.0
974 974
 	 */
975
-	protected function build_shipping_methods( $shipping_methods ) {
976
-		if ( empty( $shipping_methods ) ) {
975
+	protected function build_shipping_methods($shipping_methods) {
976
+		if (empty($shipping_methods)) {
977 977
 			return array();
978 978
 		}
979 979
 
980 980
 		$shipping = array();
981 981
 
982
-		foreach ( $shipping_methods as $method ) {
982
+		foreach ($shipping_methods as $method) {
983 983
 			$shipping[] = array(
984 984
 				'id'         => $method['id'],
985 985
 				'label'      => $method['label'],
986 986
 				'detail'     => '',
987
-				'amount'     => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
987
+				'amount'     => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
988 988
 			);
989 989
 		}
990 990
 
@@ -998,69 +998,69 @@  discard block
 block discarded – undo
998 998
 	 * @version 4.0.0
999 999
 	 */
1000 1000
 	protected function build_display_items() {
1001
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1002
-			define( 'WOOCOMMERCE_CART', true );
1001
+		if ( ! defined('WOOCOMMERCE_CART')) {
1002
+			define('WOOCOMMERCE_CART', true);
1003 1003
 		}
1004 1004
 
1005 1005
 		$items    = array();
1006 1006
 		$subtotal = 0;
1007 1007
 
1008 1008
 		// Default show only subtotal instead of itemization.
1009
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1010
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1009
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1010
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1011 1011
 				$amount         = $cart_item['line_subtotal'];
1012
-				$subtotal       += $cart_item['line_subtotal'];
1012
+				$subtotal += $cart_item['line_subtotal'];
1013 1013
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1014 1014
 
1015 1015
 				$product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1016 1016
 
1017 1017
 				$item = array(
1018 1018
 					'label'  => $product_name . $quantity_label,
1019
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1019
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1020 1020
 				);
1021 1021
 
1022 1022
 				$items[] = $item;
1023 1023
 			}
1024 1024
 		}
1025 1025
 
1026
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1027
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1028
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1029
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1030
-		$order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp );
1026
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1027
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1028
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1029
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1030
+		$order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp);
1031 1031
 
1032
-		if ( wc_tax_enabled() ) {
1032
+		if (wc_tax_enabled()) {
1033 1033
 			$items[] = array(
1034
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1035
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1034
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1035
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1036 1036
 			);
1037 1037
 		}
1038 1038
 
1039
-		if ( WC()->cart->needs_shipping() ) {
1039
+		if (WC()->cart->needs_shipping()) {
1040 1040
 			$items[] = array(
1041
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1042
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1041
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1042
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1043 1043
 			);
1044 1044
 		}
1045 1045
 
1046
-		if ( WC()->cart->has_discount() ) {
1046
+		if (WC()->cart->has_discount()) {
1047 1047
 			$items[] = array(
1048
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1049
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1048
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1049
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1050 1050
 			);
1051 1051
 		}
1052 1052
 
1053
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1053
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1054 1054
 			$cart_fees = WC()->cart->fees;
1055 1055
 		} else {
1056 1056
 			$cart_fees = WC()->cart->get_fees();
1057 1057
 		}
1058 1058
 
1059 1059
 		// Include fees and taxes as display items.
1060
-		foreach ( $cart_fees as $key => $fee ) {
1060
+		foreach ($cart_fees as $key => $fee) {
1061 1061
 			$items[] = array(
1062 1062
 				'label'  => $fee->name,
1063
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1063
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1064 1064
 			);
1065 1065
 		}
1066 1066
 
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 			'displayItems' => $items,
1069 1069
 			'total'      => array(
1070 1070
 				'label'   => $this->total_label,
1071
-				'amount'  => max( 0, apply_filters( 'woocommerce_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1071
+				'amount'  => max(0, apply_filters('woocommerce_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1072 1072
 				'pending' => false,
1073 1073
 			),
1074 1074
 		);
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-alipay.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_alipay';
60
-		$this->method_title         = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Alipay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function get_environment_warning() {
127 127
 		if (
128
-			'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() )
128
+			'yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())
129 129
 		) {
130 130
 			/* translators: supported currency list */
131
-			$message = sprintf( __( 'Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), implode( ', ', $this->get_supported_currency() ) );
131
+			$message = sprintf(__('Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), implode(', ', $this->get_supported_currency()));
132 132
 
133 133
 			return $message;
134 134
 		}
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @return array
145 145
 	 */
146 146
 	public function get_supported_currency() {
147
-		return apply_filters( 'wc_stripe_alipay_supported_currencies', array(
147
+		return apply_filters('wc_stripe_alipay_supported_currencies', array(
148 148
 			'EUR',
149 149
 			'AUD',
150 150
 			'CAD',
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			'NZD',
155 155
 			'SGD',
156 156
 			'USD',
157
-		) );
157
+		));
158 158
 	}
159 159
 
160 160
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function is_available() {
168
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
168
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 	 * @return array
181 181
 	 */
182 182
 	public function payment_icons() {
183
-		return apply_filters( 'wc_stripe_payment_icons', array(
183
+		return apply_filters('wc_stripe_payment_icons', array(
184 184
 			'alipay' => '<i class="stripe-pf stripe-pf-alipay stripe-pf-right" alt="Alipay" aria-hidden="true"></i>',
185
-		) );
185
+		));
186 186
 	}
187 187
 
188 188
 	/**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 
200 200
 		$icons_str .= $icons['alipay'];
201 201
 
202
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
202
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
203 203
 	}
204 204
 
205 205
 	/**
@@ -209,19 +209,19 @@  discard block
 block discarded – undo
209 209
 	 * @version 4.0.0
210 210
 	 */
211 211
 	public function payment_scripts() {
212
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
212
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
213 213
 			return;
214 214
 		}
215 215
 
216
-		wp_enqueue_style( 'stripe_paymentfonts' );
217
-		wp_enqueue_script( 'woocommerce_stripe' );
216
+		wp_enqueue_style('stripe_paymentfonts');
217
+		wp_enqueue_script('woocommerce_stripe');
218 218
 	}
219 219
 
220 220
 	/**
221 221
 	 * Initialize Gateway Settings Form Fields.
222 222
 	 */
223 223
 	public function init_form_fields() {
224
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' );
224
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php');
225 225
 	}
226 226
 
227 227
 	/**
@@ -232,25 +232,25 @@  discard block
 block discarded – undo
232 232
 		$total                = WC()->cart->total;
233 233
 
234 234
 		// If paying from order, we need to get total from order not cart.
235
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
236
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
235
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
236
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
237 237
 			$total = $order->get_total();
238 238
 		}
239 239
 
240
-		if ( is_add_payment_method_page() ) {
241
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
242
-			$total        = '';
240
+		if (is_add_payment_method_page()) {
241
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
242
+			$total = '';
243 243
 		} else {
244 244
 			$pay_button_text = '';
245 245
 		}
246 246
 
247 247
 		echo '<div
248 248
 			id="stripe-alipay-payment-data"
249
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
250
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
249
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
250
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
251 251
 
252
-		if ( $this->description ) {
253
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
252
+		if ($this->description) {
253
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
254 254
 		}
255 255
 
256 256
 		echo '</div>';
@@ -264,24 +264,24 @@  discard block
 block discarded – undo
264 264
 	 * @param object $order
265 265
 	 * @return mixed
266 266
 	 */
267
-	public function create_source( $order ) {
267
+	public function create_source($order) {
268 268
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
269 269
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
270
-		$return_url                        = $this->get_stripe_return_url( $order );
270
+		$return_url                        = $this->get_stripe_return_url($order);
271 271
 		$post_data                         = array();
272
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
273
-		$post_data['currency']             = strtolower( $currency );
272
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
273
+		$post_data['currency']             = strtolower($currency);
274 274
 		$post_data['type']                 = 'alipay';
275
-		$post_data['owner']                = $this->get_owner_details( $order );
276
-		$post_data['redirect']             = array( 'return_url' => $return_url );
275
+		$post_data['owner']                = $this->get_owner_details($order);
276
+		$post_data['redirect']             = array('return_url' => $return_url);
277 277
 
278
-		if ( ! empty( $this->statement_descriptor ) ) {
279
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
278
+		if ( ! empty($this->statement_descriptor)) {
279
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
280 280
 		}
281 281
 
282
-		WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' );
282
+		WC_Stripe_Logger::log('Info: Begin creating Alipay source');
283 283
 
284
-		return WC_Stripe_API::request( $post_data, 'sources' );
284
+		return WC_Stripe_API::request($post_data, 'sources');
285 285
 	}
286 286
 
287 287
 	/**
@@ -295,53 +295,53 @@  discard block
 block discarded – undo
295 295
 	 *
296 296
 	 * @return array|void
297 297
 	 */
298
-	public function process_payment( $order_id, $retry = true, $force_save_save = false ) {
298
+	public function process_payment($order_id, $retry = true, $force_save_save = false) {
299 299
 		try {
300
-			$order = wc_get_order( $order_id );
300
+			$order = wc_get_order($order_id);
301 301
 
302 302
 			// This will throw exception if not valid.
303
-			$this->validate_minimum_order_amount( $order );
303
+			$this->validate_minimum_order_amount($order);
304 304
 
305 305
 			// This comes from the create account checkbox in the checkout page.
306
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
306
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
307 307
 
308
-			if ( $create_account ) {
308
+			if ($create_account) {
309 309
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
310
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
310
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
311 311
 				$new_stripe_customer->create_customer();
312 312
 			}
313 313
 
314
-			$response = $this->create_source( $order );
314
+			$response = $this->create_source($order);
315 315
 
316
-			if ( ! empty( $response->error ) ) {
317
-				$order->add_order_note( $response->error->message );
316
+			if ( ! empty($response->error)) {
317
+				$order->add_order_note($response->error->message);
318 318
 
319
-				throw new Exception( $response->error->message );
319
+				throw new Exception($response->error->message);
320 320
 			}
321 321
 
322
-			if ( WC_Stripe_Helper::is_pre_30() ) {
323
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
322
+			if (WC_Stripe_Helper::is_pre_30()) {
323
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
324 324
 			} else {
325
-				$order->update_meta_data( '_stripe_source_id', $response->id );
325
+				$order->update_meta_data('_stripe_source_id', $response->id);
326 326
 				$order->save();
327 327
 			}
328 328
 
329
-			WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' );
329
+			WC_Stripe_Logger::log('Info: Redirecting to Alipay...');
330 330
 
331 331
 			return array(
332 332
 				'result'   => 'success',
333
-				'redirect' => esc_url_raw( $response->redirect->url ),
333
+				'redirect' => esc_url_raw($response->redirect->url),
334 334
 			);
335
-		} catch ( Exception $e ) {
336
-			wc_add_notice( $e->getMessage(), 'error' );
337
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
335
+		} catch (Exception $e) {
336
+			wc_add_notice($e->getMessage(), 'error');
337
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
338 338
 
339
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
339
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
340 340
 
341
-			$statuses = array( 'pending', 'failed' );
341
+			$statuses = array('pending', 'failed');
342 342
 
343
-			if ( $order->has_status( $statuses ) ) {
344
-				$this->send_failed_order_email( $order_id );
343
+			if ($order->has_status($statuses)) {
344
+				$this->send_failed_order_email($order_id);
345 345
 			}
346 346
 
347 347
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-giropay.php 1 patch
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_giropay';
60
-		$this->method_title         = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe Giropay', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_giropay_supported_currencies', array(
144
+		return apply_filters('wc_stripe_giropay_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 	 * @return array
170 170
 	 */
171 171
 	public function payment_icons() {
172
-		return apply_filters( 'wc_stripe_payment_icons', array(
172
+		return apply_filters('wc_stripe_payment_icons', array(
173 173
 			'giropay' => '<i class="stripe-pf stripe-pf-giropay stripe-pf-right" alt="Giropay" aria-hidden="true"></i>',
174
-		) );
174
+		));
175 175
 	}
176 176
 
177 177
 	/**
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 		$icons_str .= $icons['giropay'];
190 190
 
191
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
191
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
192 192
 	}
193 193
 
194 194
 	/**
@@ -199,19 +199,19 @@  discard block
 block discarded – undo
199 199
 	 * @access public
200 200
 	 */
201 201
 	public function payment_scripts() {
202
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
202
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
203 203
 			return;
204 204
 		}
205 205
 
206
-		wp_enqueue_style( 'stripe_paymentfonts' );
207
-		wp_enqueue_script( 'woocommerce_stripe' );
206
+		wp_enqueue_style('stripe_paymentfonts');
207
+		wp_enqueue_script('woocommerce_stripe');
208 208
 	}
209 209
 
210 210
 	/**
211 211
 	 * Initialize Gateway Settings Form Fields.
212 212
 	 */
213 213
 	public function init_form_fields() {
214
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' );
214
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php');
215 215
 	}
216 216
 
217 217
 	/**
@@ -222,25 +222,25 @@  discard block
 block discarded – undo
222 222
 		$total                = WC()->cart->total;
223 223
 
224 224
 		// If paying from order, we need to get total from order not cart.
225
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
226
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
225
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
226
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
227 227
 			$total = $order->get_total();
228 228
 		}
229 229
 
230
-		if ( is_add_payment_method_page() ) {
231
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
232
-			$total        = '';
230
+		if (is_add_payment_method_page()) {
231
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
232
+			$total = '';
233 233
 		} else {
234 234
 			$pay_button_text = '';
235 235
 		}
236 236
 
237 237
 		echo '<div
238 238
 			id="stripe-giropay-payment-data"
239
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
240
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
239
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
240
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
241 241
 
242
-		if ( $this->description ) {
243
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
242
+		if ($this->description) {
243
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
244 244
 		}
245 245
 
246 246
 		echo '</div>';
@@ -254,24 +254,24 @@  discard block
 block discarded – undo
254 254
 	 * @param object $order
255 255
 	 * @return mixed
256 256
 	 */
257
-	public function create_source( $order ) {
257
+	public function create_source($order) {
258 258
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
259 259
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
260
-		$return_url                        = $this->get_stripe_return_url( $order );
260
+		$return_url                        = $this->get_stripe_return_url($order);
261 261
 		$post_data                         = array();
262
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
263
-		$post_data['currency']             = strtolower( $currency );
262
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
263
+		$post_data['currency']             = strtolower($currency);
264 264
 		$post_data['type']                 = 'giropay';
265
-		$post_data['owner']                = $this->get_owner_details( $order );
266
-		$post_data['redirect']             = array( 'return_url' => $return_url );
265
+		$post_data['owner']                = $this->get_owner_details($order);
266
+		$post_data['redirect']             = array('return_url' => $return_url);
267 267
 
268
-		if ( ! empty( $this->statement_descriptor ) ) {
269
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
268
+		if ( ! empty($this->statement_descriptor)) {
269
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
270 270
 		}
271 271
 
272
-		WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' );
272
+		WC_Stripe_Logger::log('Info: Begin creating Giropay source');
273 273
 
274
-		return WC_Stripe_API::request( $post_data, 'sources' );
274
+		return WC_Stripe_API::request($post_data, 'sources');
275 275
 	}
276 276
 
277 277
 	/**
@@ -285,51 +285,51 @@  discard block
 block discarded – undo
285 285
 	 *
286 286
 	 * @return array|void
287 287
 	 */
288
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
288
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
289 289
 		try {
290
-			$order = wc_get_order( $order_id );
290
+			$order = wc_get_order($order_id);
291 291
 
292 292
 			// This will throw exception if not valid.
293
-			$this->validate_minimum_order_amount( $order );
293
+			$this->validate_minimum_order_amount($order);
294 294
 
295 295
 			// This comes from the create account checkbox in the checkout page.
296
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
296
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
297 297
 
298
-			if ( $create_account ) {
298
+			if ($create_account) {
299 299
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
300
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
300
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
301 301
 				$new_stripe_customer->create_customer();
302 302
 			}
303 303
 
304
-			$response = $this->create_source( $order );
304
+			$response = $this->create_source($order);
305 305
 
306
-			if ( ! empty( $response->error ) ) {
307
-				$order->add_order_note( $response->error->message );
306
+			if ( ! empty($response->error)) {
307
+				$order->add_order_note($response->error->message);
308 308
 
309
-				throw new Exception( $response->error->message );
309
+				throw new Exception($response->error->message);
310 310
 			}
311 311
 
312
-			if ( WC_Stripe_Helper::is_pre_30() ) {
313
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
312
+			if (WC_Stripe_Helper::is_pre_30()) {
313
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
314 314
 			} else {
315
-				$order->update_meta_data( '_stripe_source_id', $response->id );
315
+				$order->update_meta_data('_stripe_source_id', $response->id);
316 316
 				$order->save();
317 317
 			}
318 318
 
319
-			WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' );
319
+			WC_Stripe_Logger::log('Info: Redirecting to Giropay...');
320 320
 
321 321
 			return array(
322 322
 				'result'   => 'success',
323
-				'redirect' => esc_url_raw( $response->redirect->url ),
323
+				'redirect' => esc_url_raw($response->redirect->url),
324 324
 			);
325
-		} catch ( Exception $e ) {
326
-			wc_add_notice( $e->getMessage(), 'error' );
327
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
325
+		} catch (Exception $e) {
326
+			wc_add_notice($e->getMessage(), 'error');
327
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
328 328
 
329
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
329
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
330 330
 
331
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
332
-				$this->send_failed_order_email( $order_id );
331
+			if ($order->has_status(array('pending', 'failed'))) {
332
+				$this->send_failed_order_email($order_id);
333 333
 			}
334 334
 
335 335
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-ideal.php 1 patch
Spacing   +78 added lines, -78 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_ideal';
60
-		$this->method_title         = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe iDeal', '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 = __( 'iDeal 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 = __('iDeal 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_ideal_supported_currencies', array(
144
+		return apply_filters('wc_stripe_ideal_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
 
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 	 * @return array
170 170
 	 */
171 171
 	public function payment_icons() {
172
-		return apply_filters( 'wc_stripe_payment_icons', array(
172
+		return apply_filters('wc_stripe_payment_icons', array(
173 173
 			'ideal' => '<i class="stripe-pf stripe-pf-ideal stripe-pf-right" alt="iDeal" aria-hidden="true"></i>',
174
-		) );
174
+		));
175 175
 	}
176 176
 
177 177
 	/**
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 		$icons_str .= $icons['ideal'];
190 190
 
191
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
191
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
192 192
 	}
193 193
 
194 194
 	/**
@@ -199,19 +199,19 @@  discard block
 block discarded – undo
199 199
 	 * @access public
200 200
 	 */
201 201
 	public function payment_scripts() {
202
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
202
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
203 203
 			return;
204 204
 		}
205 205
 
206
-		wp_enqueue_style( 'stripe_paymentfonts' );
207
-		wp_enqueue_script( 'woocommerce_stripe' );
206
+		wp_enqueue_style('stripe_paymentfonts');
207
+		wp_enqueue_script('woocommerce_stripe');
208 208
 	}
209 209
 
210 210
 	/**
211 211
 	 * Initialize Gateway Settings Form Fields.
212 212
 	 */
213 213
 	public function init_form_fields() {
214
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' );
214
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php');
215 215
 	}
216 216
 
217 217
 	/**
@@ -222,25 +222,25 @@  discard block
 block discarded – undo
222 222
 		$total                = WC()->cart->total;
223 223
 
224 224
 		// If paying from order, we need to get total from order not cart.
225
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
226
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
225
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
226
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
227 227
 			$total = $order->get_total();
228 228
 		}
229 229
 
230
-		if ( is_add_payment_method_page() ) {
231
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
232
-			$total        = '';
230
+		if (is_add_payment_method_page()) {
231
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
232
+			$total = '';
233 233
 		} else {
234 234
 			$pay_button_text = '';
235 235
 		}
236 236
 
237 237
 		echo '<div
238 238
 			id="stripe-ideal-payment-data"
239
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
240
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
239
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
240
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
241 241
 
242
-		if ( $this->description ) {
243
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
242
+		if ($this->description) {
243
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
244 244
 		}
245 245
 
246 246
 		echo '</div>';
@@ -254,24 +254,24 @@  discard block
 block discarded – undo
254 254
 	 * @param object $order
255 255
 	 * @return mixed
256 256
 	 */
257
-	public function create_source( $order ) {
257
+	public function create_source($order) {
258 258
 		$currency                          = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
259 259
 		$order_id                          = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
260
-		$return_url                        = $this->get_stripe_return_url( $order );
260
+		$return_url                        = $this->get_stripe_return_url($order);
261 261
 		$post_data                         = array();
262
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
263
-		$post_data['currency']             = strtolower( $currency );
262
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
263
+		$post_data['currency']             = strtolower($currency);
264 264
 		$post_data['type']                 = 'ideal';
265
-		$post_data['owner']                = $this->get_owner_details( $order );
266
-		$post_data['redirect']             = array( 'return_url' => $return_url );
265
+		$post_data['owner']                = $this->get_owner_details($order);
266
+		$post_data['redirect']             = array('return_url' => $return_url);
267 267
 
268
-		if ( ! empty( $this->statement_descriptor ) ) {
269
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
268
+		if ( ! empty($this->statement_descriptor)) {
269
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
270 270
 		}
271 271
 
272
-		WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' );
272
+		WC_Stripe_Logger::log('Info: Begin creating iDeal source');
273 273
 
274
-		return WC_Stripe_API::request( $post_data, 'sources' );
274
+		return WC_Stripe_API::request($post_data, 'sources');
275 275
 	}
276 276
 
277 277
 	/**
@@ -285,51 +285,51 @@  discard block
 block discarded – undo
285 285
 	 *
286 286
 	 * @return array|void
287 287
 	 */
288
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
288
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
289 289
 		try {
290
-			$order = wc_get_order( $order_id );
290
+			$order = wc_get_order($order_id);
291 291
 
292 292
 			// This will throw exception if not valid.
293
-			$this->validate_minimum_order_amount( $order );
293
+			$this->validate_minimum_order_amount($order);
294 294
 
295 295
 			// This comes from the create account checkbox in the checkout page.
296
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
296
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
297 297
 
298
-			if ( $create_account ) {
298
+			if ($create_account) {
299 299
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
300
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
300
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
301 301
 				$new_stripe_customer->create_customer();
302 302
 			}
303 303
 
304
-			$response = $this->create_source( $order );
304
+			$response = $this->create_source($order);
305 305
 
306
-			if ( ! empty( $response->error ) ) {
307
-				$order->add_order_note( $response->error->message );
306
+			if ( ! empty($response->error)) {
307
+				$order->add_order_note($response->error->message);
308 308
 
309
-				throw new Exception( $response->error->message );
309
+				throw new Exception($response->error->message);
310 310
 			}
311 311
 
312
-			if ( WC_Stripe_Helper::is_pre_30() ) {
313
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
312
+			if (WC_Stripe_Helper::is_pre_30()) {
313
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
314 314
 			} else {
315
-				$order->update_meta_data( '_stripe_source_id', $response->id );
315
+				$order->update_meta_data('_stripe_source_id', $response->id);
316 316
 				$order->save();
317 317
 			}
318 318
 
319
-			WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' );
319
+			WC_Stripe_Logger::log('Info: Redirecting to iDeal...');
320 320
 
321 321
 			return array(
322 322
 				'result'   => 'success',
323
-				'redirect' => esc_url_raw( $response->redirect->url ),
323
+				'redirect' => esc_url_raw($response->redirect->url),
324 324
 			);
325
-		} catch ( Exception $e ) {
326
-			wc_add_notice( $e->getMessage(), 'error' );
327
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
325
+		} catch (Exception $e) {
326
+			wc_add_notice($e->getMessage(), 'error');
327
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
328 328
 
329
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
329
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
330 330
 
331
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
332
-				$this->send_failed_order_email( $order_id );
331
+			if ($order->has_status(array('pending', 'failed'))) {
332
+				$this->send_failed_order_email($order_id);
333 333
 			}
334 334
 
335 335
 			return array(
Please login to merge, or discard this patch.