Completed
Push — master ( 2d7327...a3e3dd )
by Roy
10s
created
includes/class-wc-gateway-stripe-addons.php 2 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -96,7 +96,6 @@  discard block
 block discarded – undo
96 96
 	 * process_subscription_payment function.
97 97
 	 * @param mixed $order
98 98
 	 * @param int $amount (default: 0)
99
-	 * @param string $stripe_token (default: '')
100 99
 	 * @param  bool initial_payment
101 100
 	 */
102 101
 	public function process_subscription_payment( $order = '', $amount = 0 ) {
@@ -139,6 +138,8 @@  discard block
 block discarded – undo
139 138
 	/**
140 139
 	 * Process the pre-order
141 140
 	 * @param int $order_id
141
+	 * @param boolean $retry
142
+	 * @param boolean $force_customer
142 143
 	 * @return array
143 144
 	 */
144 145
 	public function process_pre_order( $order_id, $retry, $force_customer ) {
@@ -239,7 +240,7 @@  discard block
 block discarded – undo
239 240
 
240 241
 	/**
241 242
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
242
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
243
+	 * @param integer $renewal_order
243 244
 	 */
244 245
 	public function delete_renewal_meta( $renewal_order ) {
245 246
 		delete_post_meta( $renewal_order->id, 'Stripe Fee' );
Please login to merge, or discard this patch.
Spacing   +121 added lines, -121 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
 
@@ -16,22 +16,22 @@  discard block
 block discarded – undo
16 16
 	public function __construct() {
17 17
 		parent::__construct();
18 18
 
19
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
20
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
21
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
22
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
23
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
19
+		if (class_exists('WC_Subscriptions_Order')) {
20
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
21
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
22
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
23
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
24 24
 
25 25
 			// display the credit card used for a subscription in the "My Subscriptions" table
26
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
26
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
27 27
 
28 28
 			// allow store managers to manually set Stripe as the payment method on a subscription
29
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
29
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
30
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
31 31
 		}
32 32
 
33
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
34
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
33
+		if (class_exists('WC_Pre_Orders_Order')) {
34
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
35 35
 		}
36 36
 	}
37 37
 
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	 * @param  int  $order_id
41 41
 	 * @return boolean
42 42
 	 */
43
-	protected function is_subscription( $order_id ) {
44
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
43
+	protected function is_subscription($order_id) {
44
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
45 45
 	}
46 46
 
47 47
 	/**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	 * @param  int  $order_id
50 50
 	 * @return boolean
51 51
 	 */
52
-	protected function is_pre_order( $order_id ) {
53
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
52
+	protected function is_pre_order($order_id) {
53
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
54 54
 	}
55 55
 
56 56
 	/**
@@ -58,37 +58,37 @@  discard block
 block discarded – undo
58 58
 	 * @param  int $order_id
59 59
 	 * @return array
60 60
 	 */
61
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
62
-		if ( $this->is_subscription( $order_id ) ) {
61
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
62
+		if ($this->is_subscription($order_id)) {
63 63
 			// Regular payment with force customer enabled
64
-			return parent::process_payment( $order_id, true, true );
64
+			return parent::process_payment($order_id, true, true);
65 65
 
66
-		} elseif ( $this->is_pre_order( $order_id ) ) {
67
-			return $this->process_pre_order( $order_id, $retry, $force_customer );
66
+		} elseif ($this->is_pre_order($order_id)) {
67
+			return $this->process_pre_order($order_id, $retry, $force_customer);
68 68
 
69 69
 		} else {
70
-			return parent::process_payment( $order_id, $retry, $force_customer );
70
+			return parent::process_payment($order_id, $retry, $force_customer);
71 71
 		}
72 72
 	}
73 73
 
74 74
 	/**
75 75
 	 * Updates other subscription sources.
76 76
 	 */
77
-	protected function save_source( $order, $source ) {
78
-		parent::save_source( $order, $source );
77
+	protected function save_source($order, $source) {
78
+		parent::save_source($order, $source);
79 79
 
80 80
 		// Also store it on the subscriptions being purchased or paid for in the order
81
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order->id ) ) {
82
-			$subscriptions = wcs_get_subscriptions_for_order( $order->id );
83
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order->id ) ) {
84
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order->id );
81
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order->id)) {
82
+			$subscriptions = wcs_get_subscriptions_for_order($order->id);
83
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order->id)) {
84
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order->id);
85 85
 		} else {
86 86
 			$subscriptions = array();
87 87
 		}
88 88
 
89
-		foreach( $subscriptions as $subscription ) {
90
-			update_post_meta( $subscription->id, '_stripe_customer_id', $source->customer );
91
-			update_post_meta( $subscription->id, '_stripe_card_id', $source->source );
89
+		foreach ($subscriptions as $subscription) {
90
+			update_post_meta($subscription->id, '_stripe_customer_id', $source->customer);
91
+			update_post_meta($subscription->id, '_stripe_card_id', $source->source);
92 92
 		}
93 93
 	}
94 94
 
@@ -99,39 +99,39 @@  discard block
 block discarded – undo
99 99
 	 * @param string $stripe_token (default: '')
100 100
 	 * @param  bool initial_payment
101 101
 	 */
102
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
102
+	public function process_subscription_payment($order = '', $amount = 0) {
103 103
 		
104
-		if ( $amount * 100 < WC_Stripe::get_minimum_amount() ) {
105
-			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
104
+		if ($amount * 100 < WC_Stripe::get_minimum_amount()) {
105
+			return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
106 106
 		}
107 107
 
108 108
 		// Get source from order
109
-		$source = $this->get_order_source( $order );
109
+		$source = $this->get_order_source($order);
110 110
 
111 111
 		// If no order source was defined, use user source instead.
112
-		if ( ! $source->customer ) {
113
-			$source = $this->get_source( $order->customer_user );
112
+		if ( ! $source->customer) {
113
+			$source = $this->get_source($order->customer_user);
114 114
 		}
115 115
 
116 116
 		// Or fail :(
117
-		if ( ! $source->customer ) {
118
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
117
+		if ( ! $source->customer) {
118
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
119 119
 		}
120 120
 
121
-		WC_Stripe::log( "Info: Begin processing subscription payment for order {$order->id} for the amount of {$amount}" );
121
+		WC_Stripe::log("Info: Begin processing subscription payment for order {$order->id} for the amount of {$amount}");
122 122
 
123 123
 		// Make the request
124
-		$request             = $this->generate_payment_request( $order, $source );
124
+		$request             = $this->generate_payment_request($order, $source);
125 125
 		$request['capture']  = 'true';
126
-		$request['amount']   = $this->get_stripe_amount( $amount, $request['currency'] );
126
+		$request['amount']   = $this->get_stripe_amount($amount, $request['currency']);
127 127
 		$request['metadata'] = array(
128 128
 			'payment_type'   => 'recurring'
129 129
 		);
130
-		$response            = WC_Stripe_API::request( $request );
130
+		$response            = WC_Stripe_API::request($request);
131 131
 
132 132
 		// Process valid response
133
-		if ( ! is_wp_error( $response ) ) {
134
-			$this->process_response( $response, $order );
133
+		if ( ! is_wp_error($response)) {
134
+			$this->process_response($response, $order);
135 135
 		}
136 136
 
137 137
 		return $response;
@@ -142,24 +142,24 @@  discard block
 block discarded – undo
142 142
 	 * @param int $order_id
143 143
 	 * @return array
144 144
 	 */
145
-	public function process_pre_order( $order_id, $retry, $force_customer ) {
146
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
145
+	public function process_pre_order($order_id, $retry, $force_customer) {
146
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
147 147
 			try {
148
-				$order = wc_get_order( $order_id );
148
+				$order = wc_get_order($order_id);
149 149
 
150
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
151
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
150
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
151
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
152 152
 				}
153 153
 
154
-				$source = $this->get_source( get_current_user_id(), true );
154
+				$source = $this->get_source(get_current_user_id(), true);
155 155
 
156 156
 				// We need a source on file to continue.
157
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
158
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
157
+				if (empty($source->customer) || empty($source->source)) {
158
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
159 159
 				}
160 160
 
161 161
 				// Store source to order meta
162
-				$this->save_source( $order, $source );
162
+				$this->save_source($order, $source);
163 163
 
164 164
 				// Reduce stock levels
165 165
 				$order->reduce_order_stock();
@@ -168,19 +168,19 @@  discard block
 block discarded – undo
168 168
 				WC()->cart->empty_cart();
169 169
 
170 170
 				// Is pre ordered!
171
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
171
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
172 172
 
173 173
 				// Return thank you page redirect
174 174
 				return array(
175 175
 					'result'   => 'success',
176
-					'redirect' => $this->get_return_url( $order )
176
+					'redirect' => $this->get_return_url($order)
177 177
 				);
178
-			} catch ( Exception $e ) {
179
-				wc_add_notice( $e->getMessage(), 'error' );
178
+			} catch (Exception $e) {
179
+				wc_add_notice($e->getMessage(), 'error');
180 180
 				return;
181 181
 			}
182 182
 		} else {
183
-			return parent::process_payment( $order_id, $retry, $force_customer );
183
+			return parent::process_payment($order_id, $retry, $force_customer);
184 184
 		}
185 185
 	}
186 186
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @param WC_Order $order
190 190
 	 * @return void
191 191
 	 */
192
-	public function process_pre_order_release_payment( $order ) {
192
+	public function process_pre_order_release_payment($order) {
193 193
 		try {
194 194
 			// Define some callbacks if the first attempt fails.
195 195
 			$retry_callbacks = array(
@@ -197,33 +197,33 @@  discard block
 block discarded – undo
197 197
 				'remove_order_customer_before_retry',
198 198
 			);
199 199
 
200
-			while ( 1 ) {
201
-				$source   = $this->get_order_source( $order );
202
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
200
+			while (1) {
201
+				$source   = $this->get_order_source($order);
202
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
203 203
 
204
-				if ( is_wp_error( $response ) ) {
205
-					if ( 0 === sizeof( $retry_callbacks ) ) {
206
-						throw new Exception( $response->get_error_message() );
204
+				if (is_wp_error($response)) {
205
+					if (0 === sizeof($retry_callbacks)) {
206
+						throw new Exception($response->get_error_message());
207 207
 					} else {
208
-						$retry_callback = array_shift( $retry_callbacks );
209
-						call_user_func( array( $this, $retry_callback ), $order );
208
+						$retry_callback = array_shift($retry_callbacks);
209
+						call_user_func(array($this, $retry_callback), $order);
210 210
 					}
211 211
 				} else {
212 212
 					// Successful
213
-					$this->process_response( $response, $order );
213
+					$this->process_response($response, $order);
214 214
 					break;
215 215
 				}
216 216
 			}
217 217
 
218
-		} catch ( Exception $e ) {
219
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
218
+		} catch (Exception $e) {
219
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
220 220
 
221 221
 			// Mark order as failed if not already set,
222 222
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
223
-			if ( ! $order->has_status( 'failed' ) ) {
224
-				$order->update_status( 'failed', $order_note );
223
+			if ( ! $order->has_status('failed')) {
224
+				$order->update_status('failed', $order_note);
225 225
 			} else {
226
-				$order->add_order_note( $order_note );
226
+				$order->add_order_note($order_note);
227 227
 			}
228 228
 		}
229 229
 	}
@@ -232,20 +232,20 @@  discard block
 block discarded – undo
232 232
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
233 233
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
234 234
 	 */
235
-	public function delete_resubscribe_meta( $resubscribe_order ) {
236
-		delete_post_meta( $resubscribe_order->id, '_stripe_customer_id' );
237
-		delete_post_meta( $resubscribe_order->id, '_stripe_card_id' );
238
-		$this->delete_renewal_meta( $resubscribe_order );
235
+	public function delete_resubscribe_meta($resubscribe_order) {
236
+		delete_post_meta($resubscribe_order->id, '_stripe_customer_id');
237
+		delete_post_meta($resubscribe_order->id, '_stripe_card_id');
238
+		$this->delete_renewal_meta($resubscribe_order);
239 239
 	}
240 240
 
241 241
 	/**
242 242
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
243 243
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
244 244
 	 */
245
-	public function delete_renewal_meta( $renewal_order ) {
246
-		delete_post_meta( $renewal_order->id, 'Stripe Fee' );
247
-		delete_post_meta( $renewal_order->id, 'Net Revenue From Stripe' );
248
-		delete_post_meta( $renewal_order->id, 'Stripe Payment ID' );
245
+	public function delete_renewal_meta($renewal_order) {
246
+		delete_post_meta($renewal_order->id, 'Stripe Fee');
247
+		delete_post_meta($renewal_order->id, 'Net Revenue From Stripe');
248
+		delete_post_meta($renewal_order->id, 'Stripe Payment ID');
249 249
 		return $renewal_order;
250 250
 	}
251 251
 
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
 	 * @param $amount_to_charge float The amount to charge.
256 256
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
257 257
 	 */
258
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
259
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
258
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
259
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
260 260
 
261
-		if ( is_wp_error( $response ) ) {
262
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
261
+		if (is_wp_error($response)) {
262
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
263 263
 		}
264 264
 	}
265 265
 
@@ -267,16 +267,16 @@  discard block
 block discarded – undo
267 267
 	 * Remove order meta
268 268
 	 * @param  object $order
269 269
 	 */
270
-	public function remove_order_source_before_retry( $order ) {
271
-		delete_post_meta( $order->id, '_stripe_card_id' );
270
+	public function remove_order_source_before_retry($order) {
271
+		delete_post_meta($order->id, '_stripe_card_id');
272 272
 	}
273 273
 
274 274
 	/**
275 275
 	 * Remove order meta
276 276
 	 * @param  object $order
277 277
 	 */
278
-	public function remove_order_customer_before_retry( $order ) {
279
-		delete_post_meta( $order->id, '_stripe_customer_id' );
278
+	public function remove_order_customer_before_retry($order) {
279
+		delete_post_meta($order->id, '_stripe_customer_id');
280 280
 	}
281 281
 
282 282
 	/**
@@ -288,9 +288,9 @@  discard block
 block discarded – undo
288 288
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
289 289
 	 * @return void
290 290
 	 */
291
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
292
-		update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
293
-		update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id );
291
+	public function update_failing_payment_method($subscription, $renewal_order) {
292
+		update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
293
+		update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id);
294 294
 	}
295 295
 
296 296
 	/**
@@ -302,15 +302,15 @@  discard block
 block discarded – undo
302 302
 	 * @param WC_Subscription $subscription An instance of a subscription object
303 303
 	 * @return array
304 304
 	 */
305
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
306
-		$payment_meta[ $this->id ] = array(
305
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
306
+		$payment_meta[$this->id] = array(
307 307
 			'post_meta' => array(
308 308
 				'_stripe_customer_id' => array(
309
-					'value' => get_post_meta( $subscription->id, '_stripe_customer_id', true ),
309
+					'value' => get_post_meta($subscription->id, '_stripe_customer_id', true),
310 310
 					'label' => 'Stripe Customer ID',
311 311
 				),
312 312
 				'_stripe_card_id' => array(
313
-					'value' => get_post_meta( $subscription->id, '_stripe_card_id', true ),
313
+					'value' => get_post_meta($subscription->id, '_stripe_card_id', true),
314 314
 					'label' => 'Stripe Card ID',
315 315
 				),
316 316
 			),
@@ -327,17 +327,17 @@  discard block
 block discarded – undo
327 327
 	 * @param array $payment_meta associative array of meta data required for automatic payments
328 328
 	 * @return array
329 329
 	 */
330
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
331
-		if ( $this->id === $payment_method_id ) {
330
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
331
+		if ($this->id === $payment_method_id) {
332 332
 
333
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
334
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
335
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
336
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
333
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
334
+				throw new Exception('A "_stripe_customer_id" value is required.');
335
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
336
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
337 337
 			}
338 338
 
339
-			if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) {
340
-				throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' );
339
+			if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) {
340
+				throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".');
341 341
 			}
342 342
 		}
343 343
 	}
@@ -350,43 +350,43 @@  discard block
 block discarded – undo
350 350
 	 * @param WC_Subscription $subscription the subscription details
351 351
 	 * @return string the subscription payment method
352 352
 	 */
353
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
353
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
354 354
 		// bail for other payment methods
355
-		if ( $this->id !== $subscription->payment_method || ! $subscription->customer_user ) {
355
+		if ($this->id !== $subscription->payment_method || ! $subscription->customer_user) {
356 356
 			return $payment_method_to_display;
357 357
 		}
358 358
 
359 359
 		$stripe_customer    = new WC_Stripe_Customer();
360
-		$stripe_customer_id = get_post_meta( $subscription->id, '_stripe_customer_id', true );
361
-		$stripe_card_id     = get_post_meta( $subscription->id, '_stripe_card_id', true );
360
+		$stripe_customer_id = get_post_meta($subscription->id, '_stripe_customer_id', true);
361
+		$stripe_card_id     = get_post_meta($subscription->id, '_stripe_card_id', true);
362 362
 
363 363
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
364
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
364
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
365 365
 			$user_id            = $subscription->customer_user;
366
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
367
-			$stripe_card_id     = get_user_meta( $user_id, '_stripe_card_id', true );
366
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
367
+			$stripe_card_id     = get_user_meta($user_id, '_stripe_card_id', true);
368 368
 		}
369 369
 
370 370
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
371
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
372
-			$stripe_customer_id = get_post_meta( $subscription->order->id, '_stripe_customer_id', true );
373
-			$stripe_card_id     = get_post_meta( $subscription->order->id, '_stripe_card_id', true );
371
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
372
+			$stripe_customer_id = get_post_meta($subscription->order->id, '_stripe_customer_id', true);
373
+			$stripe_card_id     = get_post_meta($subscription->order->id, '_stripe_card_id', true);
374 374
 		}
375 375
 
376
-		$stripe_customer->set_id( $stripe_customer_id );
376
+		$stripe_customer->set_id($stripe_customer_id);
377 377
 		$cards = $stripe_customer->get_cards();
378 378
 
379
-		if ( $cards ) {
379
+		if ($cards) {
380 380
 			$found_card = false;
381
-			foreach ( $cards as $card ) {
382
-				if ( $card->id === $stripe_card_id ) {
381
+			foreach ($cards as $card) {
382
+				if ($card->id === $stripe_card_id) {
383 383
 					$found_card                = true;
384
-					$payment_method_to_display = sprintf( __( 'Via %s card ending in %s', 'woocommerce-gateway-stripe' ), ( isset( $card->type ) ? $card->type : $card->brand ), $card->last4 );
384
+					$payment_method_to_display = sprintf(__('Via %s card ending in %s', 'woocommerce-gateway-stripe'), (isset($card->type) ? $card->type : $card->brand), $card->last4);
385 385
 					break;
386 386
 				}
387 387
 			}
388
-			if ( ! $found_card ) {
389
-				$payment_method_to_display = sprintf( __( 'Via %s card ending in %s', 'woocommerce-gateway-stripe' ), ( isset( $cards[0]->type ) ? $cards[0]->type : $cards[0]->brand ), $cards[0]->last4 );
388
+			if ( ! $found_card) {
389
+				$payment_method_to_display = sprintf(__('Via %s card ending in %s', 'woocommerce-gateway-stripe'), (isset($cards[0]->type) ? $cards[0]->type : $cards[0]->brand), $cards[0]->last4);
390 390
 			}
391 391
 		}
392 392
 
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@
 block discarded – undo
177 177
 	 * @param float  $total Amount due.
178 178
 	 * @param string $currency Accepted currency.
179 179
 	 *
180
-	 * @return float|int
180
+	 * @return double
181 181
 	 */
182 182
 	public function get_stripe_amount( $total, $currency = '' ) {
183 183
 		if ( ! $currency ) {
Please login to merge, or discard this patch.
Spacing   +216 added lines, -216 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
 
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function __construct() {
101 101
 		$this->id                   = 'stripe';
102
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
103
-		$this->method_description   = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' );
102
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
103
+		$this->method_description   = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe');
104 104
 		$this->has_fields           = true;
105 105
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
106 106
 		$this->supports             = array(
@@ -128,37 +128,37 @@  discard block
 block discarded – undo
128 128
 		$this->init_settings();
129 129
 
130 130
 		// Get setting values.
131
-		$this->title                  = $this->get_option( 'title' );
132
-		$this->description            = $this->get_option( 'description' );
133
-		$this->enabled                = $this->get_option( 'enabled' );
134
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
135
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
136
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
137
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
138
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
139
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
140
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
141
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
142
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
143
-		$this->apple_pay              = 'yes' === $this->get_option( 'apple_pay' );
144
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
145
-		$this->allow_remember_me      = 'yes' === $this->get_option( 'allow_remember_me', 'no' );
131
+		$this->title                  = $this->get_option('title');
132
+		$this->description            = $this->get_option('description');
133
+		$this->enabled                = $this->get_option('enabled');
134
+		$this->testmode               = 'yes' === $this->get_option('testmode');
135
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
136
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
137
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
138
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
139
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
140
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
141
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
142
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
143
+		$this->apple_pay              = 'yes' === $this->get_option('apple_pay');
144
+		$this->logging                = 'yes' === $this->get_option('logging');
145
+		$this->allow_remember_me      = 'yes' === $this->get_option('allow_remember_me', 'no');
146 146
 
147
-		if ( $this->stripe_checkout ) {
148
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
147
+		if ($this->stripe_checkout) {
148
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
149 149
 		}
150 150
 
151
-		if ( $this->testmode ) {
152
-			$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
153
-			$this->description  = trim( $this->description );
151
+		if ($this->testmode) {
152
+			$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
153
+			$this->description  = trim($this->description);
154 154
 		}
155 155
 
156
-		WC_Stripe_API::set_secret_key( $this->secret_key );
156
+		WC_Stripe_API::set_secret_key($this->secret_key);
157 157
 
158 158
 		// Hooks.
159
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
160
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
161
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
159
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
160
+		add_action('admin_notices', array($this, 'admin_notices'));
161
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
162 162
 	}
163 163
 
164 164
 	/**
@@ -168,24 +168,24 @@  discard block
 block discarded – undo
168 168
 	 * @return string
169 169
 	 */
170 170
 	public function get_icon() {
171
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
172
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
171
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
172
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
173 173
 
174
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
175
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
176
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
174
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
175
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
176
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
177 177
 
178
-		if ( 'USD' === get_woocommerce_currency() ) {
179
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
180
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
181
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
178
+		if ('USD' === get_woocommerce_currency()) {
179
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
180
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
181
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
182 182
 		}
183 183
 
184
-		if ( $this->bitcoin && $this->stripe_checkout ) {
185
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
184
+		if ($this->bitcoin && $this->stripe_checkout) {
185
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
186 186
 		}
187 187
 
188
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
188
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
189 189
 	}
190 190
 
191 191
 	/**
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 	 *
197 197
 	 * @return float|int
198 198
 	 */
199
-	public function get_stripe_amount( $total, $currency = '' ) {
200
-		if ( ! $currency ) {
199
+	public function get_stripe_amount($total, $currency = '') {
200
+		if ( ! $currency) {
201 201
 			$currency = get_woocommerce_currency();
202 202
 		}
203
-		switch ( strtoupper( $currency ) ) {
203
+		switch (strtoupper($currency)) {
204 204
 			// Zero decimal currencies.
205 205
 			case 'BIF' :
206 206
 			case 'CLP' :
@@ -217,10 +217,10 @@  discard block
 block discarded – undo
217 217
 			case 'XAF' :
218 218
 			case 'XOF' :
219 219
 			case 'XPF' :
220
-				$total = absint( $total );
220
+				$total = absint($total);
221 221
 				break;
222 222
 			default :
223
-				$total = round( $total, 2 ) * 100; // In cents.
223
+				$total = round($total, 2) * 100; // In cents.
224 224
 				break;
225 225
 		}
226 226
 		return $total;
@@ -230,13 +230,13 @@  discard block
 block discarded – undo
230 230
 	 * Check if SSL is enabled and notify the user
231 231
 	 */
232 232
 	public function admin_notices() {
233
-		if ( 'no' === $this->enabled ) {
233
+		if ('no' === $this->enabled) {
234 234
 			return;
235 235
 		}
236 236
 
237 237
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
238
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
239
-			echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>';
238
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
239
+			echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>';
240 240
 		}
241 241
 	}
242 242
 
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
 	 * Check if this gateway is enabled
245 245
 	 */
246 246
 	public function is_available() {
247
-		if ( 'yes' === $this->enabled ) {
248
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
247
+		if ('yes' === $this->enabled) {
248
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
249 249
 				return false;
250 250
 			}
251
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
251
+			if ( ! $this->secret_key || ! $this->publishable_key) {
252 252
 				return false;
253 253
 			}
254 254
 			return true;
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	 * Initialise Gateway Settings Form Fields
261 261
 	 */
262 262
 	public function init_form_fields() {
263
-		$this->form_fields = include( 'settings-stripe.php' );
263
+		$this->form_fields = include('settings-stripe.php');
264 264
 
265
-		wc_enqueue_js( "
265
+		wc_enqueue_js("
266 266
 			jQuery( function( $ ) {
267 267
 				$( document.body ).on( 'change', '#woocommerce_stripe_testmode', function() {
268 268
 					var test_secret_key = $( '#woocommerce_stripe_test_secret_key' ).parents( 'tr' ).eq( 0 ),
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 					var value = $( this ).val();
300 300
 
301 301
 					if ( value.indexOf( '_test_' ) >= 0 ) {
302
-						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ) . "</span>' );
302
+						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe') . "</span>' );
303 303
 					} else {
304 304
 						$( this ).css( 'border-color', '' );
305 305
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 					var value = $( this ).val();
311 311
 
312 312
 					if ( value.indexOf( '_live_' ) >= 0 ) {
313
-						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ) . "</span>' );
313
+						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe') . "</span>' );
314 314
 					} else {
315 315
 						$( this ).css( 'border-color', '' );
316 316
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -325,54 +325,54 @@  discard block
 block discarded – undo
325 325
 	 */
326 326
 	public function payment_fields() {
327 327
 		$user                 = wp_get_current_user();
328
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
328
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
329 329
 		$total                = WC()->cart->total;
330 330
 
331 331
 		// If paying from order, we need to get total from order not cart.
332
-		if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) {
333
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
332
+		if (isset($_GET['pay_for_order']) && isset($_GET['key'])) {
333
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
334 334
 			$total = $order->get_total();
335 335
 		}
336 336
 
337
-		if ( $user->ID ) {
338
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
337
+		if ($user->ID) {
338
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
339 339
 			$user_email = $user_email ? $user_email : $user->user_email;
340 340
 		} else {
341 341
 			$user_email = '';
342 342
 		}
343 343
 
344
-		if ( is_add_payment_method_page() ) {
345
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
344
+		if (is_add_payment_method_page()) {
345
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
346 346
 		} else {
347 347
 			$pay_button_text = '';
348 348
 		}
349 349
 
350 350
 		echo '<div
351 351
 			id="stripe-payment-data"
352
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
352
+			data-panel-label="' . esc_attr($pay_button_text) . '"
353 353
 			data-description=""
354
-			data-email="' . esc_attr( $user_email ) . '"
355
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
356
-			data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '"
357
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
358
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
359
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
360
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
361
-			data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">';
354
+			data-email="' . esc_attr($user_email) . '"
355
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
356
+			data-name="' . esc_attr(get_bloginfo('name', 'display')) . '"
357
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
358
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
359
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
360
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
361
+			data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">';
362 362
 
363
-		if ( $this->description ) {
364
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
363
+		if ($this->description) {
364
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
365 365
 		}
366 366
 
367
-		if ( $display_tokenization ) {
367
+		if ($display_tokenization) {
368 368
 			$this->tokenization_script();
369 369
 			$this->saved_payment_methods();
370 370
 		}
371 371
 
372
-		if ( ! $this->stripe_checkout ) {
372
+		if ( ! $this->stripe_checkout) {
373 373
 			$this->form();
374 374
 
375
-			if ( $display_tokenization ) {
375
+			if ($display_tokenization) {
376 376
 				$this->save_payment_method_checkbox();
377 377
 			}
378 378
 		}
@@ -388,20 +388,20 @@  discard block
 block discarded – undo
388 388
 	 * @return array
389 389
 	 */
390 390
 	public function get_localized_messages() {
391
-		return apply_filters( 'wc_stripe_localized_messages', array(
392
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
393
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
394
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
395
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
396
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
397
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
398
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
399
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
400
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
401
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
402
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
403
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
404
-			) );
391
+		return apply_filters('wc_stripe_localized_messages', array(
392
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
393
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
394
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
395
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
396
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
397
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
398
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
399
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
400
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
401
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
402
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
403
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
404
+			));
405 405
 	}
406 406
 
407 407
 	/**
@@ -412,30 +412,30 @@  discard block
 block discarded – undo
412 412
 	 * @access public
413 413
 	 */
414 414
 	public function payment_scripts() {
415
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
415
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
416 416
 			return;
417 417
 		}
418 418
 
419
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
419
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
420 420
 
421
-		if ( $this->stripe_checkout ) {
422
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
423
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
421
+		if ($this->stripe_checkout) {
422
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
423
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
424 424
 		} else {
425
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
426
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
425
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
426
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
427 427
 		}
428 428
 
429 429
 		$stripe_params = array(
430 430
 			'key'                  => $this->publishable_key,
431
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
432
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
431
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
432
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
433 433
 		);
434 434
 
435 435
 		// If we're on the pay page we need to pass stripe.js the address of the order.
436
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
437
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
438
-			$order    = wc_get_order( $order_id );
436
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
437
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
438
+			$order    = wc_get_order($order_id);
439 439
 
440 440
 			$stripe_params['billing_first_name'] = $order->billing_first_name;
441 441
 			$stripe_params['billing_last_name']  = $order->billing_last_name;
@@ -447,14 +447,14 @@  discard block
 block discarded – undo
447 447
 			$stripe_params['billing_country']    = $order->billing_country;
448 448
 		}
449 449
 
450
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
451
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
452
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
450
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
451
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
452
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
453 453
 
454 454
 		// merge localized messages to be use in JS
455
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
455
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
456 456
 
457
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
457
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
458 458
 	}
459 459
 
460 460
 	/**
@@ -463,24 +463,24 @@  discard block
 block discarded – undo
463 463
 	 * @param  object $source
464 464
 	 * @return array()
465 465
 	 */
466
-	protected function generate_payment_request( $order, $source ) {
466
+	protected function generate_payment_request($order, $source) {
467 467
 		$post_data                = array();
468
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
469
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
470
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
468
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
469
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
470
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
471 471
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
472 472
 
473
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
473
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
474 474
 			$post_data['receipt_email'] = $order->billing_email;
475 475
 		}
476 476
 
477
-		$post_data['expand[]']    = 'balance_transaction';
477
+		$post_data['expand[]'] = 'balance_transaction';
478 478
 
479
-		if ( $source->customer ) {
479
+		if ($source->customer) {
480 480
 			$post_data['customer'] = $source->customer;
481 481
 		}
482 482
 
483
-		if ( $source->source ) {
483
+		if ($source->source) {
484 484
 			$post_data['source'] = $source->source;
485 485
 		}
486 486
 		
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 		 * @param WC_Order $order
493 493
 		 * @param object $source
494 494
 		 */
495
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
495
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
496 496
 	}
497 497
 
498 498
 	/**
@@ -504,22 +504,22 @@  discard block
 block discarded – undo
504 504
 	 * @throws Exception When card was not added or for and invalid card.
505 505
 	 * @return object
506 506
 	 */
507
-	protected function get_source( $user_id, $force_customer = false ) {
508
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
507
+	protected function get_source($user_id, $force_customer = false) {
508
+		$stripe_customer = new WC_Stripe_Customer($user_id);
509 509
 		$stripe_source   = false;
510 510
 		$token_id        = false;
511 511
 
512 512
 		// New CC info was entered and we have a new token to process
513
-		if ( isset( $_POST['stripe_token'] ) ) {
514
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
515
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
513
+		if (isset($_POST['stripe_token'])) {
514
+			$stripe_token     = wc_clean($_POST['stripe_token']);
515
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
516 516
 
517 517
 			// This is true if the user wants to store the card to their account.
518
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
519
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
518
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
519
+				$stripe_source = $stripe_customer->add_card($stripe_token);
520 520
 
521
-				if ( is_wp_error( $stripe_source ) ) {
522
-					throw new Exception( $stripe_source->get_error_message() );
521
+				if (is_wp_error($stripe_source)) {
522
+					throw new Exception($stripe_source->get_error_message());
523 523
 				}
524 524
 
525 525
 			} else {
@@ -530,13 +530,13 @@  discard block
 block discarded – undo
530 530
 		}
531 531
 
532 532
 		// Use an existing token, and then process the payment
533
-		elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
534
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
535
-			$token    = WC_Payment_Tokens::get( $token_id );
533
+		elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
534
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
535
+			$token    = WC_Payment_Tokens::get($token_id);
536 536
 
537
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
538
-				WC()->session->set( 'refresh_totals', true );
539
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
537
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
538
+				WC()->session->set('refresh_totals', true);
539
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
540 540
 			}
541 541
 
542 542
 			$stripe_source = $token->get_token();
@@ -560,16 +560,16 @@  discard block
 block discarded – undo
560 560
 	 * @param object $order
561 561
 	 * @return object
562 562
 	 */
563
-	protected function get_order_source( $order = null ) {
563
+	protected function get_order_source($order = null) {
564 564
 		$stripe_customer = new WC_Stripe_Customer();
565 565
 		$stripe_source   = false;
566 566
 		$token_id        = false;
567 567
 
568
-		if ( $order ) {
569
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
570
-				$stripe_customer->set_id( $meta_value );
568
+		if ($order) {
569
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
570
+				$stripe_customer->set_id($meta_value);
571 571
 			}
572
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
572
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
573 573
 				$stripe_source = $meta_value;
574 574
 			}
575 575
 		}
@@ -592,50 +592,50 @@  discard block
 block discarded – undo
592 592
 	 *
593 593
 	 * @return array|void
594 594
 	 */
595
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
595
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
596 596
 		try {
597
-			$order  = wc_get_order( $order_id );
598
-			$source = $this->get_source( get_current_user_id(), $force_customer );
597
+			$order  = wc_get_order($order_id);
598
+			$source = $this->get_source(get_current_user_id(), $force_customer);
599 599
 
600
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
601
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
602
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
603
-				throw new Exception( $error_msg );
600
+			if (empty($source->source) && empty($source->customer)) {
601
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
602
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
603
+				throw new Exception($error_msg);
604 604
 			}
605 605
 
606 606
 			// Store source to order meta.
607
-			$this->save_source( $order, $source );
607
+			$this->save_source($order, $source);
608 608
 
609 609
 			// Handle payment.
610
-			if ( $order->get_total() > 0 ) {
610
+			if ($order->get_total() > 0) {
611 611
 
612
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
613
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
612
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
613
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
614 614
 				}
615 615
 
616
-				WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
616
+				WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
617 617
 
618 618
 				// Make the request.
619
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
619
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
620 620
 
621
-				if ( is_wp_error( $response ) ) {
621
+				if (is_wp_error($response)) {
622 622
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
623
-					if ( 'customer' === $response->get_error_code() && $retry ) {
624
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
625
-						return $this->process_payment( $order_id, false, $force_customer );
623
+					if ('customer' === $response->get_error_code() && $retry) {
624
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
625
+						return $this->process_payment($order_id, false, $force_customer);
626 626
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
627
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
628
-						$token = WC_Payment_Tokens::get( $source->token_id );
627
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
628
+						$token = WC_Payment_Tokens::get($source->token_id);
629 629
 						$token->delete();
630
-						throw new Exception( __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ) );
630
+						throw new Exception(__('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'));
631 631
 					}
632 632
 					$localized_messages = $this->get_localized_messages();
633 633
 
634
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
634
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
635 635
 				}
636 636
 
637 637
 				// Process valid response.
638
-				$this->process_response( $response, $order );
638
+				$this->process_response($response, $order);
639 639
 			} else {
640 640
 				$order->payment_complete();
641 641
 			}
@@ -643,23 +643,23 @@  discard block
 block discarded – undo
643 643
 			// Remove cart.
644 644
 			WC()->cart->empty_cart();
645 645
 
646
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
646
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
647 647
 
648 648
 			// Return thank you page redirect.
649 649
 			return array(
650 650
 				'result'   => 'success',
651
-				'redirect' => $this->get_return_url( $order )
651
+				'redirect' => $this->get_return_url($order)
652 652
 			);
653 653
 
654
-		} catch ( Exception $e ) {
655
-			wc_add_notice( $e->getMessage(), 'error' );
656
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
654
+		} catch (Exception $e) {
655
+			wc_add_notice($e->getMessage(), 'error');
656
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
657 657
 
658
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
659
-				$this->send_failed_order_email( $order_id );
658
+			if ($order->has_status(array('pending', 'failed'))) {
659
+				$this->send_failed_order_email($order_id);
660 660
 			}
661 661
 
662
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
662
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
663 663
 
664 664
 			return array(
665 665
 				'result'   => 'fail',
@@ -674,52 +674,52 @@  discard block
 block discarded – undo
674 674
 	 * @param WC_Order $order For to which the source applies.
675 675
 	 * @param stdClass $source Source information.
676 676
 	 */
677
-	protected function save_source( $order, $source ) {
677
+	protected function save_source($order, $source) {
678 678
 		// Store source in the order.
679
-		if ( $source->customer ) {
680
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
679
+		if ($source->customer) {
680
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
681 681
 		}
682
-		if ( $source->source ) {
683
-			update_post_meta( $order->id, '_stripe_card_id', $source->source );
682
+		if ($source->source) {
683
+			update_post_meta($order->id, '_stripe_card_id', $source->source);
684 684
 		}
685 685
 	}
686 686
 
687 687
 	/**
688 688
 	 * Store extra meta data for an order from a Stripe Response.
689 689
 	 */
690
-	public function process_response( $response, $order ) {
691
-		WC_Stripe::log( "Processing response: " . print_r( $response, true ) );
690
+	public function process_response($response, $order) {
691
+		WC_Stripe::log("Processing response: " . print_r($response, true));
692 692
 
693 693
 		// Store charge data
694
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
695
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
694
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
695
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
696 696
 
697 697
 		// Store other data such as fees
698
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
698
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
699 699
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
700 700
 			// values are in the local currency of the Stripe account, not from WC.
701
-			$fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0;
702
-			$net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0;
703
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
704
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
701
+			$fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0;
702
+			$net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0;
703
+			update_post_meta($order->id, 'Stripe Fee', $fee);
704
+			update_post_meta($order->id, 'Net Revenue From Stripe', $net);
705 705
 		}
706 706
 
707
-		if ( $response->captured ) {
708
-			$order->payment_complete( $response->id );
707
+		if ($response->captured) {
708
+			$order->payment_complete($response->id);
709 709
 
710
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
711
-			$order->add_order_note( $message );
712
-			WC_Stripe::log( 'Success: ' . $message );
710
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
711
+			$order->add_order_note($message);
712
+			WC_Stripe::log('Success: ' . $message);
713 713
 
714 714
 		} else {
715
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
715
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
716 716
 
717
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
717
+			if ($order->has_status(array('pending', 'failed'))) {
718 718
 				$order->reduce_order_stock();
719 719
 			}
720 720
 
721
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
722
-			WC_Stripe::log( "Successful auth: $response->id" );
721
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
722
+			WC_Stripe::log("Successful auth: $response->id");
723 723
 		}
724 724
 
725 725
 		return $response;
@@ -731,32 +731,32 @@  discard block
 block discarded – undo
731 731
 	 * @since 3.0.0
732 732
 	 */
733 733
 	public function add_payment_method() {
734
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
735
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
734
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
735
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
736 736
 			return;
737 737
 		}
738 738
 
739
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
740
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
739
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
740
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
741 741
 
742
-		if ( is_wp_error( $card ) ) {
742
+		if (is_wp_error($card)) {
743 743
 			$localized_messages = $this->get_localized_messages();
744
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
744
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
745 745
 
746 746
 			// loop through the errors to find matching localized message
747
-			foreach ( $card->errors as $error => $msg ) {
748
-				if ( isset( $localized_messages[ $error ] ) ) {
749
-					$error_msg = $localized_messages[ $error ];
747
+			foreach ($card->errors as $error => $msg) {
748
+				if (isset($localized_messages[$error])) {
749
+					$error_msg = $localized_messages[$error];
750 750
 				}
751 751
 			}
752 752
 
753
-			wc_add_notice( $error_msg, 'error' );
753
+			wc_add_notice($error_msg, 'error');
754 754
 			return;
755 755
 		}
756 756
 
757 757
 		return array(
758 758
 			'result'   => 'success',
759
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
759
+			'redirect' => wc_get_endpoint_url('payment-methods'),
760 760
 		);
761 761
 	}
762 762
 
@@ -766,36 +766,36 @@  discard block
 block discarded – undo
766 766
 	 * @param  float $amount
767 767
 	 * @return bool
768 768
 	 */
769
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
770
-		$order = wc_get_order( $order_id );
769
+	public function process_refund($order_id, $amount = null, $reason = '') {
770
+		$order = wc_get_order($order_id);
771 771
 
772
-		if ( ! $order || ! $order->get_transaction_id() ) {
772
+		if ( ! $order || ! $order->get_transaction_id()) {
773 773
 			return false;
774 774
 		}
775 775
 
776 776
 		$body = array();
777 777
 
778
-		if ( ! is_null( $amount ) ) {
779
-			$body['amount']	= $this->get_stripe_amount( $amount );
778
+		if ( ! is_null($amount)) {
779
+			$body['amount'] = $this->get_stripe_amount($amount);
780 780
 		}
781 781
 
782
-		if ( $reason ) {
782
+		if ($reason) {
783 783
 			$body['metadata'] = array(
784 784
 				'reason'	=> $reason,
785 785
 			);
786 786
 		}
787 787
 
788
-		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
788
+		WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}");
789 789
 
790
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
790
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
791 791
 
792
-		if ( is_wp_error( $response ) ) {
793
-			WC_Stripe::log( "Error: " . $response->get_error_message() );
792
+		if (is_wp_error($response)) {
793
+			WC_Stripe::log("Error: " . $response->get_error_message());
794 794
 			return $response;
795
-		} elseif ( ! empty( $response->id ) ) {
796
-			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
797
-			$order->add_order_note( $refund_message );
798
-			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
795
+		} elseif ( ! empty($response->id)) {
796
+			$refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
797
+			$order->add_order_note($refund_message);
798
+			WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message)));
799 799
 			return true;
800 800
 		}
801 801
 	}
@@ -808,10 +808,10 @@  discard block
 block discarded – undo
808 808
 	 * @param int $order_id
809 809
 	 * @return null
810 810
 	 */
811
-	public function send_failed_order_email( $order_id ) {
811
+	public function send_failed_order_email($order_id) {
812 812
 		$emails = WC()->mailer()->get_emails();
813
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
814
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
813
+		if ( ! empty($emails) && ! empty($order_id)) {
814
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
815 815
 		}
816 816
 	}
817 817
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,6 @@
 block discarded – undo
23 23
 
24 24
 	/**
25 25
 	 * Set secret API Key.
26
-	 * @param string $key
27 26
 	 */
28 27
 	public static function set_secret_key( $secret_key ) {
29 28
 		self::$secret_key = $secret_key;
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 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
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 * Set secret API Key.
26 26
 	 * @param string $key
27 27
 	 */
28
-	public static function set_secret_key( $secret_key ) {
28
+	public static function set_secret_key($secret_key) {
29 29
 		self::$secret_key = $secret_key;
30 30
 	}
31 31
 
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
 	 * @return string
35 35
 	 */
36 36
 	public static function get_secret_key() {
37
-		if ( ! self::$secret_key ) {
38
-			$options = get_option( 'woocommerce_stripe_settings' );
37
+		if ( ! self::$secret_key) {
38
+			$options = get_option('woocommerce_stripe_settings');
39 39
 
40
-			if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) {
41
-				self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] );
40
+			if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) {
41
+				self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']);
42 42
 			}
43 43
 		}
44 44
 		return self::$secret_key;
@@ -51,39 +51,39 @@  discard block
 block discarded – undo
51 51
 	 * @param string $api
52 52
 	 * @return array|WP_Error
53 53
 	 */
54
-	public static function request( $request, $api = 'charges', $method = 'POST' ) {
55
-		WC_Stripe::log( "{$api} request: " . print_r( $request, true ) );
54
+	public static function request($request, $api = 'charges', $method = 'POST') {
55
+		WC_Stripe::log("{$api} request: " . print_r($request, true));
56 56
 
57 57
 		$response = wp_safe_remote_post(
58 58
 			self::ENDPOINT . $api,
59 59
 			array(
60 60
 				'method'        => $method,
61 61
 				'headers'       => array(
62
-					'Authorization'  => 'Basic ' . base64_encode( self::get_secret_key(). ':' ),
62
+					'Authorization'  => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
63 63
 					'Stripe-Version' => '2016-03-07'
64 64
 				),
65
-				'body'       => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
65
+				'body'       => apply_filters('woocommerce_stripe_request_body', $request, $api),
66 66
 				'timeout'    => 70,
67 67
 				'user-agent' => 'WooCommerce ' . WC()->version
68 68
 			)
69 69
 		);
70 70
 
71
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
72
-			WC_Stripe::log( "Error Response: " . print_r( $response, true ) );
73
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe' ) );
71
+		if (is_wp_error($response) || empty($response['body'])) {
72
+			WC_Stripe::log("Error Response: " . print_r($response, true));
73
+			return new WP_Error('stripe_error', __('There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe'));
74 74
 		}
75 75
 
76
-		$parsed_response = json_decode( $response['body'] );
76
+		$parsed_response = json_decode($response['body']);
77 77
 		// Handle response
78
-		if ( ! empty( $parsed_response->error ) ) {
79
-			if ( ! empty( $parsed_response->error->param ) ) {
78
+		if ( ! empty($parsed_response->error)) {
79
+			if ( ! empty($parsed_response->error->param)) {
80 80
 				$code = $parsed_response->error->param;
81
-			} elseif ( ! empty( $parsed_response->error->code ) ) {
81
+			} elseif ( ! empty($parsed_response->error->code)) {
82 82
 				$code = $parsed_response->error->code;
83 83
 			} else {
84 84
 				$code = 'stripe_error';
85 85
 			}
86
-			return new WP_Error( $code, $parsed_response->error->message );
86
+			return new WP_Error($code, $parsed_response->error->message);
87 87
 		} else {
88 88
 			return $parsed_response;
89 89
 		}
Please login to merge, or discard this patch.
includes/class-wc-stripe-customer.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -210,7 +210,6 @@
 block discarded – undo
210 210
 	/**
211 211
 	 * Get a customers saved cards using their Stripe ID. Cached.
212 212
 	 *
213
-	 * @param  string $customer_id
214 213
 	 * @return array
215 214
 	 */
216 215
 	public function get_cards() {
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 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 integer $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,12 +90,12 @@  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
-		if ( empty( $this->customer_data ) && $this->get_id() && false === ( $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ) ) ) {
94
-			$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() );
93
+		if (empty($this->customer_data) && $this->get_id() && false === ($this->customer_data = get_transient('stripe_customer_' . $this->get_id()))) {
94
+			$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id());
95 95
 
96
-			if ( ! is_wp_error( $response ) ) {
97
-				$this->set_customer_data( $response );
98
-				set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 );
96
+			if ( ! is_wp_error($response)) {
97
+				$this->set_customer_data($response);
98
+				set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48);
99 99
 			}
100 100
 		}
101 101
 		return $this->customer_data;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		$data   = $this->get_customer_data();
110 110
 		$source = '';
111 111
 
112
-		if ( $data ) {
112
+		if ($data) {
113 113
 			$source = $data->default_source;
114 114
 		}
115 115
 
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
 	 * @param array $args
122 122
 	 * @return WP_Error|int
123 123
 	 */
124
-	public function create_customer( $args = array() ) {
125
-		if ( $user = $this->get_user() ) {
126
-			$billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true );
127
-			$billing_last_name  = get_user_meta( $user->ID, 'billing_last_name', true );
124
+	public function create_customer($args = array()) {
125
+		if ($user = $this->get_user()) {
126
+			$billing_first_name = get_user_meta($user->ID, 'billing_first_name', true);
127
+			$billing_last_name  = get_user_meta($user->ID, 'billing_last_name', true);
128 128
 
129 129
 			$defaults = array(
130 130
 				'email'       => $user->user_email,
@@ -137,24 +137,24 @@  discard block
 block discarded – undo
137 137
 			);
138 138
 		}
139 139
 
140
-		$args     = wp_parse_args( $args, $defaults );
141
-		$response = WC_Stripe_API::request( $args, 'customers' );
140
+		$args     = wp_parse_args($args, $defaults);
141
+		$response = WC_Stripe_API::request($args, 'customers');
142 142
 
143
-		if ( is_wp_error( $response ) ) {
143
+		if (is_wp_error($response)) {
144 144
 			return $response;
145
-		} elseif ( empty( $response->id ) ) {
146
-			return new WP_Error( 'stripe_error', __( 'Could not create Stripe customer.', 'woocommerce-gateway-stripe' ) );
145
+		} elseif (empty($response->id)) {
146
+			return new WP_Error('stripe_error', __('Could not create Stripe customer.', 'woocommerce-gateway-stripe'));
147 147
 		}
148 148
 
149
-		$this->set_id( $response->id );
149
+		$this->set_id($response->id);
150 150
 		$this->clear_cache();
151
-		$this->set_customer_data( $response );
151
+		$this->set_customer_data($response);
152 152
 
153
-		if ( $this->get_user_id() ) {
154
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id );
153
+		if ($this->get_user_id()) {
154
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id);
155 155
 		}
156 156
 
157
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
157
+		do_action('woocommerce_stripe_add_customer', $args, $response);
158 158
 
159 159
 		return $response->id;
160 160
 	}
@@ -165,44 +165,44 @@  discard block
 block discarded – undo
165 165
 	 * @param bool $retry
166 166
 	 * @return WP_Error|int
167 167
 	 */
168
-	public function add_card( $token, $retry = true ) {
169
-		if ( ! $this->get_id() ) {
170
-			if ( ( $response = $this->create_customer() ) && is_wp_error( $response ) ) {
168
+	public function add_card($token, $retry = true) {
169
+		if ( ! $this->get_id()) {
170
+			if (($response = $this->create_customer()) && is_wp_error($response)) {
171 171
 				return $response;
172 172
 			}
173 173
 		}
174 174
 
175
-		$response = WC_Stripe_API::request( array(
175
+		$response = WC_Stripe_API::request(array(
176 176
 			'source' => $token
177
-		), 'customers/' . $this->get_id() . '/sources' );
177
+		), 'customers/' . $this->get_id() . '/sources');
178 178
 
179
-		if ( is_wp_error( $response ) ) {
180
-			if ( 'customer' === $response->get_error_code() && $retry ) {
179
+		if (is_wp_error($response)) {
180
+			if ('customer' === $response->get_error_code() && $retry) {
181 181
 				$this->create_customer();
182
-				return $this->add_card( $token, false );
182
+				return $this->add_card($token, false);
183 183
 			} else {
184 184
 				return $response;
185 185
 			}
186
-		} elseif ( empty( $response->id ) ) {
187
-			return new WP_Error( 'error', __( 'Unable to add card', 'woocommerce-gateway-stripe' ) );
186
+		} elseif (empty($response->id)) {
187
+			return new WP_Error('error', __('Unable to add card', 'woocommerce-gateway-stripe'));
188 188
 		}
189 189
 
190 190
 		// Add token to WooCommerce
191
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
191
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
192 192
 			$token = new WC_Payment_Token_CC();
193
-			$token->set_token( $response->id );
194
-			$token->set_gateway_id( 'stripe' );
195
-			$token->set_card_type( strtolower( $response->brand ) );
196
-			$token->set_last4( $response->last4 );
197
-			$token->set_expiry_month( $response->exp_month  );
198
-			$token->set_expiry_year( $response->exp_year );
199
-			$token->set_user_id( $this->get_user_id() );
193
+			$token->set_token($response->id);
194
+			$token->set_gateway_id('stripe');
195
+			$token->set_card_type(strtolower($response->brand));
196
+			$token->set_last4($response->last4);
197
+			$token->set_expiry_month($response->exp_month);
198
+			$token->set_expiry_year($response->exp_year);
199
+			$token->set_user_id($this->get_user_id());
200 200
 			$token->save();
201 201
 		}
202 202
 
203 203
 		$this->clear_cache();
204 204
 
205
-		do_action( 'woocommerce_stripe_add_card', $this->get_id(), $token, $response );
205
+		do_action('woocommerce_stripe_add_card', $this->get_id(), $token, $response);
206 206
 
207 207
 		return $response->id;
208 208
 	}
@@ -216,20 +216,20 @@  discard block
 block discarded – undo
216 216
 	public function get_cards() {
217 217
 		$cards = array();
218 218
 
219
-		if ( $this->get_id() && false === ( $cards = get_transient( 'stripe_cards_' . $this->get_id() ) ) ) {
220
-			$response = WC_Stripe_API::request( array(
219
+		if ($this->get_id() && false === ($cards = get_transient('stripe_cards_' . $this->get_id()))) {
220
+			$response = WC_Stripe_API::request(array(
221 221
 				'limit'       => 100
222
-			), 'customers/' . $this->get_id() . '/sources', 'GET' );
222
+			), 'customers/' . $this->get_id() . '/sources', 'GET');
223 223
 
224
-			if ( is_wp_error( $response ) ) {
224
+			if (is_wp_error($response)) {
225 225
 				return array();
226 226
 			}
227 227
 
228
-			if ( is_array( $response->data ) ) {
228
+			if (is_array($response->data)) {
229 229
 				$cards = $response->data;
230 230
 			}
231 231
 
232
-			set_transient( 'stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48 );
232
+			set_transient('stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48);
233 233
 		}
234 234
 
235 235
 		return $cards;
@@ -239,13 +239,13 @@  discard block
 block discarded – undo
239 239
 	 * Delete a card from stripe.
240 240
 	 * @param string $card_id
241 241
 	 */
242
-	public function delete_card( $card_id ) {
243
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $card_id ), 'DELETE' );
242
+	public function delete_card($card_id) {
243
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($card_id), 'DELETE');
244 244
 
245 245
 		$this->clear_cache();
246 246
 
247
-		if ( ! is_wp_error( $response ) ) {
248
-			do_action( 'wc_stripe_delete_card', $this->get_id(), $response );
247
+		if ( ! is_wp_error($response)) {
248
+			do_action('wc_stripe_delete_card', $this->get_id(), $response);
249 249
 
250 250
 			return true;
251 251
 		}
@@ -257,15 +257,15 @@  discard block
 block discarded – undo
257 257
 	 * Set default card in Stripe
258 258
 	 * @param string $card_id
259 259
 	 */
260
-	public function set_default_card( $card_id ) {
261
-		$response = WC_Stripe_API::request( array(
262
-			'default_source' => sanitize_text_field( $card_id ),
263
-		), 'customers/' . $this->get_id(), 'POST' );
260
+	public function set_default_card($card_id) {
261
+		$response = WC_Stripe_API::request(array(
262
+			'default_source' => sanitize_text_field($card_id),
263
+		), 'customers/' . $this->get_id(), 'POST');
264 264
 
265 265
 		$this->clear_cache();
266 266
 
267
-		if ( ! is_wp_error( $response ) ) {
268
-			do_action( 'wc_stripe_set_default_card', $this->get_id(), $response );
267
+		if ( ! is_wp_error($response)) {
268
+			do_action('wc_stripe_set_default_card', $this->get_id(), $response);
269 269
 
270 270
 			return true;
271 271
 		}
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	 * Deletes caches for this users cards.
278 278
 	 */
279 279
 	public function clear_cache() {
280
-		delete_transient( 'stripe_cards_' . $this->get_id() );
281
-		delete_transient( 'stripe_customer_' . $this->get_id() );
280
+		delete_transient('stripe_cards_' . $this->get_id());
281
+		delete_transient('stripe_customer_' . $this->get_id());
282 282
 		$this->customer_data = array();
283 283
 	}
284 284
 }
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 2 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -139,6 +139,8 @@
 block discarded – undo
139 139
 
140 140
 	/**
141 141
 	 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
142
+	 * @param string $slug
143
+	 * @param string $class
142 144
 	 */
143 145
 	public function add_admin_notice( $slug, $class, $message ) {
144 146
 		$this->notices[ $slug ] = array(
Please login to merge, or discard this patch.
Spacing   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -25,20 +25,20 @@  discard block
 block discarded – undo
25 25
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 26
 */
27 27
 
28
-if ( ! defined( 'ABSPATH' ) ) {
28
+if ( ! defined('ABSPATH')) {
29 29
 	exit;
30 30
 }
31 31
 
32 32
 /**
33 33
  * Required minimums and constants
34 34
  */
35
-define( 'WC_STRIPE_VERSION', '3.0.6' );
36
-define( 'WC_STRIPE_MIN_PHP_VER', '5.3.0' );
37
-define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' );
38
-define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
39
-define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
35
+define('WC_STRIPE_VERSION', '3.0.6');
36
+define('WC_STRIPE_MIN_PHP_VER', '5.3.0');
37
+define('WC_STRIPE_MIN_WC_VER', '2.5.0');
38
+define('WC_STRIPE_MAIN_FILE', __FILE__);
39
+define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
40 40
 
41
-if ( ! class_exists( 'WC_Stripe' ) ) :
41
+if ( ! class_exists('WC_Stripe')) :
42 42
 
43 43
 class WC_Stripe {
44 44
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 * @return Singleton The *Singleton* instance.
59 59
 	 */
60 60
 	public static function get_instance() {
61
-		if ( null === self::$instance ) {
61
+		if (null === self::$instance) {
62 62
 			self::$instance = new self();
63 63
 		}
64 64
 		return self::$instance;
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 	 * *Singleton* via the `new` operator from outside of this class.
108 108
 	 */
109 109
 	protected function __construct() {
110
-		add_action( 'admin_init', array( $this, 'check_environment' ) );
111
-		add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
112
-		add_action( 'plugins_loaded', array( $this, 'init' ) );
110
+		add_action('admin_init', array($this, 'check_environment'));
111
+		add_action('admin_notices', array($this, 'admin_notices'), 15);
112
+		add_action('plugins_loaded', array($this, 'init'));
113 113
 	}
114 114
 
115 115
 	/**
@@ -117,33 +117,33 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function init() {
119 119
 		// Don't hook anything else in the plugin if we're in an incompatible environment
120
-		if ( self::get_environment_warning() ) {
120
+		if (self::get_environment_warning()) {
121 121
 			return;
122 122
 		}
123 123
 
124
-		include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
125
-		include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
124
+		include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
125
+		include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
126 126
 
127 127
 		// Init the gateway itself
128 128
 		$this->init_gateways();
129 129
 
130
-		add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
131
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
132
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
133
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
134
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
135
-		add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
136
-		add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
137
-		add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );
130
+		add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
131
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
132
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
133
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
134
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
135
+		add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
136
+		add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
137
+		add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));
138 138
 
139
-		include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' );
139
+		include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php');
140 140
 	}
141 141
 
142 142
 	/**
143 143
 	 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
144 144
 	 */
145
-	public function add_admin_notice( $slug, $class, $message ) {
146
-		$this->notices[ $slug ] = array(
145
+	public function add_admin_notice($slug, $class, $message) {
146
+		$this->notices[$slug] = array(
147 147
 			'class'   => $class,
148 148
 			'message' => $message
149 149
 		);
@@ -156,21 +156,21 @@  discard block
 block discarded – undo
156 156
 	public function check_environment() {
157 157
 		$environment_warning = self::get_environment_warning();
158 158
 
159
-		if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
160
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
159
+		if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
160
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
161 161
 		}
162 162
 
163 163
 		// Check if secret key present. Otherwise prompt, via notice, to go to
164 164
 		// setting.
165
-		if ( ! class_exists( 'WC_Stripe_API' ) ) {
166
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
165
+		if ( ! class_exists('WC_Stripe_API')) {
166
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
167 167
 		}
168 168
 
169 169
 		$secret = WC_Stripe_API::get_secret_key();
170 170
 
171
-		if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
171
+		if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
172 172
 			$setting_link = $this->get_setting_link();
173
-			$this->add_admin_notice( 'prompt_connect', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ) );
173
+			$this->add_admin_notice('prompt_connect', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link));
174 174
 		}
175 175
 	}
176 176
 
@@ -179,24 +179,24 @@  discard block
 block discarded – undo
179 179
 	 * found or false if the environment has no problems.
180 180
 	 */
181 181
 	static function get_environment_warning() {
182
-		if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
183
-			$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' );
182
+		if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
183
+			$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe');
184 184
 
185
-			return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
185
+			return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
186 186
 		}
187 187
 
188
-		if ( ! defined( 'WC_VERSION' ) ) {
189
-			return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
188
+		if ( ! defined('WC_VERSION')) {
189
+			return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
190 190
 		}
191 191
 
192
-		if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
193
-			$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' );
192
+		if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
193
+			$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe');
194 194
 
195
-			return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
195
+			return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
196 196
 		}
197 197
 
198
-		if ( ! function_exists( 'curl_init' ) ) {
199
-			return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
198
+		if ( ! function_exists('curl_init')) {
199
+			return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
200 200
 		}
201 201
 
202 202
 		return false;
@@ -207,15 +207,15 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 * @since 1.0.0
209 209
 	 */
210
-	public function plugin_action_links( $links ) {
210
+	public function plugin_action_links($links) {
211 211
 		$setting_link = $this->get_setting_link();
212 212
 
213 213
 		$plugin_links = array(
214
-			'<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
215
-			'<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
216
-			'<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
214
+			'<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>',
215
+			'<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>',
216
+			'<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>',
217 217
 		);
218
-		return array_merge( $plugin_links, $links );
218
+		return array_merge($plugin_links, $links);
219 219
 	}
220 220
 
221 221
 	/**
@@ -226,20 +226,20 @@  discard block
 block discarded – undo
226 226
 	 * @return string Setting link
227 227
 	 */
228 228
 	public function get_setting_link() {
229
-		$use_id_as_section = version_compare( WC()->version, '2.6', '>=' );
229
+		$use_id_as_section = version_compare(WC()->version, '2.6', '>=');
230 230
 
231
-		$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
231
+		$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
232 232
 
233
-		return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
233
+		return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
234 234
 	}
235 235
 
236 236
 	/**
237 237
 	 * Display any notices we've collected thus far (e.g. for connection, disconnection)
238 238
 	 */
239 239
 	public function admin_notices() {
240
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
241
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
242
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
240
+		foreach ((array) $this->notices as $notice_key => $notice) {
241
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
242
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
243 243
 			echo "</p></div>";
244 244
 		}
245 245
 	}
@@ -250,28 +250,28 @@  discard block
 block discarded – undo
250 250
 	 * @since 1.0.0
251 251
 	 */
252 252
 	public function init_gateways() {
253
-		if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
253
+		if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
254 254
 			$this->subscription_support_enabled = true;
255 255
 		}
256 256
 
257
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
257
+		if (class_exists('WC_Pre_Orders_Order')) {
258 258
 			$this->pre_order_enabled = true;
259 259
 		}
260 260
 
261
-		if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
261
+		if ( ! class_exists('WC_Payment_Gateway')) {
262 262
 			return;
263 263
 		}
264 264
 
265
-		if ( class_exists( 'WC_Payment_Gateway_CC' ) ) {
266
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
267
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' );
265
+		if (class_exists('WC_Payment_Gateway_CC')) {
266
+			include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
267
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php');
268 268
 		} else {
269
-			include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' );
270
-			include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' );
269
+			include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php');
270
+			include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php');
271 271
 		}
272 272
 
273
-		load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
274
-		add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
273
+		load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
274
+		add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
275 275
 
276 276
 		$load_addons = (
277 277
 			$this->subscription_support_enabled
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 			$this->pre_order_enabled
280 280
 		);
281 281
 
282
-		if ( $load_addons ) {
283
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' );
282
+		if ($load_addons) {
283
+			require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php');
284 284
 		}
285 285
 	}
286 286
 
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 	 *
290 290
 	 * @since 1.0.0
291 291
 	 */
292
-	public function add_gateways( $methods ) {
293
-		if ( $this->subscription_support_enabled || $this->pre_order_enabled ) {
292
+	public function add_gateways($methods) {
293
+		if ($this->subscription_support_enabled || $this->pre_order_enabled) {
294 294
 			$methods[] = 'WC_Gateway_Stripe_Addons';
295 295
 		} else {
296 296
 			$methods[] = 'WC_Gateway_Stripe';
@@ -303,35 +303,35 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param  int $order_id
305 305
 	 */
306
-	public function capture_payment( $order_id ) {
307
-		$order = wc_get_order( $order_id );
306
+	public function capture_payment($order_id) {
307
+		$order = wc_get_order($order_id);
308 308
 
309
-		if ( 'stripe' === $order->payment_method ) {
310
-			$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
311
-			$captured = get_post_meta( $order_id, '_stripe_charge_captured', true );
309
+		if ('stripe' === $order->payment_method) {
310
+			$charge   = get_post_meta($order_id, '_stripe_charge_id', true);
311
+			$captured = get_post_meta($order_id, '_stripe_charge_captured', true);
312 312
 
313
-			if ( $charge && 'no' === $captured ) {
314
-				$result = WC_Stripe_API::request( array(
313
+			if ($charge && 'no' === $captured) {
314
+				$result = WC_Stripe_API::request(array(
315 315
 					'amount'   => $order->get_total() * 100,
316 316
 					'expand[]' => 'balance_transaction'
317
-				), 'charges/' . $charge . '/capture' );
317
+				), 'charges/' . $charge . '/capture');
318 318
 
319
-				if ( is_wp_error( $result ) ) {
320
-					$order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
319
+				if (is_wp_error($result)) {
320
+					$order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
321 321
 				} else {
322
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
323
-					update_post_meta( $order->id, '_stripe_charge_captured', 'yes' );
322
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
323
+					update_post_meta($order->id, '_stripe_charge_captured', 'yes');
324 324
 
325 325
 					// Store other data such as fees
326
-					update_post_meta( $order->id, 'Stripe Payment ID', $result->id );
326
+					update_post_meta($order->id, 'Stripe Payment ID', $result->id);
327 327
 
328
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
328
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
329 329
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
330 330
 						// values are in the local currency of the Stripe account, not from WC.
331
-						$fee = ! empty( $result->balance_transaction->fee ) ? number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) : 0;
332
-						$net = ! empty( $result->balance_transaction->net ) ? number_format( $result->balance_transaction->net / 100, 2, '.', '' ) : 0;
333
-						update_post_meta( $order->id, 'Stripe Fee', $fee );
334
-						update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
331
+						$fee = ! empty($result->balance_transaction->fee) ? number_format($result->balance_transaction->fee / 100, 2, '.', '') : 0;
332
+						$net = ! empty($result->balance_transaction->net) ? number_format($result->balance_transaction->net / 100, 2, '.', '') : 0;
333
+						update_post_meta($order->id, 'Stripe Fee', $fee);
334
+						update_post_meta($order->id, 'Net Revenue From Stripe', $net);
335 335
 					}
336 336
 				}
337 337
 			}
@@ -343,23 +343,23 @@  discard block
 block discarded – undo
343 343
 	 *
344 344
 	 * @param  int $order_id
345 345
 	 */
346
-	public function cancel_payment( $order_id ) {
347
-		$order = wc_get_order( $order_id );
346
+	public function cancel_payment($order_id) {
347
+		$order = wc_get_order($order_id);
348 348
 
349
-		if ( 'stripe' === $order->payment_method ) {
350
-			$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
349
+		if ('stripe' === $order->payment_method) {
350
+			$charge = get_post_meta($order_id, '_stripe_charge_id', true);
351 351
 
352
-			if ( $charge ) {
353
-				$result = WC_Stripe_API::request( array(
352
+			if ($charge) {
353
+				$result = WC_Stripe_API::request(array(
354 354
 					'amount' => $order->get_total() * 100,
355
-				), 'charges/' . $charge . '/refund' );
355
+				), 'charges/' . $charge . '/refund');
356 356
 
357
-				if ( is_wp_error( $result ) ) {
358
-					$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
357
+				if (is_wp_error($result)) {
358
+					$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
359 359
 				} else {
360
-					$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
361
-					delete_post_meta( $order->id, '_stripe_charge_captured' );
362
-					delete_post_meta( $order->id, '_stripe_charge_id' );
360
+					$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
361
+					delete_post_meta($order->id, '_stripe_charge_captured');
362
+					delete_post_meta($order->id, '_stripe_charge_id');
363 363
 				}
364 364
 			}
365 365
 		}
@@ -370,28 +370,28 @@  discard block
 block discarded – undo
370 370
 	 * @param array $tokens
371 371
 	 * @return array
372 372
 	 */
373
-	public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) {
374
-		if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) {
375
-			$stripe_customer = new WC_Stripe_Customer( $customer_id );
373
+	public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) {
374
+		if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) {
375
+			$stripe_customer = new WC_Stripe_Customer($customer_id);
376 376
 			$stripe_cards    = $stripe_customer->get_cards();
377 377
 			$stored_tokens   = array();
378 378
 
379
-			foreach ( $tokens as $token ) {
379
+			foreach ($tokens as $token) {
380 380
 				$stored_tokens[] = $token->get_token();
381 381
 			}
382 382
 
383
-			foreach ( $stripe_cards as $card ) {
384
-				if ( ! in_array( $card->id, $stored_tokens ) ) {
383
+			foreach ($stripe_cards as $card) {
384
+				if ( ! in_array($card->id, $stored_tokens)) {
385 385
 					$token = new WC_Payment_Token_CC();
386
-					$token->set_token( $card->id );
387
-					$token->set_gateway_id( 'stripe' );
388
-					$token->set_card_type( strtolower( $card->brand ) );
389
-					$token->set_last4( $card->last4 );
390
-					$token->set_expiry_month( $card->exp_month  );
391
-					$token->set_expiry_year( $card->exp_year );
392
-					$token->set_user_id( $customer_id );
386
+					$token->set_token($card->id);
387
+					$token->set_gateway_id('stripe');
388
+					$token->set_card_type(strtolower($card->brand));
389
+					$token->set_last4($card->last4);
390
+					$token->set_expiry_month($card->exp_month);
391
+					$token->set_expiry_year($card->exp_year);
392
+					$token->set_user_id($customer_id);
393 393
 					$token->save();
394
-					$tokens[ $token->get_id() ] = $token;
394
+					$tokens[$token->get_id()] = $token;
395 395
 				}
396 396
 			}
397 397
 		}
@@ -401,21 +401,21 @@  discard block
 block discarded – undo
401 401
 	/**
402 402
 	 * Delete token from Stripe
403 403
 	 */
404
-	public function woocommerce_payment_token_deleted( $token_id, $token ) {
405
-		if ( 'stripe' === $token->get_gateway_id() ) {
406
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
407
-			$stripe_customer->delete_card( $token->get_token() );
404
+	public function woocommerce_payment_token_deleted($token_id, $token) {
405
+		if ('stripe' === $token->get_gateway_id()) {
406
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
407
+			$stripe_customer->delete_card($token->get_token());
408 408
 		}
409 409
 	}
410 410
 
411 411
 	/**
412 412
 	 * Set as default in Stripe
413 413
 	 */
414
-	public function woocommerce_payment_token_set_default( $token_id ) {
415
-		$token = WC_Payment_Tokens::get( $token_id );
416
-		if ( 'stripe' === $token->get_gateway_id() ) {
417
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
418
-			$stripe_customer->set_default_card( $token->get_token() );
414
+	public function woocommerce_payment_token_set_default($token_id) {
415
+		$token = WC_Payment_Tokens::get($token_id);
416
+		if ('stripe' === $token->get_gateway_id()) {
417
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
418
+			$stripe_customer->set_default_card($token->get_token());
419 419
 		}
420 420
 	}
421 421
 	
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 	public function get_minimum_amount() {
426 426
 	
427 427
 		// Check order amount
428
-		switch ( get_woocommerce_currency() ) {
428
+		switch (get_woocommerce_currency()) {
429 429
 			case 'USD':
430 430
 			case 'CAD':
431 431
 			case 'EUR':
@@ -470,15 +470,15 @@  discard block
 block discarded – undo
470 470
 	 * And fits on your back?
471 471
 	 * It's log, log, log
472 472
 	 */
473
-	public static function log( $message ) {
474
-		if ( empty( self::$log ) ) {
473
+	public static function log($message) {
474
+		if (empty(self::$log)) {
475 475
 			self::$log = new WC_Logger();
476 476
 		}
477 477
 
478
-		self::$log->add( 'woocommerce-gateway-stripe', $message );
478
+		self::$log->add('woocommerce-gateway-stripe', $message);
479 479
 
480
-		if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
481
-			error_log( $message );
480
+		if (defined('WP_DEBUG') && WP_DEBUG) {
481
+			error_log($message);
482 482
 		}
483 483
 	}
484 484
 }
Please login to merge, or discard this patch.
includes/legacy/class-wc-gateway-stripe-saved-cards.php 1 patch
Spacing   +24 added lines, -24 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
 
@@ -12,25 +12,25 @@  discard block
 block discarded – undo
12 12
 	 * Constructor
13 13
 	 */
14 14
 	public function __construct() {
15
-		add_action( 'wp', array( $this, 'delete_card' ) );
16
-		add_action( 'woocommerce_after_my_account', array( $this, 'output' ) );
17
-		add_action( 'wp', array( $this, 'default_card' ) );
15
+		add_action('wp', array($this, 'delete_card'));
16
+		add_action('woocommerce_after_my_account', array($this, 'output'));
17
+		add_action('wp', array($this, 'default_card'));
18 18
 	}
19 19
 
20 20
 	/**
21 21
 	 * Display saved cards
22 22
 	 */
23 23
 	public function output() {
24
-		if ( ! is_user_logged_in() ) {
24
+		if ( ! is_user_logged_in()) {
25 25
 			return;
26 26
 		}
27 27
 
28
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
28
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
29 29
 		$stripe_cards    = $stripe_customer->get_cards();
30 30
 		$default_card    = $stripe_customer->get_default_card();
31 31
 
32
-		if ( $stripe_cards ) {
33
-			wc_get_template( 'saved-cards.php', array( 'cards' => $stripe_cards, 'default_card' => $default_card ), 'woocommerce-gateway-stripe/', untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/legacy/templates/' );
32
+		if ($stripe_cards) {
33
+			wc_get_template('saved-cards.php', array('cards' => $stripe_cards, 'default_card' => $default_card), 'woocommerce-gateway-stripe/', untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/legacy/templates/');
34 34
 		}
35 35
 	}
36 36
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 	 * Delete a card
39 39
 	 */
40 40
 	public function delete_card() {
41
-		if ( ! isset( $_POST['stripe_delete_card'] ) || ! is_account_page() ) {
41
+		if ( ! isset($_POST['stripe_delete_card']) || ! is_account_page()) {
42 42
 			return;
43 43
 		}
44 44
 
45
-		$stripe_customer    = new WC_Stripe_Customer( get_current_user_id() );
45
+		$stripe_customer    = new WC_Stripe_Customer(get_current_user_id());
46 46
 		$stripe_customer_id = $stripe_customer->get_id();
47
-		$delete_card        = sanitize_text_field( $_POST['stripe_delete_card'] );
47
+		$delete_card        = sanitize_text_field($_POST['stripe_delete_card']);
48 48
 
49
-		if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce( $_POST['_wpnonce'], "stripe_del_card" ) ) {
50
-			wp_die( __( 'Unable to make default card, please try again', 'woocommerce-gateway-stripe' ) );
49
+		if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce($_POST['_wpnonce'], "stripe_del_card")) {
50
+			wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe'));
51 51
 		}
52 52
 
53
-		if ( ! $stripe_customer->delete_card( $delete_card ) ) {
54
-			wc_add_notice( __( 'Unable to delete card.', 'woocommerce-gateway-stripe' ), 'error' );
53
+		if ( ! $stripe_customer->delete_card($delete_card)) {
54
+			wc_add_notice(__('Unable to delete card.', 'woocommerce-gateway-stripe'), 'error');
55 55
 		} else {
56
-			wc_add_notice( __( 'Card deleted.', 'woocommerce-gateway-stripe' ), 'success' );
56
+			wc_add_notice(__('Card deleted.', 'woocommerce-gateway-stripe'), 'success');
57 57
 		}
58 58
 	}
59 59
 
@@ -61,22 +61,22 @@  discard block
 block discarded – undo
61 61
 	 * Make a card as default method
62 62
 	 */
63 63
 	public function default_card() {
64
-		if ( ! isset( $_POST['stripe_default_card'] ) || ! is_account_page() ) {
64
+		if ( ! isset($_POST['stripe_default_card']) || ! is_account_page()) {
65 65
 			return;
66 66
 		}
67 67
 
68
-		$stripe_customer    = new WC_Stripe_Customer( get_current_user_id() );
68
+		$stripe_customer    = new WC_Stripe_Customer(get_current_user_id());
69 69
 		$stripe_customer_id = $stripe_customer->get_id();
70
-		$default_source     = sanitize_text_field( $_POST['stripe_default_card'] );
70
+		$default_source     = sanitize_text_field($_POST['stripe_default_card']);
71 71
 
72
-		if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce( $_POST['_wpnonce'], "stripe_default_card" ) ) {
73
-			wp_die( __( 'Unable to make default card, please try again', 'woocommerce-gateway-stripe' ) );
72
+		if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce($_POST['_wpnonce'], "stripe_default_card")) {
73
+			wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe'));
74 74
 		}
75 75
 
76
-		if ( ! $stripe_customer->set_default_card( $default_source ) ) {
77
-			wc_add_notice( __( 'Unable to update default card.', 'woocommerce-gateway-stripe' ), 'error' );
76
+		if ( ! $stripe_customer->set_default_card($default_source)) {
77
+			wc_add_notice(__('Unable to update default card.', 'woocommerce-gateway-stripe'), 'error');
78 78
 		} else {
79
-			wc_add_notice( __( 'Default card updated.', 'woocommerce-gateway-stripe' ), 'success' );
79
+			wc_add_notice(__('Default card updated.', 'woocommerce-gateway-stripe'), 'success');
80 80
 		}
81 81
 	}
82 82
 }
Please login to merge, or discard this patch.
includes/legacy/templates/saved-cards.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,37 +1,37 @@
 block discarded – undo
1
-<h2 id="saved-cards" style="margin-top:40px;"><?php _e( 'Saved cards', 'woocommerce-gateway-stripe' ); ?></h2>
1
+<h2 id="saved-cards" style="margin-top:40px;"><?php _e('Saved cards', 'woocommerce-gateway-stripe'); ?></h2>
2 2
 <table class="shop_table">
3 3
 	<thead>
4 4
 		<tr>
5
-			<th><?php esc_html_e( 'Card', 'woocommerce-gateway-stripe' ); ?></th>
6
-			<th><?php esc_html_e( 'Expires', 'woocommerce-gateway-stripe' ); ?></th>
5
+			<th><?php esc_html_e('Card', 'woocommerce-gateway-stripe'); ?></th>
6
+			<th><?php esc_html_e('Expires', 'woocommerce-gateway-stripe'); ?></th>
7 7
 			<th></th>
8 8
 		</tr>
9 9
 	</thead>
10 10
 	<tbody>
11
-		<?php foreach ( $cards as $card ) :
12
-			if ( 'card' !== $card->object ) {
11
+		<?php foreach ($cards as $card) :
12
+			if ('card' !== $card->object) {
13 13
 				continue;
14 14
 			}
15 15
 
16 16
 			$is_default_card = $card->id === $default_card ? true : false;
17 17
 		?>
18 18
 		<tr>
19
-            <td><?php printf( __( '%s card ending in %s', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4 ); ?>
20
-            	<?php if ( $is_default_card ) echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); ?>
19
+            <td><?php printf(__('%s card ending in %s', 'woocommerce-gateway-stripe'), $card->brand, $card->last4); ?>
20
+            	<?php if ($is_default_card) echo '<br />' . __('(Default)', 'woocommerce-gateway-stripe'); ?>
21 21
             </td>
22
-            <td><?php printf( __( 'Expires %s/%s', 'woocommerce-gateway-stripe' ), $card->exp_month, $card->exp_year ); ?></td>
22
+            <td><?php printf(__('Expires %s/%s', 'woocommerce-gateway-stripe'), $card->exp_month, $card->exp_year); ?></td>
23 23
 			<td>
24 24
                 <form action="" method="POST">
25
-                    <?php wp_nonce_field ( 'stripe_del_card' ); ?>
26
-                    <input type="hidden" name="stripe_delete_card" value="<?php echo esc_attr( $card->id ); ?>">
27
-                    <input type="submit" class="button" value="<?php esc_attr_e( 'Delete card', 'woocommerce-gateway-stripe' ); ?>">
25
+                    <?php wp_nonce_field('stripe_del_card'); ?>
26
+                    <input type="hidden" name="stripe_delete_card" value="<?php echo esc_attr($card->id); ?>">
27
+                    <input type="submit" class="button" value="<?php esc_attr_e('Delete card', 'woocommerce-gateway-stripe'); ?>">
28 28
                 </form>
29 29
 
30
-                <?php if ( ! $is_default_card ) { ?>
30
+                <?php if ( ! $is_default_card) { ?>
31 31
 	                <form action="" method="POST" style="margin-top:10px;">
32
-	                    <?php wp_nonce_field ( 'stripe_default_card' ); ?>
33
-	                    <input type="hidden" name="stripe_default_card" value="<?php echo esc_attr( $card->id ); ?>">
34
-	                    <input type="submit" class="button" value="<?php esc_attr_e( 'Make Default', 'woocommerce-gateway-stripe' ); ?>">
32
+	                    <?php wp_nonce_field('stripe_default_card'); ?>
33
+	                    <input type="hidden" name="stripe_default_card" value="<?php echo esc_attr($card->id); ?>">
34
+	                    <input type="submit" class="button" value="<?php esc_attr_e('Make Default', 'woocommerce-gateway-stripe'); ?>">
35 35
 	                </form>
36 36
                 <?php } ?>
37 37
 			</td>
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,10 @@
 block discarded – undo
17 17
 		?>
18 18
 		<tr>
19 19
             <td><?php printf( __( '%s card ending in %s', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4 ); ?>
20
-            	<?php if ( $is_default_card ) echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); ?>
20
+            	<?php if ( $is_default_card ) {
21
+	echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' );
22
+}
23
+?>
21 24
             </td>
22 25
             <td><?php printf( __( 'Expires %s/%s', 'woocommerce-gateway-stripe' ), $card->exp_month, $card->exp_year ); ?></td>
23 26
 			<td>
Please login to merge, or discard this patch.
includes/class-wc-stripe-payment-request.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @version 3.1.0
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if ( ! defined('ABSPATH')) {
11 11
 	exit;
12 12
 }
13 13
 
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 	 * Initialize class actions.
21 21
 	 */
22 22
 	public function __construct() {
23
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
23
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
24 24
 
25
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
26
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
27
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
28
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
25
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
26
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
27
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
28
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
29 29
 	}
30 30
 
31 31
 	/**
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
 	 * @return bool
35 35
 	 */
36 36
 	protected function is_activated() {
37
-		$options             = get_option( 'woocommerce_stripe_settings', array() );
38
-		$enabled             = isset( $options['enabled'] ) && 'yes' === $options['enabled'];
39
-		$stripe_checkout     = isset( $options['stripe_checkout'] ) && 'yes' !== $options['stripe_checkout'];
40
-		$request_payment_api = isset( $options['request_payment_api'] ) && 'yes' === $options['request_payment_api'];
37
+		$options             = get_option('woocommerce_stripe_settings', array());
38
+		$enabled             = isset($options['enabled']) && 'yes' === $options['enabled'];
39
+		$stripe_checkout     = isset($options['stripe_checkout']) && 'yes' !== $options['stripe_checkout'];
40
+		$request_payment_api = isset($options['request_payment_api']) && 'yes' === $options['request_payment_api'];
41 41
 
42 42
 		return $enabled && $stripe_checkout && $request_payment_api && is_ssl();
43 43
 	}
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 	 * @return string
49 49
 	 */
50 50
 	protected function get_publishable_key() {
51
-		$options = get_option( 'woocommerce_stripe_settings', array() );
51
+		$options = get_option('woocommerce_stripe_settings', array());
52 52
 
53
-		if ( empty( $options ) ) {
53
+		if (empty($options)) {
54 54
 			return '';
55 55
 		}
56 56
 
@@ -62,38 +62,38 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function scripts() {
64 64
 		// Load PaymentRequest only on cart for now.
65
-		if ( ! is_cart() ) {
65
+		if ( ! is_cart()) {
66 66
 			return;
67 67
 		}
68 68
 
69
-		if ( ! $this->is_activated() ) {
69
+		if ( ! $this->is_activated()) {
70 70
 			return;
71 71
 		}
72 72
 
73
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
73
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
74 74
 
75
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
76
-		wp_enqueue_script( 'wc-stripe-payment-request', plugins_url( 'assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true );
75
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
76
+		wp_enqueue_script('wc-stripe-payment-request', plugins_url('assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true);
77 77
 
78 78
 		wp_localize_script(
79 79
 			'wc-stripe-payment-request',
80 80
 			'wcStripePaymentRequestParams',
81 81
 			array(
82
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
82
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
83 83
 				'stripe'   => array(
84 84
 					'key'                => $this->get_publishable_key(),
85
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
85
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
86 86
 				),
87 87
 				'nonce'    => array(
88
-					'payment'         => wp_create_nonce( 'wc-stripe-payment-request' ),
89
-					'shipping'        => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
90
-					'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
91
-					'checkout'        => wp_create_nonce( 'woocommerce-process_checkout' ),
88
+					'payment'         => wp_create_nonce('wc-stripe-payment-request'),
89
+					'shipping'        => wp_create_nonce('wc-stripe-payment-request-shipping'),
90
+					'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'),
91
+					'checkout'        => wp_create_nonce('woocommerce-process_checkout'),
92 92
 				),
93 93
 				'i18n'     => array(
94
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
94
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
95 95
 					/* translators: Do not translate the [option] placeholder */
96
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
96
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
97 97
 				),
98 98
 			)
99 99
 		);
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
 	 * Get cart details.
104 104
 	 */
105 105
 	public function ajax_get_cart_details() {
106
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
106
+		check_ajax_referer('wc-stripe-payment-request', 'security');
107 107
 
108
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
109
-			define( 'WOOCOMMERCE_CART', true );
108
+		if ( ! defined('WOOCOMMERCE_CART')) {
109
+			define('WOOCOMMERCE_CART', true);
110 110
 		}
111 111
 
112 112
 		WC()->cart->calculate_totals();
@@ -118,16 +118,16 @@  discard block
 block discarded – undo
118 118
 			'shipping_required' => WC()->cart->needs_shipping(),
119 119
 			'order_data'        => array(
120 120
 				'total' => array(
121
-					'label'  => __( 'Total', 'woocommerce-gateway-stripe' ),
121
+					'label'  => __('Total', 'woocommerce-gateway-stripe'),
122 122
 					'amount' => array(
123
-						'value'    => max( 0, apply_filters( 'woocommerce_calculated_total', round( WC()->cart->cart_contents_total + WC()->cart->fee_total, WC()->cart->dp ), WC()->cart ) ),
123
+						'value'    => max(0, apply_filters('woocommerce_calculated_total', round(WC()->cart->cart_contents_total + WC()->cart->fee_total, WC()->cart->dp), WC()->cart)),
124 124
 						'currency' => $currency,
125 125
 					),
126 126
 				),
127 127
 			),
128 128
 		);
129 129
 
130
-		wp_send_json( $data );
130
+		wp_send_json($data);
131 131
 	}
132 132
 
133 133
 	/**
@@ -138,17 +138,17 @@  discard block
 block discarded – undo
138 138
 	 * @see WC_Shipping::get_packages().
139 139
 	 */
140 140
 	public function ajax_get_shipping_options() {
141
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
141
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
142 142
 
143 143
 		// Set the shipping package.
144
-		$posted   = filter_input_array( INPUT_POST, array(
144
+		$posted = filter_input_array(INPUT_POST, array(
145 145
 			'country'   => FILTER_SANITIZE_ENCODED,
146 146
 			'state'     => FILTER_SANITIZE_STRING,
147 147
 			'postcode'  => FILTER_SANITIZE_ENCODED,
148 148
 			'city'      => FILTER_SANITIZE_STRING,
149 149
 			'address'   => FILTER_SANITIZE_STRING,
150 150
 			'address_2' => FILTER_SANITIZE_STRING,
151
-		) );
151
+		));
152 152
 		$packages = array();
153 153
 
154 154
 		$packages[0]['contents']                 = WC()->cart->get_cart();
@@ -162,23 +162,23 @@  discard block
 block discarded – undo
162 162
 		$packages[0]['destination']['address']   = $posted['address'];
163 163
 		$packages[0]['destination']['address_2'] = $posted['address_2'];
164 164
 
165
-		foreach ( WC()->cart->get_cart() as $item ) {
166
-			if ( $item['data']->needs_shipping() ) {
167
-				if ( isset( $item['line_total'] ) ) {
165
+		foreach (WC()->cart->get_cart() as $item) {
166
+			if ($item['data']->needs_shipping()) {
167
+				if (isset($item['line_total'])) {
168 168
 					$packages[0]['contents_cost'] += $item['line_total'];
169 169
 				}
170 170
 			}
171 171
 		}
172 172
 
173
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
173
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
174 174
 
175
-		WC()->shipping->calculate_shipping( $packages );
175
+		WC()->shipping->calculate_shipping($packages);
176 176
 
177 177
 		// Set the shipping options.
178 178
 		$currency = get_woocommerce_currency();
179 179
 		$data     = array();
180
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
181
-			foreach ( $package['rates'] as $key => $rate ) {
180
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
181
+			foreach ($package['rates'] as $key => $rate) {
182 182
 				$data[] = array(
183 183
 					'id'       => $rate->id,
184 184
 					'label'    => $rate->label,
@@ -192,45 +192,45 @@  discard block
 block discarded – undo
192 192
 		}
193 193
 
194 194
 		// Auto select when have only one shipping method available.
195
-		if ( 1 === count( $data ) ) {
195
+		if (1 === count($data)) {
196 196
 			$data[0]['selected'] = true;
197 197
 		}
198 198
 
199
-		wp_send_json( $data );
199
+		wp_send_json($data);
200 200
 	}
201 201
 
202 202
 	/**
203 203
 	 * Update shipping method.
204 204
 	 */
205 205
 	public function ajax_update_shipping_method() {
206
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
206
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
207 207
 
208
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
209
-			define( 'WOOCOMMERCE_CART', true );
208
+		if ( ! defined('WOOCOMMERCE_CART')) {
209
+			define('WOOCOMMERCE_CART', true);
210 210
 		}
211 211
 
212
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
213
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
212
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
213
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
214 214
 
215
-		if ( is_array( $shipping_method ) ) {
216
-			foreach ( $shipping_method as $i => $value ) {
217
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
215
+		if (is_array($shipping_method)) {
216
+			foreach ($shipping_method as $i => $value) {
217
+				$chosen_shipping_methods[$i] = wc_clean($value);
218 218
 			}
219 219
 		}
220 220
 
221
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
221
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
222 222
 
223 223
 		WC()->cart->calculate_totals();
224 224
 
225 225
 		// Send back the new cart total.
226 226
 		$currency  = get_woocommerce_currency();
227
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
227
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
228 228
 		$data      = array(
229 229
 			'total' => WC()->cart->total,
230 230
 		);
231 231
 
232 232
 		// Include fees and taxes as displayItems.
233
-		foreach ( WC()->cart->fees as $key => $fee ) {
233
+		foreach (WC()->cart->fees as $key => $fee) {
234 234
 			$data['items'][] = array(
235 235
 				'label'  => $fee->name,
236 236
 				'amount' => array(
@@ -239,9 +239,9 @@  discard block
 block discarded – undo
239 239
 				),
240 240
 			);
241 241
 		}
242
-		if ( 0 < $tax_total ) {
242
+		if (0 < $tax_total) {
243 243
 			$data['items'][] = array(
244
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
244
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
245 245
 				'amount' => array(
246 246
 					'currency' => $currency,
247 247
 					'value'    => $tax_total,
@@ -249,24 +249,24 @@  discard block
 block discarded – undo
249 249
 			);
250 250
 		}
251 251
 
252
-		wp_send_json( $data );
252
+		wp_send_json($data);
253 253
 	}
254 254
 
255 255
 	/**
256 256
 	 * Create order.
257 257
 	 */
258 258
 	public function ajax_create_order() {
259
-		if ( WC()->cart->is_empty() ) {
260
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
259
+		if (WC()->cart->is_empty()) {
260
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
261 261
 		}
262 262
 
263
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
264
-			define( 'WOOCOMMERCE_CHECKOUT', true );
263
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
264
+			define('WOOCOMMERCE_CHECKOUT', true);
265 265
 		}
266 266
 
267 267
 		WC()->checkout()->process_checkout();
268 268
 
269
-		die( 0 );
269
+		die(0);
270 270
 	}
271 271
 }
272 272
 
Please login to merge, or discard this patch.
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +122 added lines, -122 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
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	public function __construct() {
41 41
 		self::$_this = $this;
42 42
 
43
-		$this->_gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
43
+		$this->_gateway_settings = get_option('woocommerce_stripe_settings', '');
44 44
 
45 45
 		$this->init();
46 46
 	}
@@ -57,15 +57,15 @@  discard block
 block discarded – undo
57 57
 	 * @version 3.1.0
58 58
 	 */
59 59
 	public function init() {
60
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
61
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 20 );
62
-		add_action( 'woocommerce_review_order_before_payment', array( $this, 'display_apple_pay_button' ) );
60
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
61
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 20);
62
+		add_action('woocommerce_review_order_before_payment', array($this, 'display_apple_pay_button'));
63 63
 		
64
-		if ( is_admin() ) {
65
-			add_action( 'wp_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
66
-			add_action( 'wp_ajax_nopriv_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
67
-			add_action( 'wp_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
68
-			add_action( 'wp_ajax_nopriv_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
64
+		if (is_admin()) {
65
+			add_action('wp_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
66
+			add_action('wp_ajax_nopriv_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
67
+			add_action('wp_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
68
+			add_action('wp_ajax_nopriv_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
69 69
 		}
70 70
 	}
71 71
 
@@ -76,38 +76,38 @@  discard block
 block discarded – undo
76 76
 	 * @version 3.1.0
77 77
 	 */
78 78
 	public function payment_scripts() {
79
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
79
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
80 80
 			return;
81 81
 		}
82 82
 
83
-		if ( ! $this->is_supported_product_type() ) {
83
+		if ( ! $this->is_supported_product_type()) {
84 84
 			return;
85 85
 		}
86 86
 		
87
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
87
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
88 88
 		
89
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
89
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
90 90
 
91
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
92
-		wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
91
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
92
+		wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
93 93
 
94 94
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
95 95
 
96 96
 		$stripe_params = array(
97 97
 			'key'                         => $publishable_key,
98 98
 			'currency_code'               => get_woocommerce_currency(),
99
-			'country_code'                => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
100
-			'label'                       => get_bloginfo( 'name', 'display' ),
101
-			'ajaxurl'                     => admin_url( 'admin-ajax.php' ),
102
-			'stripe_apple_pay_nonce'      => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
103
-			'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
99
+			'country_code'                => substr(get_option('woocommerce_default_country'), 0, 2),
100
+			'label'                       => get_bloginfo('name', 'display'),
101
+			'ajaxurl'                     => admin_url('admin-ajax.php'),
102
+			'stripe_apple_pay_nonce'      => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
103
+			'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
104 104
 			'needs_shipping'              => WC()->cart->needs_shipping() ? 'yes' : 'no',
105
-			'needs_shipping_msg'          => __( 'Please first calculate your shipping.', 'woocommerce-gateway-stripe' ),
105
+			'needs_shipping_msg'          => __('Please first calculate your shipping.', 'woocommerce-gateway-stripe'),
106 106
 			'is_cart_page'                => is_cart() ? 'yes' : 'no',
107 107
 			'chosen_shipping'             => wc_get_chosen_shipping_method_ids(),
108 108
 		);
109 109
 
110
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
110
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
111 111
 	}
112 112
 		
113 113
 	/**
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 	 *
116 116
 	 */
117 117
 	public function is_supported_product_type() {
118
-		foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
119
-			if ( 'subscription' === $values['data']->product_type ) {
118
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
119
+			if ('subscription' === $values['data']->product_type) {
120 120
 				return false;
121 121
 			}
122 122
 		}
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
 		 */
140 140
 		if ( 
141 141
 			'yes' !== $this->_gateway_settings['apple_pay']
142
-			|| ! isset( $gateways['stripe'] ) 
142
+			|| ! isset($gateways['stripe']) 
143 143
 		) {
144 144
 			return;
145 145
 		}
146 146
 
147
-		if ( ! $this->is_supported_product_type() ) {
147
+		if ( ! $this->is_supported_product_type()) {
148 148
 			return;
149 149
 		}
150 150
 		?>
@@ -159,15 +159,15 @@  discard block
 block discarded – undo
159 159
 	 * @version 3.1.0
160 160
 	 */
161 161
 	public function generate_apple_pay_cart() {
162
-		if ( ! defined( 'DOING_AJAX' ) ) {
163
-			define( 'DOING_AJAX', true );
162
+		if ( ! defined('DOING_AJAX')) {
163
+			define('DOING_AJAX', true);
164 164
 		}
165 165
 
166
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
167
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
166
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
167
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
168 168
 		}
169 169
 
170
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total, 'chosen_shipping' => wc_get_chosen_shipping_method_ids() ) );
170
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total, 'chosen_shipping' => wc_get_chosen_shipping_method_ids()));
171 171
 	}
172 172
 
173 173
 	/**
@@ -178,39 +178,39 @@  discard block
 block discarded – undo
178 178
 	 * @version 3.1.0
179 179
 	 */
180 180
 	public function process_apple_pay() {
181
-		if ( ! defined( 'DOING_AJAX' ) ) {
182
-			define( 'DOING_AJAX', true );
181
+		if ( ! defined('DOING_AJAX')) {
182
+			define('DOING_AJAX', true);
183 183
 		}
184 184
 
185
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
186
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
185
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
186
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
187 187
 		}
188 188
 
189 189
 		try {
190
-			$result = array_map( 'wc_clean', $_POST['result'] );
190
+			$result = array_map('wc_clean', $_POST['result']);
191 191
 
192
-			$order = $this->create_order( $result );
192
+			$order = $this->create_order($result);
193 193
 
194 194
 			// Handle payment.
195
-			if ( $order->get_total() > 0 ) {
195
+			if ($order->get_total() > 0) {
196 196
 
197
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
198
-					return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
197
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
198
+					return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
199 199
 				}
200 200
 
201
-				WC_Stripe::log( "Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}" );
201
+				WC_Stripe::log("Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}");
202 202
 
203 203
 				// Make the request.
204
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
204
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
205 205
 
206
-				if ( is_wp_error( $response ) ) {
206
+				if (is_wp_error($response)) {
207 207
 					$localized_messages = $this->get_localized_messages();
208 208
 
209
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
209
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
210 210
 				}
211 211
 
212 212
 				// Process valid response.
213
-				$this->process_response( $response, $order );
213
+				$this->process_response($response, $order);
214 214
 			} else {
215 215
 				$order->payment_complete();
216 216
 			}
@@ -218,23 +218,23 @@  discard block
 block discarded – undo
218 218
 			// Remove cart.
219 219
 			WC()->cart->empty_cart();
220 220
 
221
-			update_post_meta( $order->id, '_customer_user', get_current_user_id() );
221
+			update_post_meta($order->id, '_customer_user', get_current_user_id());
222 222
 
223 223
 			// Return thank you page redirect.
224
-			wp_send_json( array(
224
+			wp_send_json(array(
225 225
 				'success'  => 'true',
226
-				'redirect' => $this->get_return_url( $order ),
227
-			) );
226
+				'redirect' => $this->get_return_url($order),
227
+			));
228 228
 
229
-		} catch ( Exception $e ) {
230
-			WC()->session->set( 'refresh_totals', true );
231
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
229
+		} catch (Exception $e) {
230
+			WC()->session->set('refresh_totals', true);
231
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
232 232
 
233
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
234
-				$this->send_failed_order_email( $order->id );
233
+			if ($order->has_status(array('pending', 'failed'))) {
234
+				$this->send_failed_order_email($order->id);
235 235
 			}
236 236
 
237
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
237
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
238 238
 		}
239 239
 	}
240 240
 
@@ -244,14 +244,14 @@  discard block
 block discarded – undo
244 244
 	 * @param string $source token
245 245
 	 * @return array()
246 246
 	 */
247
-	protected function generate_payment_request( $order, $source ) {
247
+	protected function generate_payment_request($order, $source) {
248 248
 		$post_data                = array();
249
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
250
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
251
-		$post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
249
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
250
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
251
+		$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
252 252
 		$post_data['capture']     = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false';
253 253
 
254
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
254
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
255 255
 			$post_data['receipt_email'] = $order->billing_email;
256 256
 		}
257 257
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 		 * @param WC_Order $order
267 267
 		 * @param object $source
268 268
 		 */
269
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
269
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
270 270
 	}
271 271
 
272 272
 	/**
@@ -276,49 +276,49 @@  discard block
 block discarded – undo
276 276
 	 * @version 3.1.0
277 277
 	 */	
278 278
 	public function build_line_items() {
279
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
279
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
280 280
 
281 281
 		$items = array();
282 282
 
283
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
284
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
283
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
284
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
285 285
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
286 286
 
287 287
 			$item = array(
288 288
 				'type'   => 'final',
289 289
 				'label'  => $values['data']->post->post_title . $quantity_label,
290
-				'amount' => wc_format_decimal( $amount, $decimals ),
290
+				'amount' => wc_format_decimal($amount, $decimals),
291 291
 			);
292 292
 
293 293
 			$items[] = $item;
294 294
 		}
295 295
 
296
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
297
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
298
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
299
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
300
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
296
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
297
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
298
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
299
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
300
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
301 301
 
302
-		if ( wc_tax_enabled() ) {
302
+		if (wc_tax_enabled()) {
303 303
 			$items[] = array(
304 304
 				'type'   => 'final',
305
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
305
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
306 306
 				'amount' => $tax,
307 307
 			);
308 308
 		}
309 309
 
310
-		if ( WC()->cart->needs_shipping() ) {
310
+		if (WC()->cart->needs_shipping()) {
311 311
 			$items[] = array(
312 312
 				'type'   => 'final',
313
-				'label'  => __( 'Shipping', 'woocommerce-gateway-stripe' ),
313
+				'label'  => __('Shipping', 'woocommerce-gateway-stripe'),
314 314
 				'amount' => $shipping,
315 315
 			);
316 316
 		}
317 317
 
318
-		if ( WC()->cart->has_discount() ) {
318
+		if (WC()->cart->has_discount()) {
319 319
 			$items[] = array(
320 320
 				'type'   => 'final',
321
-				'label'  => __( 'Discount', 'woocommerce-gateway-stripe' ),
321
+				'label'  => __('Discount', 'woocommerce-gateway-stripe'),
322 322
 				'amount' => $discounts,
323 323
 			);
324 324
 		}
@@ -334,24 +334,24 @@  discard block
 block discarded – undo
334 334
 	 * @param array $data
335 335
 	 * @return object $order
336 336
 	 */
337
-	public function create_order( $data = array() ) {
338
-		if ( empty( $data ) ) {
339
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
337
+	public function create_order($data = array()) {
338
+		if (empty($data)) {
339
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
340 340
 		}
341 341
 
342 342
 		$order = wc_create_order();
343 343
 
344
-		if ( is_wp_error( $order ) ) {
345
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
346
-		} elseif ( false === $order ) {
347
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
344
+		if (is_wp_error($order)) {
345
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
346
+		} elseif (false === $order) {
347
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
348 348
 		} else {
349 349
 			$order_id = $order->id;
350
-			do_action( 'woocommerce_new_order', $order_id );
350
+			do_action('woocommerce_new_order', $order_id);
351 351
 		}
352 352
 
353 353
 		// Store the line items to the new/resumed order
354
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
354
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
355 355
 			$item_id = $order->add_product(
356 356
 				$values['data'],
357 357
 				$values['quantity'],
@@ -367,47 +367,47 @@  discard block
 block discarded – undo
367 367
 				)
368 368
 			);
369 369
 
370
-			if ( ! $item_id ) {
371
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
370
+			if ( ! $item_id) {
371
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
372 372
 			}
373 373
 
374 374
 			// Allow plugins to add order item meta
375
-			do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
375
+			do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
376 376
 		}
377 377
 
378 378
 		// Store fees
379
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
380
-			$item_id = $order->add_fee( $fee );
379
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
380
+			$item_id = $order->add_fee($fee);
381 381
 
382
-			if ( ! $item_id ) {
383
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
382
+			if ( ! $item_id) {
383
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
384 384
 			}
385 385
 
386 386
 			// Allow plugins to add order item meta to fees
387
-			do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
387
+			do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
388 388
 		}
389 389
 
390 390
 		// Store tax rows
391
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
392
-			if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
393
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
391
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
392
+			if ($tax_rate_id && ! $order->add_tax($tax_rate_id, WC()->cart->get_tax_amount($tax_rate_id), WC()->cart->get_shipping_tax_amount($tax_rate_id)) && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
393
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
394 394
 			}
395 395
 		}
396 396
 
397 397
 		// Store coupons
398
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
399
-			if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
400
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
398
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
399
+			if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) {
400
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
401 401
 			}
402 402
 		}
403 403
 
404 404
 		// Billing address
405 405
 		$billing_address = array();
406
-		if ( ! empty( $data['token']['card'] ) ) {
406
+		if ( ! empty($data['token']['card'])) {
407 407
 			// Name from Stripe is a full name string.
408
-			$name                          = explode( ' ', $data['token']['card']['name'] );
409
-			$lastname                      = array_pop( $name );
410
-			$firstname                     = implode( ' ', $name );
408
+			$name                          = explode(' ', $data['token']['card']['name']);
409
+			$lastname                      = array_pop($name);
410
+			$firstname                     = implode(' ', $name);
411 411
 			$billing_address['first_name'] = $firstname;
412 412
 			$billing_address['last_name']  = $lastname;
413 413
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 
423 423
 		// Shipping address.
424 424
 		$shipping_address = array();
425
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
425
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
426 426
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
427 427
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
428 428
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 			$shipping_address['state']      = $data['shippingContact']['locality'];
433 433
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
434 434
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
435
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
435
+		} elseif ( ! empty($data['shippingContact'])) {
436 436
 			$shipping_address['first_name'] = $firstname;
437 437
 			$shipping_address['last_name']  = $lastname;
438 438
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -445,34 +445,34 @@  discard block
 block discarded – undo
445 445
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
446 446
 		}
447 447
 
448
-		$order->set_address( $billing_address, 'billing' );
449
-		$order->set_address( $shipping_address, 'shipping' );
448
+		$order->set_address($billing_address, 'billing');
449
+		$order->set_address($shipping_address, 'shipping');
450 450
 
451
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
451
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
452 452
 		
453 453
 		// Get the rate object selected by user.
454
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
455
-			foreach ( $package['rates'] as $key => $rate ) {
454
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
455
+			foreach ($package['rates'] as $key => $rate) {
456 456
 				// Loop through user chosen shipping methods.
457
-				foreach( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
458
-					if ( $method === $key ) {
459
-						$order->add_shipping( $rate );
457
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
458
+					if ($method === $key) {
459
+						$order->add_shipping($rate);
460 460
 					}
461 461
 				}
462 462
 			}
463 463
 		}
464 464
 
465 465
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
466
-		$order->set_payment_method( $available_gateways['stripe'] );
467
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
468
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
469
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
470
-		$order->set_total( WC()->cart->tax_total, 'tax' );
471
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
472
-		$order->set_total( WC()->cart->total );
466
+		$order->set_payment_method($available_gateways['stripe']);
467
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
468
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
469
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
470
+		$order->set_total(WC()->cart->tax_total, 'tax');
471
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
472
+		$order->set_total(WC()->cart->total);
473 473
 
474 474
 		// If we got here, the order was created without problems!
475
-		wc_transaction_query( 'commit' );
475
+		wc_transaction_query('commit');
476 476
 
477 477
 		return $order;
478 478
 	}
Please login to merge, or discard this patch.