Completed
Pull Request — master (#1478)
by
unknown
10:44
created
includes/class-wc-stripe-intent-controller.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
 	 * @since 4.2.0
24 24
 	 */
25 25
 	public function __construct() {
26
-		add_action( 'wc_ajax_wc_stripe_verify_intent', array( $this, 'verify_intent' ) );
27
-		add_action( 'wc_ajax_wc_stripe_create_setup_intent', array( $this, 'create_setup_intent' ) );
26
+		add_action('wc_ajax_wc_stripe_verify_intent', array($this, 'verify_intent'));
27
+		add_action('wc_ajax_wc_stripe_create_setup_intent', array($this, 'create_setup_intent'));
28 28
 	}
29 29
 
30 30
 	/**
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
 	 * @return WC_Gateway_Stripe
35 35
 	 */
36 36
 	protected function get_gateway() {
37
-		if ( ! isset( $this->gateway ) ) {
38
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
37
+		if ( ! isset($this->gateway)) {
38
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
39 39
 				$class_name = 'WC_Stripe_Subs_Compat';
40 40
 			} else {
41 41
 				$class_name = 'WC_Gateway_Stripe';
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
 	 * @return WC_Order
56 56
 	 */
57 57
 	protected function get_order_from_request() {
58
-		if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'wc_stripe_confirm_pi' ) ) {
59
-			throw new WC_Stripe_Exception( 'missing-nonce', __( 'CSRF verification failed.', 'woocommerce-gateway-stripe' ) );
58
+		if ( ! isset($_GET['nonce']) || ! wp_verify_nonce(sanitize_key($_GET['nonce']), 'wc_stripe_confirm_pi')) {
59
+			throw new WC_Stripe_Exception('missing-nonce', __('CSRF verification failed.', 'woocommerce-gateway-stripe'));
60 60
 		}
61 61
 
62 62
 		// Load the order ID.
63 63
 		$order_id = null;
64
-		if ( isset( $_GET['order'] ) && absint( $_GET['order'] ) ) {
65
-			$order_id = absint( $_GET['order'] );
64
+		if (isset($_GET['order']) && absint($_GET['order'])) {
65
+			$order_id = absint($_GET['order']);
66 66
 		}
67 67
 
68 68
 		// Retrieve the order.
69
-		$order = wc_get_order( $order_id );
69
+		$order = wc_get_order($order_id);
70 70
 
71
-		if ( ! $order ) {
72
-			throw new WC_Stripe_Exception( 'missing-order', __( 'Missing order ID for payment confirmation', 'woocommerce-gateway-stripe' ) );
71
+		if ( ! $order) {
72
+			throw new WC_Stripe_Exception('missing-order', __('Missing order ID for payment confirmation', 'woocommerce-gateway-stripe'));
73 73
 		}
74 74
 
75 75
 		return $order;
@@ -87,32 +87,32 @@  discard block
 block discarded – undo
87 87
 
88 88
 		try {
89 89
 			$order = $this->get_order_from_request();
90
-		} catch ( WC_Stripe_Exception $e ) {
90
+		} catch (WC_Stripe_Exception $e) {
91 91
 			/* translators: Error message text */
92
-			$message = sprintf( __( 'Payment verification error: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() );
93
-			wc_add_notice( esc_html( $message ), 'error' );
92
+			$message = sprintf(__('Payment verification error: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage());
93
+			wc_add_notice(esc_html($message), 'error');
94 94
 
95 95
 			$redirect_url = $woocommerce->cart->is_empty()
96
-				? get_permalink( wc_get_page_id( 'shop' ) )
96
+				? get_permalink(wc_get_page_id('shop'))
97 97
 				: wc_get_checkout_url();
98 98
 
99
-			$this->handle_error( $e, $redirect_url );
99
+			$this->handle_error($e, $redirect_url);
100 100
 		}
101 101
 
102 102
 		try {
103
-			$gateway->verify_intent_after_checkout( $order );
103
+			$gateway->verify_intent_after_checkout($order);
104 104
 
105
-			if ( ! isset( $_GET['is_ajax'] ) ) {
106
-				$redirect_url = isset( $_GET['redirect_to'] ) // wpcs: csrf ok.
107
-					? esc_url_raw( wp_unslash( $_GET['redirect_to'] ) ) // wpcs: csrf ok.
108
-					: $gateway->get_return_url( $order );
105
+			if ( ! isset($_GET['is_ajax'])) {
106
+				$redirect_url = isset($_GET['redirect_to']) // wpcs: csrf ok.
107
+					? esc_url_raw(wp_unslash($_GET['redirect_to'])) // wpcs: csrf ok.
108
+					: $gateway->get_return_url($order);
109 109
 
110
-				wp_safe_redirect( $redirect_url );
110
+				wp_safe_redirect($redirect_url);
111 111
 			}
112 112
 
113 113
 			exit;
114
-		} catch ( WC_Stripe_Exception $e ) {
115
-			$this->handle_error( $e, $gateway->get_return_url( $order ) );
114
+		} catch (WC_Stripe_Exception $e) {
115
+			$this->handle_error($e, $gateway->get_return_url($order));
116 116
 		}
117 117
 	}
118 118
 
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	 * @param WC_Stripe_Exception $e           The exception that was thrown.
124 124
 	 * @param string              $redirect_url An URL to use if a redirect is needed.
125 125
 	 */
126
-	protected function handle_error( $e, $redirect_url ) {
126
+	protected function handle_error($e, $redirect_url) {
127 127
 		// Log the exception before redirecting.
128
-		$message = sprintf( 'PaymentIntent verification exception: %s', $e->getLocalizedMessage() );
129
-		WC_Stripe_Logger::log( $message );
128
+		$message = sprintf('PaymentIntent verification exception: %s', $e->getLocalizedMessage());
129
+		WC_Stripe_Logger::log($message);
130 130
 
131 131
 		// `is_ajax` is only used for PI error reporting, a response is not expected.
132
-		if ( isset( $_GET['is_ajax'] ) ) {
132
+		if (isset($_GET['is_ajax'])) {
133 133
 			exit;
134 134
 		}
135 135
 
136
-		wp_safe_redirect( $redirect_url );
136
+		wp_safe_redirect($redirect_url);
137 137
 		exit;
138 138
 	}
139 139
 
@@ -143,31 +143,31 @@  discard block
 block discarded – undo
143 143
 	public function create_setup_intent() {
144 144
 		if (
145 145
 			! is_user_logged_in()
146
-			|| ! isset( $_POST['stripe_source_id'] )
147
-			|| ! isset( $_POST['nonce'] )
146
+			|| ! isset($_POST['stripe_source_id'])
147
+			|| ! isset($_POST['nonce'])
148 148
 		) {
149 149
 			return;
150 150
 		}
151 151
 
152 152
 		try {
153
-			$source_id = wc_clean( $_POST['stripe_source_id'] );
153
+			$source_id = wc_clean($_POST['stripe_source_id']);
154 154
 
155 155
 			// 1. Verify.
156 156
 			if (
157
-				! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'wc_stripe_create_si' )
158
-				|| ! preg_match( '/^src_.*$/', $source_id )
157
+				! wp_verify_nonce(sanitize_key($_POST['nonce']), 'wc_stripe_create_si')
158
+				|| ! preg_match('/^src_.*$/', $source_id)
159 159
 			) {
160
-				throw new Exception( __( 'Unable to verify your request. Please reload the page and try again.', 'woocommerce-gateway-stripe' ) );
160
+				throw new Exception(__('Unable to verify your request. Please reload the page and try again.', 'woocommerce-gateway-stripe'));
161 161
 			}
162 162
 
163 163
 
164 164
 			// 2. Load the customer ID (and create a customer eventually).
165
-			$customer = new WC_Stripe_Customer( wp_get_current_user()->ID );
165
+			$customer = new WC_Stripe_Customer(wp_get_current_user()->ID);
166 166
 
167 167
 			// 3. Attach the source to the customer (Setup Intents require that).
168
-			$source_object = $customer->attach_source( $source_id );
169
-			if ( is_wp_error( $source_object ) ) {
170
-				throw new Exception( $source_object->get_error_message() );
168
+			$source_object = $customer->attach_source($source_id);
169
+			if (is_wp_error($source_object)) {
170
+				throw new Exception($source_object->get_error_message());
171 171
 			}
172 172
 
173 173
 			// 4. Generate the setup intent
@@ -180,28 +180,28 @@  discard block
 block discarded – undo
180 180
 				'setup_intents'
181 181
 			);
182 182
 
183
-			if ( ! empty( $setup_intent->error ) ) {
184
-				$error_response_message = print_r( $setup_intent, true );
183
+			if ( ! empty($setup_intent->error)) {
184
+				$error_response_message = print_r($setup_intent, true);
185 185
 				WC_Stripe_Logger::log("Failed create Setup Intent while saving a card.");
186 186
 				WC_Stripe_Logger::log("Response: $error_response_message");
187
-				throw new Exception( __( 'Your card could not be set up for future usage.', 'woocommerce-gateway-stripe' ) );
187
+				throw new Exception(__('Your card could not be set up for future usage.', 'woocommerce-gateway-stripe'));
188 188
 			}
189 189
 
190 190
 			// 5. Respond.
191
-			if ( 'requires_action' === $setup_intent->status ) {
191
+			if ('requires_action' === $setup_intent->status) {
192 192
 				$response = [
193 193
 					'status'        => 'requires_action',
194 194
 					'client_secret' => $setup_intent->client_secret,
195 195
 				];
196
-			} elseif ( 'requires_payment_method' === $setup_intent->status
196
+			} elseif ('requires_payment_method' === $setup_intent->status
197 197
 				|| 'requires_confirmation' === $setup_intent->status
198
-				|| 'canceled' === $setup_intent->status ) {
198
+				|| 'canceled' === $setup_intent->status) {
199 199
 				// These statuses should not be possible, as such we return an error.
200 200
 				$response = [
201 201
 					'status' => 'error',
202 202
 					'error'  => [
203 203
 						'type'    => 'setup_intent_error',
204
-						'message' => __( 'Failed to save payment method.', 'woocommerce-gateway-stripe' ),
204
+						'message' => __('Failed to save payment method.', 'woocommerce-gateway-stripe'),
205 205
 					],
206 206
 				];
207 207
 			} else {
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 					'status' => 'success',
212 212
 				];
213 213
 			}
214
-		} catch ( Exception $e ) {
214
+		} catch (Exception $e) {
215 215
 			$response = [
216 216
 				'status' => 'error',
217 217
 				'error'  => array(
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 			];
222 222
 		}
223 223
 
224
-		echo wp_json_encode( $response );
224
+		echo wp_json_encode($response);
225 225
 		exit;
226 226
 	}
227 227
 }
Please login to merge, or discard this patch.
tests/phpunit/test-wc-stripe-level-3-data.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -9,6 +9,9 @@
 block discarded – undo
9 9
  */
10 10
 class WC_Stripe_Level3_Data_Test extends WP_UnitTestCase {
11 11
 
12
+	/**
13
+	 * @param string $shipping_postcode
14
+	 */
12 15
 	protected function mock_level_3_order( $shipping_postcode, $with_fee = false ) {
13 16
 		// Setup the item.
14 17
 		$mock_item = $this->getMockBuilder( WC_Order_Item_Product::class )
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -9,117 +9,117 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class WC_Stripe_Level3_Data_Test extends WP_UnitTestCase {
11 11
 
12
-	protected function mock_level_3_order( $shipping_postcode, $with_fee = false ) {
12
+	protected function mock_level_3_order($shipping_postcode, $with_fee = false) {
13 13
 		// Setup the item.
14
-		$mock_item = $this->getMockBuilder( WC_Order_Item_Product::class )
14
+		$mock_item = $this->getMockBuilder(WC_Order_Item_Product::class)
15 15
 			->disableOriginalConstructor()
16
-			->setMethods( [ 'get_name', 'get_quantity', 'get_subtotal', 'get_total_tax', 'get_total', 'get_variation_id', 'get_product_id' ] )
16
+			->setMethods(['get_name', 'get_quantity', 'get_subtotal', 'get_total_tax', 'get_total', 'get_variation_id', 'get_product_id'])
17 17
 			->getMock();
18 18
 
19 19
 		$mock_item
20
-			->method( 'get_name' )
21
-			->will( $this->returnValue( 'Beanie with Logo' ) );
20
+			->method('get_name')
21
+			->will($this->returnValue('Beanie with Logo'));
22 22
 
23 23
 		$mock_item
24
-			->method( 'get_quantity' )
25
-			->will( $this->returnValue( 1 ) );
24
+			->method('get_quantity')
25
+			->will($this->returnValue(1));
26 26
 
27 27
 		$mock_item
28
-			->method( 'get_total' )
29
-			->will( $this->returnValue( 18 ) );
28
+			->method('get_total')
29
+			->will($this->returnValue(18));
30 30
 
31 31
 		$mock_item
32
-			->method( 'get_subtotal' )
33
-			->will( $this->returnValue( 18 ) );
32
+			->method('get_subtotal')
33
+			->will($this->returnValue(18));
34 34
 
35 35
 		$mock_item
36
-			->method( 'get_total_tax' )
37
-			->will( $this->returnValue( 2.7 ) );
36
+			->method('get_total_tax')
37
+			->will($this->returnValue(2.7));
38 38
 
39 39
 		$mock_item
40
-			->method( 'get_variation_id' )
41
-			->will( $this->returnValue( false ) );
40
+			->method('get_variation_id')
41
+			->will($this->returnValue(false));
42 42
 
43 43
 		$mock_item
44
-			->method( 'get_product_id' )
45
-			->will( $this->returnValue( 30 ) );
44
+			->method('get_product_id')
45
+			->will($this->returnValue(30));
46 46
 
47 47
 		$mock_items[] = $mock_item;
48 48
 
49
-		if ( $with_fee ) {
49
+		if ($with_fee) {
50 50
 			// Setup the fee.
51
-			$mock_fee = $this->getMockBuilder( WC_Order_Item_Fee::class )
51
+			$mock_fee = $this->getMockBuilder(WC_Order_Item_Fee::class)
52 52
 				->disableOriginalConstructor()
53
-				->setMethods( [ 'get_name', 'get_quantity', 'get_total_tax', 'get_total' ] )
53
+				->setMethods(['get_name', 'get_quantity', 'get_total_tax', 'get_total'])
54 54
 				->getMock();
55 55
 
56 56
 			$mock_fee
57
-				->method( 'get_name' )
58
-				->will( $this->returnValue( 'fee' ) );
57
+				->method('get_name')
58
+				->will($this->returnValue('fee'));
59 59
 
60 60
 			$mock_fee
61
-				->method( 'get_quantity' )
62
-				->will( $this->returnValue( 1 ) );
61
+				->method('get_quantity')
62
+				->will($this->returnValue(1));
63 63
 
64 64
 			$mock_fee
65
-				->method( 'get_total' )
66
-				->will( $this->returnValue( 10 ) );
65
+				->method('get_total')
66
+				->will($this->returnValue(10));
67 67
 
68 68
 			$mock_fee
69
-				->method( 'get_total_tax' )
70
-				->will( $this->returnValue( 1.5 ) );
69
+				->method('get_total_tax')
70
+				->will($this->returnValue(1.5));
71 71
 
72 72
 			$mock_items[] = $mock_fee;
73 73
 		}
74 74
 
75 75
 		// Setup the order.
76
-		$mock_order = $this->getMockBuilder( WC_Order::class )
76
+		$mock_order = $this->getMockBuilder(WC_Order::class)
77 77
 			->disableOriginalConstructor()
78
-			->setMethods( [ 'get_id', 'get_items', 'get_currency', 'get_shipping_total', 'get_shipping_tax', 'get_shipping_postcode' ] )
78
+			->setMethods(['get_id', 'get_items', 'get_currency', 'get_shipping_total', 'get_shipping_tax', 'get_shipping_postcode'])
79 79
 			->getMock();
80 80
 
81 81
 		$mock_order
82
-			->method( 'get_id' )
83
-			->will( $this->returnValue( 210 ) );
82
+			->method('get_id')
83
+			->will($this->returnValue(210));
84 84
 
85 85
 		$mock_order
86
-			->method( 'get_items' )
87
-			->will( $this->returnValue( $mock_items ) );
86
+			->method('get_items')
87
+			->will($this->returnValue($mock_items));
88 88
 
89 89
 		$mock_order
90
-			->method( 'get_currency' )
91
-			->will( $this->returnValue( 'USD' ) );
90
+			->method('get_currency')
91
+			->will($this->returnValue('USD'));
92 92
 
93 93
 		$mock_order
94
-			->method( 'get_shipping_total' )
95
-			->will( $this->returnValue( 30 ) );
94
+			->method('get_shipping_total')
95
+			->will($this->returnValue(30));
96 96
 
97 97
 		$mock_order
98
-			->method( 'get_shipping_tax' )
99
-			->will( $this->returnValue( 8 ) );
98
+			->method('get_shipping_tax')
99
+			->will($this->returnValue(8));
100 100
 
101 101
 		$mock_order
102
-			->method( 'get_shipping_postcode' )
103
-			->will( $this->returnValue( $shipping_postcode ) );
102
+			->method('get_shipping_postcode')
103
+			->will($this->returnValue($shipping_postcode));
104 104
 
105 105
 		return $mock_order;
106 106
 	}
107 107
 
108 108
 	public function test_data_for_mutli_item_order() {
109 109
 		$store_postcode = '90210';
110
-		update_option( 'woocommerce_store_postcode', $store_postcode );
110
+		update_option('woocommerce_store_postcode', $store_postcode);
111 111
 
112 112
 		// Arrange: Create a couple of products to use.
113 113
 		$variation_product = WC_Helper_Product::create_variation_product();
114 114
 		$variation_ids     = $variation_product->get_children();
115 115
 
116
-		$product_1 = wc_get_product ( $variation_ids[0] );
117
-		$product_1->set_regular_price( 19.19 );
118
-		$product_1->set_sale_price( 11.83 );
116
+		$product_1 = wc_get_product($variation_ids[0]);
117
+		$product_1->set_regular_price(19.19);
118
+		$product_1->set_sale_price(11.83);
119 119
 		$product_1->save();
120 120
 
121
-		$product_2 = wc_get_product( $variation_ids[1] );
122
-		$product_2->set_regular_price( 20.05 );
121
+		$product_2 = wc_get_product($variation_ids[1]);
122
+		$product_2->set_regular_price(20.05);
123 123
 		$product_2->save();
124 124
 
125 125
 		// Arrange: Set up an order with:
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 		// 2) The same product added several times.
128 128
 		// 3) A valid US ZIP code
129 129
 		$order = new WC_Order();
130
-		$order->set_shipping_postcode( '90210' );
131
-		$order->add_product( $product_1, 1 ); // Add one item of the first product variation
132
-		$order->add_product( $product_2, 2 ); // Add two items of the second product variation
130
+		$order->set_shipping_postcode('90210');
131
+		$order->add_product($product_1, 1); // Add one item of the first product variation
132
+		$order->add_product($product_2, 2); // Add two items of the second product variation
133 133
 
134 134
 		$order->save();
135 135
 		$order->calculate_totals();
136 136
 
137 137
 		// Act: Call get_level3_data_from_order().
138 138
 		$gateway = new WC_Gateway_Stripe();
139
-		$result = $gateway->get_level3_data_from_order( $order );
139
+		$result = $gateway->get_level3_data_from_order($order);
140 140
 
141 141
 		// Assert.
142 142
 		$this->assertEquals(
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 				'line_items' => array(
149 149
 					(object) array(
150 150
 						'product_code'        => (string) $product_1->get_id(),
151
-						'product_description' => substr( $product_1->get_name(), 0, 26 ),
151
+						'product_description' => substr($product_1->get_name(), 0, 26),
152 152
 						'unit_cost'           => 1183,
153 153
 						'quantity'            => 1,
154 154
 						'tax_amount'          => 0,
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 					),
157 157
 					(object) array(
158 158
 						'product_code'        => (string) $product_2->get_id(),
159
-						'product_description' => substr( $product_2->get_name(), 0, 26 ),
159
+						'product_description' => substr($product_2->get_name(), 0, 26),
160 160
 						'unit_cost'           => 2005,
161 161
 						'quantity'            => 2,
162 162
 						'tax_amount'          => 0,
@@ -168,14 +168,14 @@  discard block
 block discarded – undo
168 168
 		);
169 169
 
170 170
 		// Assert: Check that Stripe's total charge check passes.
171
-		$total_charged = WC_Stripe_Helper::get_stripe_amount( $order->get_total() );
172
-		$sum_of_unit_costs = array_reduce( $result['line_items'], function( $sum, $item ) {
171
+		$total_charged = WC_Stripe_Helper::get_stripe_amount($order->get_total());
172
+		$sum_of_unit_costs = array_reduce($result['line_items'], function($sum, $item) {
173 173
 			return $sum + $item->quantity * $item->unit_cost;
174 174
 		}  );
175
-		$sum_of_taxes = array_reduce( $result['line_items'], function( $sum, $item ) {
175
+		$sum_of_taxes = array_reduce($result['line_items'], function($sum, $item) {
176 176
 			return $sum + $item->tax_amount;
177 177
 		}  );
178
-		$sum_of_discounts = array_reduce( $result['line_items'], function( $sum, $item ) {
178
+		$sum_of_discounts = array_reduce($result['line_items'], function($sum, $item) {
179 179
 			return $sum + $item->discount_amount;
180 180
 		}  );
181 181
 		$shipping_amount = $result['shipping_amount'];
@@ -187,24 +187,24 @@  discard block
 block discarded – undo
187 187
 
188 188
 	public function test_non_us_shipping_zip_codes() {
189 189
 		// Update the store with the right post code.
190
-		update_option( 'woocommerce_store_postcode', 1040 );
190
+		update_option('woocommerce_store_postcode', 1040);
191 191
 
192 192
 		// Arrange: Create a couple of products to use.
193 193
 		$product = WC_Helper_Product::create_simple_product();
194
-		$product->set_regular_price( 19.19 );
194
+		$product->set_regular_price(19.19);
195 195
 		$product->save();
196 196
 
197 197
 		// Arrange: Set up an order with a non-US postcode.
198 198
 		$order = new WC_Order();
199
-		$order->set_shipping_postcode( '1050' );
200
-		$order->add_product( $product, 1 );
199
+		$order->set_shipping_postcode('1050');
200
+		$order->add_product($product, 1);
201 201
 		$order->save();
202 202
 		$order->calculate_totals();
203 203
 
204 204
 		// Act: Call get_level3_data_from_order().
205 205
 		$store_postcode = '1100';
206 206
 		$gateway = new WC_Gateway_Stripe();
207
-		$result = $gateway->get_level3_data_from_order( $order );
207
+		$result = $gateway->get_level3_data_from_order($order);
208 208
 
209 209
 		// Assert.
210 210
 		$this->assertEquals(
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 				'line_items' => array(
215 215
 					(object) array(
216 216
 						'product_code'        => (string) $product->get_id(),
217
-						'product_description' => substr( $product->get_name(), 0, 26 ),
217
+						'product_description' => substr($product->get_name(), 0, 26),
218 218
 						'unit_cost'           => 1919,
219 219
 						'quantity'            => 1,
220 220
 						'tax_amount'          => 0,
@@ -252,12 +252,12 @@  discard block
 block discarded – undo
252 252
 			'shipping_from_zip'    => '94110',
253 253
 		);
254 254
 
255
-		update_option( 'woocommerce_store_postcode', '94110' );
255
+		update_option('woocommerce_store_postcode', '94110');
256 256
 
257
-		$mock_order   = $this->mock_level_3_order( '98012', true );
257
+		$mock_order   = $this->mock_level_3_order('98012', true);
258 258
 		$gateway      = new WC_Gateway_Stripe();
259
-		$level_3_data = $gateway->get_level3_data_from_order( $mock_order );
259
+		$level_3_data = $gateway->get_level3_data_from_order($mock_order);
260 260
 
261
-		$this->assertEquals( $expected_data, $level_3_data );
261
+		$this->assertEquals($expected_data, $level_3_data);
262 262
 	}
263 263
 }
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
15 15
  *
16 16
  */
17 17
 
18
-if ( ! defined( 'ABSPATH' ) ) {
18
+if ( ! defined('ABSPATH')) {
19 19
 	exit;
20 20
 }
21 21
 
22 22
 /**
23 23
  * Required minimums and constants
24 24
  */
25
-define( 'WC_STRIPE_VERSION', '4.8.0' ); // WRCS: DEFINED_VERSION.
26
-define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' );
27
-define( 'WC_STRIPE_MIN_WC_VER', '3.0' );
28
-define( 'WC_STRIPE_FUTURE_MIN_WC_VER', '3.3' );
29
-define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
30
-define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
31
-define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
25
+define('WC_STRIPE_VERSION', '4.8.0'); // WRCS: DEFINED_VERSION.
26
+define('WC_STRIPE_MIN_PHP_VER', '5.6.0');
27
+define('WC_STRIPE_MIN_WC_VER', '3.0');
28
+define('WC_STRIPE_FUTURE_MIN_WC_VER', '3.3');
29
+define('WC_STRIPE_MAIN_FILE', __FILE__);
30
+define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
31
+define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
32 32
 
33 33
 // phpcs:disable WordPress.Files.FileName
34 34
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
  */
41 41
 function woocommerce_stripe_missing_wc_notice() {
42 42
 	/* translators: 1. URL link. */
43
-	echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Stripe requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-gateway-stripe' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>';
43
+	echo '<div class="error"><p><strong>' . sprintf(esc_html__('Stripe requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-gateway-stripe'), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>') . '</strong></p></div>';
44 44
 }
45 45
 
46 46
 /**
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
  */
52 52
 function woocommerce_stripe_wc_not_supported() {
53 53
 	/* translators: $1. Minimum WooCommerce version. $2. Current WooCommerce version. */
54
-	echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Stripe requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is no longer supported.', 'woocommerce-gateway-stripe' ), WC_STRIPE_MIN_WC_VER, WC_VERSION ) . '</strong></p></div>';
54
+	echo '<div class="error"><p><strong>' . sprintf(esc_html__('Stripe requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is no longer supported.', 'woocommerce-gateway-stripe'), WC_STRIPE_MIN_WC_VER, WC_VERSION) . '</strong></p></div>';
55 55
 }
56 56
 
57 57
 function woocommerce_gateway_stripe() {
58 58
 
59 59
 	static $plugin;
60 60
 
61
-	if ( ! isset( $plugin ) ) {
61
+	if ( ! isset($plugin)) {
62 62
 
63 63
 		class WC_Stripe {
64 64
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 			 * @return Singleton The *Singleton* instance.
74 74
 			 */
75 75
 			public static function get_instance() {
76
-				if ( null === self::$instance ) {
76
+				if (null === self::$instance) {
77 77
 					self::$instance = new self();
78 78
 				}
79 79
 				return self::$instance;
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 			 * *Singleton* via the `new` operator from outside of this class.
115 115
 			 */
116 116
 			public function __construct() {
117
-				add_action( 'admin_init', array( $this, 'install' ) );
117
+				add_action('admin_init', array($this, 'install'));
118 118
 
119 119
 				$this->init();
120 120
 
121 121
 				$this->api     = new WC_Stripe_Connect_API();
122
-				$this->connect = new WC_Stripe_Connect( $this->api );
122
+				$this->connect = new WC_Stripe_Connect($this->api);
123 123
 
124
-				add_action( 'rest_api_init', array( $this, 'register_connect_routes' ) );
124
+				add_action('rest_api_init', array($this, 'register_connect_routes'));
125 125
 			}
126 126
 
127 127
 			/**
@@ -131,57 +131,57 @@  discard block
 block discarded – undo
131 131
 			 * @version 4.0.0
132 132
 			 */
133 133
 			public function init() {
134
-				if ( is_admin() ) {
135
-					require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-privacy.php';
134
+				if (is_admin()) {
135
+					require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-privacy.php';
136 136
 				}
137 137
 
138
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php';
139
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php';
140
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php';
141
-				include_once dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php';
142
-				require_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php';
143
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php';
144
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php';
145
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php';
146
-				require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php';
147
-				require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php';
148
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php';
149
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php';
150
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php';
151
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php';
152
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php';
153
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php';
154
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php';
155
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php';
156
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php';
157
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php';
158
-				require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php';
159
-				require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php';
160
-				require_once dirname( __FILE__ ) . '/includes/connect/class-wc-stripe-connect.php';
161
-				require_once dirname( __FILE__ ) . '/includes/connect/class-wc-stripe-connect-api.php';
162
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php';
163
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php';
164
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php';
165
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-intent-controller.php';
166
-				require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-inbox-notes.php';
167
-
168
-				if ( is_admin() ) {
169
-					require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php';
138
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-exception.php';
139
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-logger.php';
140
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-helper.php';
141
+				include_once dirname(__FILE__) . '/includes/class-wc-stripe-api.php';
142
+				require_once dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php';
143
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php';
144
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php';
145
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php';
146
+				require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-pre-orders-compat.php';
147
+				require_once dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php';
148
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php';
149
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php';
150
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php';
151
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php';
152
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php';
153
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php';
154
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php';
155
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php';
156
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php';
157
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php';
158
+				require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-subs-compat.php';
159
+				require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php';
160
+				require_once dirname(__FILE__) . '/includes/connect/class-wc-stripe-connect.php';
161
+				require_once dirname(__FILE__) . '/includes/connect/class-wc-stripe-connect-api.php';
162
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php';
163
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php';
164
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-customer.php';
165
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-intent-controller.php';
166
+				require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-inbox-notes.php';
167
+
168
+				if (is_admin()) {
169
+					require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-admin-notices.php';
170 170
 				}
171 171
 
172 172
 				// REMOVE IN THE FUTURE.
173
-				require_once dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php';
173
+				require_once dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php';
174 174
 
175
-				add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
176
-				add_filter( 'pre_update_option_woocommerce_stripe_settings', array( $this, 'gateway_settings_update' ), 10, 2 );
177
-				add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
178
-				add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
175
+				add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
176
+				add_filter('pre_update_option_woocommerce_stripe_settings', array($this, 'gateway_settings_update'), 10, 2);
177
+				add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
178
+				add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
179 179
 
180 180
 				// Modify emails emails.
181
-				add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ), 20 );
181
+				add_filter('woocommerce_email_classes', array($this, 'add_emails'), 20);
182 182
 
183
-				if ( version_compare( WC_VERSION, '3.4', '<' ) ) {
184
-					add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) );
183
+				if (version_compare(WC_VERSION, '3.4', '<')) {
184
+					add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin'));
185 185
 				}
186 186
 			}
187 187
 
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
 			 * @version 4.0.0
193 193
 			 */
194 194
 			public function update_plugin_version() {
195
-				delete_option( 'wc_stripe_version' );
196
-				update_option( 'wc_stripe_version', WC_STRIPE_VERSION );
195
+				delete_option('wc_stripe_version');
196
+				update_option('wc_stripe_version', WC_STRIPE_VERSION);
197 197
 			}
198 198
 
199 199
 			/**
@@ -203,15 +203,15 @@  discard block
 block discarded – undo
203 203
 			 * @version 3.1.0
204 204
 			 */
205 205
 			public function install() {
206
-				if ( ! is_plugin_active( plugin_basename( __FILE__ ) ) ) {
206
+				if ( ! is_plugin_active(plugin_basename(__FILE__))) {
207 207
 					return;
208 208
 				}
209 209
 
210
-				if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) {
211
-					do_action( 'woocommerce_stripe_updated' );
210
+				if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) {
211
+					do_action('woocommerce_stripe_updated');
212 212
 
213
-					if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) {
214
-						define( 'WC_STRIPE_INSTALLING', true );
213
+					if ( ! defined('WC_STRIPE_INSTALLING')) {
214
+						define('WC_STRIPE_INSTALLING', true);
215 215
 					}
216 216
 
217 217
 					$this->update_plugin_version();
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
 			 * @since 1.0.0
225 225
 			 * @version 4.0.0
226 226
 			 */
227
-			public function plugin_action_links( $links ) {
227
+			public function plugin_action_links($links) {
228 228
 				$plugin_links = array(
229
-					'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
229
+					'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>',
230 230
 				);
231
-				return array_merge( $plugin_links, $links );
231
+				return array_merge($plugin_links, $links);
232 232
 			}
233 233
 
234 234
 			/**
@@ -239,13 +239,13 @@  discard block
 block discarded – undo
239 239
 			 * @param  string $file  Name of current file.
240 240
 			 * @return array  $links Update list of plugin links.
241 241
 			 */
242
-			public function plugin_row_meta( $links, $file ) {
243
-				if ( plugin_basename( __FILE__ ) === $file ) {
242
+			public function plugin_row_meta($links, $file) {
243
+				if (plugin_basename(__FILE__) === $file) {
244 244
 					$row_meta = array(
245
-						'docs'    => '<a href="' . esc_url( apply_filters( 'woocommerce_gateway_stripe_docs_url', 'https://docs.woocommerce.com/document/stripe/' ) ) . '" title="' . esc_attr( __( 'View Documentation', 'woocommerce-gateway-stripe' ) ) . '">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
246
-						'support' => '<a href="' . esc_url( apply_filters( 'woocommerce_gateway_stripe_support_url', 'https://woocommerce.com/my-account/create-a-ticket?select=18627' ) ) . '" title="' . esc_attr( __( 'Open a support request at WooCommerce.com', 'woocommerce-gateway-stripe' ) ) . '">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
245
+						'docs'    => '<a href="' . esc_url(apply_filters('woocommerce_gateway_stripe_docs_url', 'https://docs.woocommerce.com/document/stripe/')) . '" title="' . esc_attr(__('View Documentation', 'woocommerce-gateway-stripe')) . '">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>',
246
+						'support' => '<a href="' . esc_url(apply_filters('woocommerce_gateway_stripe_support_url', 'https://woocommerce.com/my-account/create-a-ticket?select=18627')) . '" title="' . esc_attr(__('Open a support request at WooCommerce.com', 'woocommerce-gateway-stripe')) . '">' . __('Support', 'woocommerce-gateway-stripe') . '</a>',
247 247
 					);
248
-					return array_merge( $links, $row_meta );
248
+					return array_merge($links, $row_meta);
249 249
 				}
250 250
 				return (array) $links;
251 251
 			}
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
 			 * @since 1.0.0
257 257
 			 * @version 4.0.0
258 258
 			 */
259
-			public function add_gateways( $methods ) {
260
-				if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
259
+			public function add_gateways($methods) {
260
+				if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
261 261
 					$methods[] = 'WC_Stripe_Subs_Compat';
262 262
 					$methods[] = 'WC_Stripe_Sepa_Subs_Compat';
263 263
 				} else {
@@ -283,28 +283,28 @@  discard block
 block discarded – undo
283 283
 			 * @since 4.0.0
284 284
 			 * @version 4.0.0
285 285
 			 */
286
-			public function filter_gateway_order_admin( $sections ) {
287
-				unset( $sections['stripe'] );
288
-				unset( $sections['stripe_bancontact'] );
289
-				unset( $sections['stripe_sofort'] );
290
-				unset( $sections['stripe_giropay'] );
291
-				unset( $sections['stripe_eps'] );
292
-				unset( $sections['stripe_ideal'] );
293
-				unset( $sections['stripe_p24'] );
294
-				unset( $sections['stripe_alipay'] );
295
-				unset( $sections['stripe_sepa'] );
296
-				unset( $sections['stripe_multibanco'] );
286
+			public function filter_gateway_order_admin($sections) {
287
+				unset($sections['stripe']);
288
+				unset($sections['stripe_bancontact']);
289
+				unset($sections['stripe_sofort']);
290
+				unset($sections['stripe_giropay']);
291
+				unset($sections['stripe_eps']);
292
+				unset($sections['stripe_ideal']);
293
+				unset($sections['stripe_p24']);
294
+				unset($sections['stripe_alipay']);
295
+				unset($sections['stripe_sepa']);
296
+				unset($sections['stripe_multibanco']);
297 297
 
298 298
 				$sections['stripe']            = 'Stripe';
299
-				$sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
300
-				$sections['stripe_sofort']     = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
301
-				$sections['stripe_giropay']    = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
302
-				$sections['stripe_eps']        = __( 'Stripe EPS', 'woocommerce-gateway-stripe' );
303
-				$sections['stripe_ideal']      = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
304
-				$sections['stripe_p24']        = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
305
-				$sections['stripe_alipay']     = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
306
-				$sections['stripe_sepa']       = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
307
-				$sections['stripe_multibanco'] = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' );
299
+				$sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
300
+				$sections['stripe_sofort']     = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
301
+				$sections['stripe_giropay']    = __('Stripe Giropay', 'woocommerce-gateway-stripe');
302
+				$sections['stripe_eps']        = __('Stripe EPS', 'woocommerce-gateway-stripe');
303
+				$sections['stripe_ideal']      = __('Stripe iDeal', 'woocommerce-gateway-stripe');
304
+				$sections['stripe_p24']        = __('Stripe P24', 'woocommerce-gateway-stripe');
305
+				$sections['stripe_alipay']     = __('Stripe Alipay', 'woocommerce-gateway-stripe');
306
+				$sections['stripe_sepa']       = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
307
+				$sections['stripe_multibanco'] = __('Stripe Multibanco', 'woocommerce-gateway-stripe');
308 308
 
309 309
 				return $sections;
310 310
 			}
@@ -319,12 +319,12 @@  discard block
 block discarded – undo
319 319
 			 * @param array|bool $old_settings Existing settings, if any.
320 320
 			 * @return array New value but with defaults initially filled in for missing settings.
321 321
 			 */
322
-			public function gateway_settings_update( $settings, $old_settings ) {
323
-				if ( false === $old_settings ) {
322
+			public function gateway_settings_update($settings, $old_settings) {
323
+				if (false === $old_settings) {
324 324
 					$gateway  = new WC_Gateway_Stripe();
325 325
 					$fields   = $gateway->get_form_fields();
326
-					$defaults = array_merge( array_fill_keys( array_keys( $fields ), '' ), wp_list_pluck( $fields, 'default' ) );
327
-					return array_merge( $defaults, $settings );
326
+					$defaults = array_merge(array_fill_keys(array_keys($fields), ''), wp_list_pluck($fields, 'default'));
327
+					return array_merge($defaults, $settings);
328 328
 				}
329 329
 				return $settings;
330 330
 			}
@@ -335,16 +335,16 @@  discard block
 block discarded – undo
335 335
 			 * @param WC_Email[] $email_classes All existing emails.
336 336
 			 * @return WC_Email[]
337 337
 			 */
338
-			public function add_emails( $email_classes ) {
338
+			public function add_emails($email_classes) {
339 339
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication.php';
340 340
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-renewal-authentication.php';
341 341
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-preorder-authentication.php';
342 342
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication-retry.php';
343 343
 
344 344
 				// Add all emails, generated by the gateway.
345
-				$email_classes['WC_Stripe_Email_Failed_Renewal_Authentication']  = new WC_Stripe_Email_Failed_Renewal_Authentication( $email_classes );
346
-				$email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication( $email_classes );
347
-				$email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry( $email_classes );
345
+				$email_classes['WC_Stripe_Email_Failed_Renewal_Authentication']  = new WC_Stripe_Email_Failed_Renewal_Authentication($email_classes);
346
+				$email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication($email_classes);
347
+				$email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry($email_classes);
348 348
 
349 349
 				return $email_classes;
350 350
 			}
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/connect/class-wc-stripe-connect-rest-oauth-init-controller.php';
359 359
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/connect/class-wc-stripe-connect-rest-oauth-connect-controller.php';
360 360
 
361
-				$oauth_init    = new WC_Stripe_Connect_REST_Oauth_Init_Controller( $this->connect, $this->api );
362
-				$oauth_connect = new WC_Stripe_Connect_REST_Oauth_Connect_Controller( $this->connect, $this->api );
361
+				$oauth_init    = new WC_Stripe_Connect_REST_Oauth_Init_Controller($this->connect, $this->api);
362
+				$oauth_connect = new WC_Stripe_Connect_REST_Oauth_Connect_Controller($this->connect, $this->api);
363 363
 
364 364
 				$oauth_init->register_routes();
365 365
 				$oauth_connect->register_routes();
@@ -373,18 +373,18 @@  discard block
 block discarded – undo
373 373
 	return $plugin;
374 374
 }
375 375
 
376
-add_action( 'plugins_loaded', 'woocommerce_gateway_stripe_init' );
376
+add_action('plugins_loaded', 'woocommerce_gateway_stripe_init');
377 377
 
378 378
 function woocommerce_gateway_stripe_init() {
379
-	load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
379
+	load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
380 380
 
381
-	if ( ! class_exists( 'WooCommerce' ) ) {
382
-		add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' );
381
+	if ( ! class_exists('WooCommerce')) {
382
+		add_action('admin_notices', 'woocommerce_stripe_missing_wc_notice');
383 383
 		return;
384 384
 	}
385 385
 
386
-	if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
387
-		add_action( 'admin_notices', 'woocommerce_stripe_wc_not_supported' );
386
+	if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
387
+		add_action('admin_notices', 'woocommerce_stripe_wc_not_supported');
388 388
 		return;
389 389
 	}
390 390
 
Please login to merge, or discard this patch.
tests/phpunit/test-wc-stripe.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@  discard block
 block discarded – undo
2 2
 
3 3
 class WC_Stripe_Test extends WP_UnitTestCase {
4 4
 	public function test_constants_defined() {
5
-		$this->assertTrue( defined( 'WC_STRIPE_VERSION' ) );
6
-		$this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) );
7
-		$this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) );
8
-		$this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) );
9
-		$this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) );
10
-		$this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) );
5
+		$this->assertTrue(defined('WC_STRIPE_VERSION'));
6
+		$this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER'));
7
+		$this->assertTrue(defined('WC_STRIPE_MIN_WC_VER'));
8
+		$this->assertTrue(defined('WC_STRIPE_MAIN_FILE'));
9
+		$this->assertTrue(defined('WC_STRIPE_PLUGIN_URL'));
10
+		$this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH'));
11 11
 	}
12 12
 
13 13
 	/**
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
 	 * This test will see if we're indeed converting the price correctly.
16 16
 	 */
17 17
 	public function test_price_conversion_before_send_to_stripe() {
18
-		$this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) );
19
-		$this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) );
20
-		$this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) );
21
-		$this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) );
22
-		$this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) );
18
+		$this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD'));
19
+		$this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY'));
20
+		$this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY'));
21
+		$this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50));
22
+		$this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD'));
23 23
 	}
24 24
 
25 25
 	/**
@@ -33,37 +33,37 @@  discard block
 block discarded – undo
33 33
 		$balance_fee1->net = 10000;
34 34
 		$balance_fee1->currency = 'USD';
35 35
 
36
-		$this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) );
36
+		$this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee'));
37 37
 
38 38
 		$balance_fee2 = new stdClass();
39 39
 		$balance_fee2->fee = 10500;
40 40
 		$balance_fee2->net = 10000;
41 41
 		$balance_fee2->currency = 'JPY';
42 42
 
43
-		$this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) );
43
+		$this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee'));
44 44
 
45 45
 		$balance_fee3 = new stdClass();
46 46
 		$balance_fee3->fee = 10500;
47 47
 		$balance_fee3->net = 10000;
48 48
 		$balance_fee3->currency = 'USD';
49 49
 
50
-		$this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) );
50
+		$this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net'));
51 51
 
52 52
 		$balance_fee4 = new stdClass();
53 53
 		$balance_fee4->fee = 10500;
54 54
 		$balance_fee4->net = 10000;
55 55
 		$balance_fee4->currency = 'JPY';
56 56
 
57
-		$this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) );
57
+		$this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net'));
58 58
 
59 59
 		$balance_fee5 = new stdClass();
60 60
 		$balance_fee5->fee = 10500;
61 61
 		$balance_fee5->net = 10000;
62 62
 		$balance_fee5->currency = 'USD';
63 63
 
64
-		$this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) );
64
+		$this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5));
65 65
 
66
-		$this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) );
66
+		$this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5));
67 67
 	}
68 68
 
69 69
 	/**
@@ -72,27 +72,27 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @dataProvider statement_descriptor_sanitation_provider
74 74
 	 */
75
-	public function test_statement_descriptor_sanitation( $original, $expected ) {
76
-		$this->assertEquals( $expected, WC_Stripe_Helper::clean_statement_descriptor( $original ) );
75
+	public function test_statement_descriptor_sanitation($original, $expected) {
76
+		$this->assertEquals($expected, WC_Stripe_Helper::clean_statement_descriptor($original));
77 77
 	}
78 78
 
79 79
 	public function statement_descriptor_sanitation_provider() {
80 80
 		return [
81
-			'removes \'' => [ 'Test\'s Store', 'Tests Store' ],
82
-			'removes "' => [ 'Test " Store', 'Test  Store' ],
83
-			'removes <' => [ 'Test < Store', 'Test  Store' ],
84
-			'removes >' => [ 'Test > Store', 'Test  Store' ],
85
-			'removes /' => [ 'Test / Store', 'Test  Store' ],
86
-			'removes (' => [ 'Test ( Store', 'Test  Store' ],
87
-			'removes )' => [ 'Test ) Store', 'Test  Store' ],
88
-			'removes {' => [ 'Test { Store', 'Test  Store' ],
89
-			'removes }' => [ 'Test } Store', 'Test  Store' ],
90
-			'removes \\' => [ 'Test \\ Store', 'Test  Store' ],
91
-			'removes *' => [ 'Test * Store', 'Test  Store' ],
92
-			'keeps at most 22 chars' => [ 'Test\'s Store > Driving Course Range', 'Tests Store  Driving C' ],
93
-			'mixed length, \' and >' => [ 'Test\'s Store > Driving Course Range', 'Tests Store  Driving C' ],
94
-			'mixed length, \' and <' => [ 'Test\'s Store < Driving Course Range', 'Tests Store  Driving C' ],
95
-			'mixed length, \' and "' => [ 'Test\'s Store " Driving Course Range', 'Tests Store  Driving C' ]
81
+			'removes \'' => ['Test\'s Store', 'Tests Store'],
82
+			'removes "' => ['Test " Store', 'Test  Store'],
83
+			'removes <' => ['Test < Store', 'Test  Store'],
84
+			'removes >' => ['Test > Store', 'Test  Store'],
85
+			'removes /' => ['Test / Store', 'Test  Store'],
86
+			'removes (' => ['Test ( Store', 'Test  Store'],
87
+			'removes )' => ['Test ) Store', 'Test  Store'],
88
+			'removes {' => ['Test { Store', 'Test  Store'],
89
+			'removes }' => ['Test } Store', 'Test  Store'],
90
+			'removes \\' => ['Test \\ Store', 'Test  Store'],
91
+			'removes *' => ['Test * Store', 'Test  Store'],
92
+			'keeps at most 22 chars' => ['Test\'s Store > Driving Course Range', 'Tests Store  Driving C'],
93
+			'mixed length, \' and >' => ['Test\'s Store > Driving Course Range', 'Tests Store  Driving C'],
94
+			'mixed length, \' and <' => ['Test\'s Store < Driving Course Range', 'Tests Store  Driving C'],
95
+			'mixed length, \' and "' => ['Test\'s Store " Driving Course Range', 'Tests Store  Driving C']
96 96
 		];
97 97
 	}
98 98
 }
Please login to merge, or discard this patch.
tests/phpunit/bootstrap.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@
 block discarded – undo
1 1
 <?php
2
-$_tests_dir = getenv( 'WP_TESTS_DIR' );
3
-if ( ! $_tests_dir ) {
2
+$_tests_dir = getenv('WP_TESTS_DIR');
3
+if ( ! $_tests_dir) {
4 4
 	$_tests_dir = '/tmp/wordpress-tests-lib';
5 5
 }
6 6
 
7 7
 require_once $_tests_dir . '/includes/functions.php';
8 8
 
9 9
 function _manually_load_plugin() {
10
-	$plugin_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/';
10
+	$plugin_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/';
11 11
 	require $plugin_dir . 'woocommerce/woocommerce.php';
12
-	require dirname( __FILE__ ) . '/setup.php';
12
+	require dirname(__FILE__) . '/setup.php';
13 13
 	require $plugin_dir . 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php';
14 14
 }
15 15
 
16
-tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
16
+tests_add_filter('muplugins_loaded', '_manually_load_plugin');
17 17
 
18 18
 require $_tests_dir . '/includes/bootstrap.php';
19 19
 
20
-$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/legacy/framework/';
21
-require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' );
20
+$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/legacy/framework/';
21
+require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php');
22 22
 //require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' );
23
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' );
24
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' );
25
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' );
26
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' );
27
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' );
28
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' );
23
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php');
24
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php');
25
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php');
26
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php');
27
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php');
28
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php');
Please login to merge, or discard this patch.
includes/class-wc-stripe-api.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * Set secret API Key.
27 27
 	 * @param string $key
28 28
 	 */
29
-	public static function set_secret_key( $secret_key ) {
29
+	public static function set_secret_key($secret_key) {
30 30
 		self::$secret_key = $secret_key;
31 31
 	}
32 32
 
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	 * @return string
36 36
 	 */
37 37
 	public static function get_secret_key() {
38
-		if ( ! self::$secret_key ) {
39
-			$options = get_option( 'woocommerce_stripe_settings' );
38
+		if ( ! self::$secret_key) {
39
+			$options = get_option('woocommerce_stripe_settings');
40 40
 
41
-			if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) {
42
-				self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] );
41
+			if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) {
42
+				self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']);
43 43
 			}
44 44
 		}
45 45
 		return self::$secret_key;
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 		return apply_filters(
82 82
 			'woocommerce_stripe_request_headers',
83 83
 			array(
84
-				'Authorization'              => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
84
+				'Authorization'              => 'Basic ' . base64_encode(self::get_secret_key() . ':'),
85 85
 				'Stripe-Version'             => self::STRIPE_API_VERSION,
86 86
 				'User-Agent'                 => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')',
87
-				'X-Stripe-Client-User-Agent' => json_encode( $user_agent ),
87
+				'X-Stripe-Client-User-Agent' => json_encode($user_agent),
88 88
 			)
89 89
 		);
90 90
 	}
@@ -101,16 +101,16 @@  discard block
 block discarded – undo
101 101
 	 * @return stdClass|array
102 102
 	 * @throws WC_Stripe_Exception
103 103
 	 */
104
-	public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) {
105
-		WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) );
104
+	public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) {
105
+		WC_Stripe_Logger::log("{$api} request: " . print_r($request, true));
106 106
 
107 107
 		$headers         = self::get_headers();
108 108
 		$idempotency_key = '';
109 109
 
110
-		if ( 'charges' === $api && 'POST' === $method ) {
111
-			$customer        = ! empty( $request['customer'] ) ? $request['customer'] : '';
112
-			$source          = ! empty( $request['source'] ) ? $request['source'] : $customer;
113
-			$idempotency_key = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request );
110
+		if ('charges' === $api && 'POST' === $method) {
111
+			$customer        = ! empty($request['customer']) ? $request['customer'] : '';
112
+			$source          = ! empty($request['source']) ? $request['source'] : $customer;
113
+			$idempotency_key = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request);
114 114
 
115 115
 			$headers['Idempotency-Key'] = $idempotency_key;
116 116
 		}
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
 			self::ENDPOINT . $api,
120 120
 			array(
121 121
 				'method'  => $method,
122
-				'headers' => apply_filters( 'woocommerce_stripe_request_header', $headers, ["api" => $api, "method" => $method]),
123
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
122
+				'headers' => apply_filters('woocommerce_stripe_request_header', $headers, ["api" => $api, "method" => $method]),
123
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
124 124
 				'timeout' => 70,
125 125
 			)
126 126
 		);
127 127
 
128
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
128
+		if (is_wp_error($response) || empty($response['body'])) {
129 129
 			WC_Stripe_Logger::log(
130
-				'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r(
130
+				'Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r(
131 131
 					array(
132 132
 						'api'             => $api,
133 133
 						'request'         => $request,
@@ -137,17 +137,17 @@  discard block
 block discarded – undo
137 137
 				)
138 138
 			);
139 139
 
140
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
140
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
141 141
 		}
142 142
 
143
-		if ( $with_headers ) {
143
+		if ($with_headers) {
144 144
 			return array(
145
-				'headers' => wp_remote_retrieve_headers( $response ),
146
-				'body'    => json_decode( $response['body'] ),
145
+				'headers' => wp_remote_retrieve_headers($response),
146
+				'body'    => json_decode($response['body']),
147 147
 			);
148 148
 		}
149 149
 
150
-		return json_decode( $response['body'] );
150
+		return json_decode($response['body']);
151 151
 	}
152 152
 
153 153
 	/**
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 * @version 4.0.0
158 158
 	 * @param string $api
159 159
 	 */
160
-	public static function retrieve( $api ) {
161
-		WC_Stripe_Logger::log( "{$api}" );
160
+	public static function retrieve($api) {
161
+		WC_Stripe_Logger::log("{$api}");
162 162
 
163 163
 		$response = wp_safe_remote_get(
164 164
 			self::ENDPOINT . $api,
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
 			)
170 170
 		);
171 171
 
172
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
173
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
174
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
172
+		if (is_wp_error($response) || empty($response['body'])) {
173
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
174
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
175 175
 		}
176 176
 
177
-		return json_decode( $response['body'] );
177
+		return json_decode($response['body']);
178 178
 	}
179 179
 
180 180
 	/**
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
 	 *
194 194
 	 * @return stdClass|array The response
195 195
 	 */
196
-	public static function request_with_level3_data( $request, $api, $level3_data, $order ) {
196
+	public static function request_with_level3_data($request, $api, $level3_data, $order) {
197 197
 		// Do not add level3 data it's the array is empty.
198
-		if ( empty( $level3_data ) ) {
198
+		if (empty($level3_data)) {
199 199
 			return self::request(
200 200
 				$request,
201 201
 				$api
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 
205 205
 		// If there's a transient indicating that level3 data was not accepted by
206 206
 		// Stripe in the past for this account, do not try to add level3 data.
207
-		if ( get_transient( 'wc_stripe_level3_not_allowed' ) ) {
207
+		if (get_transient('wc_stripe_level3_not_allowed')) {
208 208
 			return self::request(
209 209
 				$request,
210 210
 				$api
@@ -220,40 +220,40 @@  discard block
 block discarded – undo
220 220
 		);
221 221
 
222 222
 		$is_level3_param_not_allowed = (
223
-			isset( $result->error )
224
-			&& isset( $result->error->code )
223
+			isset($result->error)
224
+			&& isset($result->error->code)
225 225
 			&& 'parameter_unknown' === $result->error->code
226
-			&& isset( $result->error->param )
226
+			&& isset($result->error->param)
227 227
 			&& 'level3' === $result->error->param
228 228
 		);
229 229
 
230 230
 		$is_level_3data_incorrect = (
231
-			isset( $result->error )
232
-			&& isset( $result->error->type )
231
+			isset($result->error)
232
+			&& isset($result->error->type)
233 233
 			&& 'invalid_request_error' === $result->error->type
234 234
 		);
235 235
 
236
-		if ( $is_level3_param_not_allowed ) {
236
+		if ($is_level3_param_not_allowed) {
237 237
 			// Set a transient so that future requests do not add level 3 data.
238 238
 			// Transient is set to expire in 3 months, can be manually removed if needed.
239
-			set_transient( 'wc_stripe_level3_not_allowed', true, 3 * MONTH_IN_SECONDS );
240
-		} else if ( $is_level_3data_incorrect ) {
239
+			set_transient('wc_stripe_level3_not_allowed', true, 3 * MONTH_IN_SECONDS);
240
+		} else if ($is_level_3data_incorrect) {
241 241
 			// Log the issue so we could debug it.
242 242
 			WC_Stripe_Logger::log(
243 243
 				'Level3 data sum incorrect: ' . PHP_EOL
244
-				. print_r( $result->error->message, true ) . PHP_EOL
245
-				. print_r( 'Order line items: ', true ) . PHP_EOL
246
-				. print_r( $order->get_items(), true ) . PHP_EOL
247
-				. print_r( 'Order shipping amount: ', true ) . PHP_EOL
248
-				. print_r( $order->get_shipping_total(), true ) . PHP_EOL
249
-				. print_r( 'Order currency: ', true ) . PHP_EOL
250
-				. print_r( $order->get_currency(), true )
244
+				. print_r($result->error->message, true) . PHP_EOL
245
+				. print_r('Order line items: ', true) . PHP_EOL
246
+				. print_r($order->get_items(), true) . PHP_EOL
247
+				. print_r('Order shipping amount: ', true) . PHP_EOL
248
+				. print_r($order->get_shipping_total(), true) . PHP_EOL
249
+				. print_r('Order currency: ', true) . PHP_EOL
250
+				. print_r($order->get_currency(), true)
251 251
 			);
252 252
 		}
253 253
 
254 254
 		// Make the request again without level 3 data.
255
-		if ( $is_level3_param_not_allowed || $is_level_3data_incorrect ) {
256
-			unset( $request['level3'] );
255
+		if ($is_level3_param_not_allowed || $is_level_3data_incorrect) {
256
+			unset($request['level3']);
257 257
 			return WC_Stripe_API::request(
258 258
 				$request,
259 259
 				$api
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +329 added lines, -329 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
 
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	public function __construct() {
86 86
 		$this->retry_interval = 1;
87 87
 		$this->id             = 'stripe';
88
-		$this->method_title   = __( 'Stripe', 'woocommerce-gateway-stripe' );
88
+		$this->method_title   = __('Stripe', 'woocommerce-gateway-stripe');
89 89
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
90
-		$this->method_description = __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' );
90
+		$this->method_description = __('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe');
91 91
 		$this->has_fields         = true;
92 92
 		$this->supports           = array(
93 93
 			'products',
@@ -114,41 +114,41 @@  discard block
 block discarded – undo
114 114
 		$this->init_settings();
115 115
 
116 116
 		// Get setting values.
117
-		$this->title                = $this->get_option( 'title' );
118
-		$this->description          = $this->get_option( 'description' );
119
-		$this->enabled              = $this->get_option( 'enabled' );
120
-		$this->testmode             = 'yes' === $this->get_option( 'testmode' );
121
-		$this->inline_cc_form       = 'yes' === $this->get_option( 'inline_cc_form' );
122
-		$this->capture              = 'yes' === $this->get_option( 'capture', 'yes' );
123
-		$this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
124
-		$this->saved_cards          = 'yes' === $this->get_option( 'saved_cards' );
125
-		$this->secret_key           = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
126
-		$this->publishable_key      = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
127
-		$this->payment_request      = 'yes' === $this->get_option( 'payment_request', 'yes' );
128
-
129
-		WC_Stripe_API::set_secret_key( $this->secret_key );
117
+		$this->title                = $this->get_option('title');
118
+		$this->description          = $this->get_option('description');
119
+		$this->enabled              = $this->get_option('enabled');
120
+		$this->testmode             = 'yes' === $this->get_option('testmode');
121
+		$this->inline_cc_form       = 'yes' === $this->get_option('inline_cc_form');
122
+		$this->capture              = 'yes' === $this->get_option('capture', 'yes');
123
+		$this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
124
+		$this->saved_cards          = 'yes' === $this->get_option('saved_cards');
125
+		$this->secret_key           = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
126
+		$this->publishable_key      = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
127
+		$this->payment_request      = 'yes' === $this->get_option('payment_request', 'yes');
128
+
129
+		WC_Stripe_API::set_secret_key($this->secret_key);
130 130
 
131 131
 		// Hooks.
132
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
133
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
134
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
135
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ) );
136
-		add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_payout' ), 20 );
137
-		add_action( 'woocommerce_customer_save_address', array( $this, 'show_update_card_notice' ), 10, 2 );
138
-		add_filter( 'woocommerce_available_payment_gateways', array( $this, 'prepare_order_pay_page' ) );
139
-		add_action( 'woocommerce_account_view-order_endpoint', array( $this, 'check_intent_status_on_order_page' ), 1 );
140
-		add_filter( 'woocommerce_payment_successful_result', array( $this, 'modify_successful_payment_result' ), 99999, 2 );
141
-		add_action( 'set_logged_in_cookie', array( $this, 'set_cookie_on_current_request' ) );
142
-		add_filter( 'woocommerce_get_checkout_payment_url', array( $this, 'get_checkout_payment_url' ), 10, 2 );
143
-		add_filter( 'woocommerce_settings_api_sanitized_fields_' . $this->id, array( $this, 'settings_api_sanitized_fields' ) );
132
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
133
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
134
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
135
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_fee'));
136
+		add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_payout'), 20);
137
+		add_action('woocommerce_customer_save_address', array($this, 'show_update_card_notice'), 10, 2);
138
+		add_filter('woocommerce_available_payment_gateways', array($this, 'prepare_order_pay_page'));
139
+		add_action('woocommerce_account_view-order_endpoint', array($this, 'check_intent_status_on_order_page'), 1);
140
+		add_filter('woocommerce_payment_successful_result', array($this, 'modify_successful_payment_result'), 99999, 2);
141
+		add_action('set_logged_in_cookie', array($this, 'set_cookie_on_current_request'));
142
+		add_filter('woocommerce_get_checkout_payment_url', array($this, 'get_checkout_payment_url'), 10, 2);
143
+		add_filter('woocommerce_settings_api_sanitized_fields_' . $this->id, array($this, 'settings_api_sanitized_fields'));
144 144
 
145 145
 		// Note: display error is in the parent class.
146
-		add_action( 'admin_notices', array( $this, 'display_errors' ), 9999 );
146
+		add_action('admin_notices', array($this, 'display_errors'), 9999);
147 147
 
148
-		if ( WC_Stripe_Helper::is_pre_orders_exists() ) {
148
+		if (WC_Stripe_Helper::is_pre_orders_exists()) {
149 149
 			$this->pre_orders = new WC_Stripe_Pre_Orders_Compat();
150 150
 
151
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) );
151
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment'));
152 152
 		}
153 153
 	}
154 154
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 * @since 4.0.2
159 159
 	 */
160 160
 	public function is_available() {
161
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
161
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
162 162
 			return false;
163 163
 		}
164 164
 
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
 	 * @param int    $user_id      The ID of the current user.
173 173
 	 * @param string $load_address The address to load.
174 174
 	 */
175
-	public function show_update_card_notice( $user_id, $load_address ) {
176
-		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) {
175
+	public function show_update_card_notice($user_id, $load_address) {
176
+		if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) {
177 177
 			return;
178 178
 		}
179 179
 
180 180
 		/* translators: 1) Opening anchor tag 2) closing anchor tag */
181
-		wc_add_notice( sprintf( __( 'If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe' ), '<a href="' . esc_url( wc_get_endpoint_url( 'payment-methods' ) ) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>' ), 'notice' );
181
+		wc_add_notice(sprintf(__('If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe'), '<a href="' . esc_url(wc_get_endpoint_url('payment-methods')) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>'), 'notice');
182 182
 	}
183 183
 
184 184
 	/**
@@ -193,24 +193,24 @@  discard block
 block discarded – undo
193 193
 
194 194
 		$icons_str = '';
195 195
 
196
-		$icons_str .= isset( $icons['visa'] ) ? $icons['visa'] : '';
197
-		$icons_str .= isset( $icons['amex'] ) ? $icons['amex'] : '';
198
-		$icons_str .= isset( $icons['mastercard'] ) ? $icons['mastercard'] : '';
196
+		$icons_str .= isset($icons['visa']) ? $icons['visa'] : '';
197
+		$icons_str .= isset($icons['amex']) ? $icons['amex'] : '';
198
+		$icons_str .= isset($icons['mastercard']) ? $icons['mastercard'] : '';
199 199
 
200
-		if ( 'USD' === get_woocommerce_currency() ) {
201
-			$icons_str .= isset( $icons['discover'] ) ? $icons['discover'] : '';
202
-			$icons_str .= isset( $icons['jcb'] ) ? $icons['jcb'] : '';
203
-			$icons_str .= isset( $icons['diners'] ) ? $icons['diners'] : '';
200
+		if ('USD' === get_woocommerce_currency()) {
201
+			$icons_str .= isset($icons['discover']) ? $icons['discover'] : '';
202
+			$icons_str .= isset($icons['jcb']) ? $icons['jcb'] : '';
203
+			$icons_str .= isset($icons['diners']) ? $icons['diners'] : '';
204 204
 		}
205 205
 
206
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
206
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
207 207
 	}
208 208
 
209 209
 	/**
210 210
 	 * Initialise Gateway Settings Form Fields
211 211
 	 */
212 212
 	public function init_form_fields() {
213
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
213
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
214 214
 	}
215 215
 
216 216
 	/**
@@ -219,27 +219,27 @@  discard block
 block discarded – undo
219 219
 	public function payment_fields() {
220 220
 		global $wp;
221 221
 		$user                 = wp_get_current_user();
222
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
222
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
223 223
 		$total                = WC()->cart->total;
224 224
 		$user_email           = '';
225 225
 		$description          = $this->get_description();
226
-		$description          = ! empty( $description ) ? $description : '';
226
+		$description          = ! empty($description) ? $description : '';
227 227
 		$firstname            = '';
228 228
 		$lastname             = '';
229 229
 
230 230
 		// If paying from order, we need to get total from order not cart.
231
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { // wpcs: csrf ok.
232
-			$order      = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) ); // wpcs: csrf ok, sanitization ok.
231
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { // wpcs: csrf ok.
232
+			$order      = wc_get_order(wc_clean($wp->query_vars['order-pay'])); // wpcs: csrf ok, sanitization ok.
233 233
 			$total      = $order->get_total();
234 234
 			$user_email = $order->get_billing_email();
235 235
 		} else {
236
-			if ( $user->ID ) {
237
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
236
+			if ($user->ID) {
237
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
238 238
 				$user_email = $user_email ? $user_email : $user->user_email;
239 239
 			}
240 240
 		}
241 241
 
242
-		if ( is_add_payment_method_page() ) {
242
+		if (is_add_payment_method_page()) {
243 243
 			$firstname       = $user->user_firstname;
244 244
 			$lastname        = $user->user_lastname;
245 245
 		}
@@ -248,33 +248,33 @@  discard block
 block discarded – undo
248 248
 
249 249
 		echo '<div
250 250
 			id="stripe-payment-data"
251
-			data-email="' . esc_attr( $user_email ) . '"
252
-			data-full-name="' . esc_attr( $firstname . ' ' . $lastname ) . '"
253
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
251
+			data-email="' . esc_attr($user_email) . '"
252
+			data-full-name="' . esc_attr($firstname . ' ' . $lastname) . '"
253
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
254 254
 		>';
255 255
 
256
-		if ( $this->testmode ) {
256
+		if ($this->testmode) {
257 257
 			/* translators: link to Stripe testing page */
258
-			$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 <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
258
+			$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 <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
259 259
 		}
260 260
 
261
-		$description = trim( $description );
261
+		$description = trim($description);
262 262
 
263
-		echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); // wpcs: xss ok.
263
+		echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); // wpcs: xss ok.
264 264
 
265
-		if ( $display_tokenization ) {
265
+		if ($display_tokenization) {
266 266
 			$this->tokenization_script();
267 267
 			$this->saved_payment_methods();
268 268
 		}
269 269
 
270 270
 		$this->elements_form();
271 271
 
272
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { // wpcs: csrf ok.
272
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { // wpcs: csrf ok.
273 273
 
274 274
 			$this->save_payment_method_checkbox();
275 275
 		}
276 276
 
277
-		do_action( 'wc_stripe_cards_payment_fields', $this->id );
277
+		do_action('wc_stripe_cards_payment_fields', $this->id);
278 278
 
279 279
 		echo '</div>';
280 280
 
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
 	 */
290 290
 	public function elements_form() {
291 291
 		?>
292
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
293
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
292
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
293
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
294 294
 
295
-			<?php if ( $this->inline_cc_form ) { ?>
295
+			<?php if ($this->inline_cc_form) { ?>
296 296
 				<label for="card-element">
297
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
297
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
298 298
 				</label>
299 299
 
300 300
 				<div id="stripe-card-element" class="wc-stripe-elements-field">
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 				</div>
303 303
 			<?php } else { ?>
304 304
 				<div class="form-row form-row-wide">
305
-					<label for="stripe-card-element"><?php esc_html_e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
305
+					<label for="stripe-card-element"><?php esc_html_e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
306 306
 					<div class="stripe-card-group">
307 307
 						<div id="stripe-card-element" class="wc-stripe-elements-field">
308 308
 						<!-- a Stripe Element will be inserted here. -->
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 				</div>
314 314
 
315 315
 				<div class="form-row form-row-first">
316
-					<label for="stripe-exp-element"><?php esc_html_e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
316
+					<label for="stripe-exp-element"><?php esc_html_e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
317 317
 
318 318
 					<div id="stripe-exp-element" class="wc-stripe-elements-field">
319 319
 					<!-- a Stripe Element will be inserted here. -->
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 				</div>
322 322
 
323 323
 				<div class="form-row form-row-last">
324
-					<label for="stripe-cvc-element"><?php esc_html_e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
324
+					<label for="stripe-cvc-element"><?php esc_html_e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
325 325
 				<div id="stripe-cvc-element" class="wc-stripe-elements-field">
326 326
 				<!-- a Stripe Element will be inserted here. -->
327 327
 				</div>
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 			<!-- Used to display form errors -->
333 333
 			<div class="stripe-source-errors" role="alert"></div>
334 334
 			<br />
335
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
335
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
336 336
 			<div class="clear"></div>
337 337
 		</fieldset>
338 338
 		<?php
@@ -345,24 +345,24 @@  discard block
 block discarded – undo
345 345
 	 * @version 3.1.0
346 346
 	 */
347 347
 	public function admin_scripts() {
348
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
348
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
349 349
 			return;
350 350
 		}
351 351
 
352
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
352
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
353 353
 
354
-		wp_register_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
354
+		wp_register_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
355 355
 
356 356
 		$params = array(
357 357
 			'time'             => time(),
358 358
 			'i18n_out_of_sync' => wp_kses(
359
-				__( '<strong>Warning:</strong> your site\'s time does not match the time on your browser and may be incorrect. Some payment methods depend on webhook verification and verifying webhooks with a signing secret depends on your site\'s time being correct, so please check your site\'s time before setting a webhook secret. You may need to contact your site\'s hosting provider to correct the site\'s time.', 'woocommerce-gateway-stripe' ),
360
-				array( 'strong' => array() )
359
+				__('<strong>Warning:</strong> your site\'s time does not match the time on your browser and may be incorrect. Some payment methods depend on webhook verification and verifying webhooks with a signing secret depends on your site\'s time being correct, so please check your site\'s time before setting a webhook secret. You may need to contact your site\'s hosting provider to correct the site\'s time.', 'woocommerce-gateway-stripe'),
360
+				array('strong' => array())
361 361
 			),
362 362
 		);
363
-		wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_settings_params', $params );
363
+		wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_settings_params', $params);
364 364
 
365
-		wp_enqueue_script( 'woocommerce_stripe_admin' );
365
+		wp_enqueue_script('woocommerce_stripe_admin');
366 366
 	}
367 367
 
368 368
 	/**
@@ -379,54 +379,54 @@  discard block
 block discarded – undo
379 379
 			! is_product()
380 380
 			&& ! is_cart()
381 381
 			&& ! is_checkout()
382
-			&& ! isset( $_GET['pay_for_order'] ) // wpcs: csrf ok.
382
+			&& ! isset($_GET['pay_for_order']) // wpcs: csrf ok.
383 383
 			&& ! is_add_payment_method_page()
384
-			&& ! isset( $_GET['change_payment_method'] ) // wpcs: csrf ok.
385
-			&& ! ( ! empty( get_query_var( 'view-subscription' ) ) && is_callable( 'WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled' ) && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled() )
386
-			|| ( is_order_received_page() )
384
+			&& ! isset($_GET['change_payment_method']) // wpcs: csrf ok.
385
+			&& ! ( ! empty(get_query_var('view-subscription')) && is_callable('WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled') && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled())
386
+			|| (is_order_received_page())
387 387
 		) {
388 388
 			return;
389 389
 		}
390 390
 
391 391
 		// If Stripe is not enabled bail.
392
-		if ( 'no' === $this->enabled ) {
392
+		if ('no' === $this->enabled) {
393 393
 			return;
394 394
 		}
395 395
 
396 396
 		// If keys are not set bail.
397
-		if ( ! $this->are_keys_set() ) {
398
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
397
+		if ( ! $this->are_keys_set()) {
398
+			WC_Stripe_Logger::log('Keys are not set correctly.');
399 399
 			return;
400 400
 		}
401 401
 
402 402
 		// If no SSL bail.
403
-		if ( ! $this->testmode && ! is_ssl() ) {
404
-			WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' );
403
+		if ( ! $this->testmode && ! is_ssl()) {
404
+			WC_Stripe_Logger::log('Stripe live mode requires SSL.');
405 405
 			return;
406 406
 		}
407 407
 
408 408
 		$current_theme = wp_get_theme();
409 409
 
410
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
410
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
411 411
 
412
-		wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
413
-		wp_enqueue_style( 'stripe_styles' );
412
+		wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
413
+		wp_enqueue_style('stripe_styles');
414 414
 
415
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
416
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
415
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
416
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
417 417
 
418 418
 		$stripe_params = array(
419 419
 			'key'                  => $this->publishable_key,
420
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
421
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
420
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
421
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
422 422
 		);
423 423
 
424 424
 		// If we're on the pay page we need to pass stripe.js the address of the order.
425
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { // wpcs: csrf ok.
426
-			$order_id = wc_clean( $wp->query_vars['order-pay'] ); // wpcs: csrf ok, sanitization ok, xss ok.
427
-			$order    = wc_get_order( $order_id );
425
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { // wpcs: csrf ok.
426
+			$order_id = wc_clean($wp->query_vars['order-pay']); // wpcs: csrf ok, sanitization ok, xss ok.
427
+			$order    = wc_get_order($order_id);
428 428
 
429
-			if ( is_a( $order, 'WC_Order' ) ) {
429
+			if (is_a($order, 'WC_Order')) {
430 430
 				$stripe_params['billing_first_name'] = $order->get_billing_first_name();
431 431
 				$stripe_params['billing_last_name']  = $order->get_billing_last_name();
432 432
 				$stripe_params['billing_address_1']  = $order->get_billing_address_1();
@@ -441,41 +441,41 @@  discard block
 block discarded – undo
441 441
 		$sepa_elements_options = apply_filters(
442 442
 			'wc_stripe_sepa_elements_options',
443 443
 			array(
444
-				'supportedCountries' => array( 'SEPA' ),
444
+				'supportedCountries' => array('SEPA'),
445 445
 				'placeholderCountry' => WC()->countries->get_base_country(),
446
-				'style'              => array( 'base' => array( 'fontSize' => '15px' ) ),
446
+				'style'              => array('base' => array('fontSize' => '15px')),
447 447
 			)
448 448
 		);
449 449
 
450
-		$stripe_params['no_prepaid_card_msg']       = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
451
-		$stripe_params['no_sepa_owner_msg']         = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
452
-		$stripe_params['no_sepa_iban_msg']          = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
453
-		$stripe_params['payment_intent_error']      = __( 'We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe' );
454
-		$stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
455
-		$stripe_params['allow_prepaid_card']        = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
450
+		$stripe_params['no_prepaid_card_msg']       = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
451
+		$stripe_params['no_sepa_owner_msg']         = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
452
+		$stripe_params['no_sepa_iban_msg']          = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
453
+		$stripe_params['payment_intent_error']      = __('We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe');
454
+		$stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
455
+		$stripe_params['allow_prepaid_card']        = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
456 456
 		$stripe_params['inline_cc_form']            = $this->inline_cc_form ? 'yes' : 'no';
457
-		$stripe_params['is_checkout']               = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; // wpcs: csrf ok.
457
+		$stripe_params['is_checkout']               = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; // wpcs: csrf ok.
458 458
 		$stripe_params['return_url']                = $this->get_stripe_return_url();
459
-		$stripe_params['ajaxurl']                   = WC_AJAX::get_endpoint( '%%endpoint%%' );
460
-		$stripe_params['stripe_nonce']              = wp_create_nonce( '_wc_stripe_nonce' );
459
+		$stripe_params['ajaxurl']                   = WC_AJAX::get_endpoint('%%endpoint%%');
460
+		$stripe_params['stripe_nonce']              = wp_create_nonce('_wc_stripe_nonce');
461 461
 		$stripe_params['statement_descriptor']      = $this->statement_descriptor;
462
-		$stripe_params['elements_options']          = apply_filters( 'wc_stripe_elements_options', array() );
462
+		$stripe_params['elements_options']          = apply_filters('wc_stripe_elements_options', array());
463 463
 		$stripe_params['sepa_elements_options']     = $sepa_elements_options;
464
-		$stripe_params['invalid_owner_name']        = __( 'Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe' );
465
-		$stripe_params['is_change_payment_page']    = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; // wpcs: csrf ok.
466
-		$stripe_params['is_add_payment_page']       = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no';
467
-		$stripe_params['is_pay_for_order_page']     = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no';
468
-		$stripe_params['elements_styling']          = apply_filters( 'wc_stripe_elements_styling', false );
469
-		$stripe_params['elements_classes']          = apply_filters( 'wc_stripe_elements_classes', false );
470
-		$stripe_params['add_card_nonce']            = wp_create_nonce( 'wc_stripe_create_si' );
464
+		$stripe_params['invalid_owner_name']        = __('Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe');
465
+		$stripe_params['is_change_payment_page']    = isset($_GET['change_payment_method']) ? 'yes' : 'no'; // wpcs: csrf ok.
466
+		$stripe_params['is_add_payment_page']       = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no';
467
+		$stripe_params['is_pay_for_order_page']     = is_wc_endpoint_url('order-pay') ? 'yes' : 'no';
468
+		$stripe_params['elements_styling']          = apply_filters('wc_stripe_elements_styling', false);
469
+		$stripe_params['elements_classes']          = apply_filters('wc_stripe_elements_classes', false);
470
+		$stripe_params['add_card_nonce']            = wp_create_nonce('wc_stripe_create_si');
471 471
 
472 472
 		// Merge localized messages to be use in JS.
473
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
473
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
474 474
 
475
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
475
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
476 476
 
477 477
 		$this->tokenization_script();
478
-		wp_enqueue_script( 'woocommerce_stripe' );
478
+		wp_enqueue_script('woocommerce_stripe');
479 479
 	}
480 480
 
481 481
 	/**
@@ -486,14 +486,14 @@  discard block
 block discarded – undo
486 486
 	 * @param object $prepared_source The object with source details.
487 487
 	 * @throws WC_Stripe_Exception An exception if the card is prepaid, but prepaid cards are not allowed.
488 488
 	 */
489
-	public function maybe_disallow_prepaid_card( $prepared_source ) {
489
+	public function maybe_disallow_prepaid_card($prepared_source) {
490 490
 		// Check if we don't allow prepaid credit cards.
491
-		if ( apply_filters( 'wc_stripe_allow_prepaid_card', true ) || ! $this->is_prepaid_card( $prepared_source->source_object ) ) {
491
+		if (apply_filters('wc_stripe_allow_prepaid_card', true) || ! $this->is_prepaid_card($prepared_source->source_object)) {
492 492
 			return;
493 493
 		}
494 494
 
495
-		$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
496
-		throw new WC_Stripe_Exception( print_r( $prepared_source->source_object, true ), $localized_message );
495
+		$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
496
+		throw new WC_Stripe_Exception(print_r($prepared_source->source_object, true), $localized_message);
497 497
 	}
498 498
 
499 499
 	/**
@@ -503,10 +503,10 @@  discard block
 block discarded – undo
503 503
 	 * @param  object $prepared_source The source that should be verified.
504 504
 	 * @throws WC_Stripe_Exception     An exception if the source ID is missing.
505 505
 	 */
506
-	public function check_source( $prepared_source ) {
507
-		if ( empty( $prepared_source->source ) ) {
508
-			$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
509
-			throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
506
+	public function check_source($prepared_source) {
507
+		if (empty($prepared_source->source)) {
508
+			$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
509
+			throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
510 510
 		}
511 511
 	}
512 512
 
@@ -518,13 +518,13 @@  discard block
 block discarded – undo
518 518
 	 * @param WC_Order $order The order those payment is being processed.
519 519
 	 * @return bool           A flag that indicates that the customer does not exist and should be removed.
520 520
 	 */
521
-	public function maybe_remove_non_existent_customer( $error, $order ) {
522
-		if ( ! $this->is_no_such_customer_error( $error ) ) {
521
+	public function maybe_remove_non_existent_customer($error, $order) {
522
+		if ( ! $this->is_no_such_customer_error($error)) {
523 523
 			return false;
524 524
 		}
525 525
 
526
-		delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
527
-		$order->delete_meta_data( '_stripe_customer_id' );
526
+		delete_user_option($order->get_customer_id(), '_stripe_customer_id');
527
+		$order->delete_meta_data('_stripe_customer_id');
528 528
 		$order->save();
529 529
 
530 530
 		return true;
@@ -539,15 +539,15 @@  discard block
 block discarded – undo
539 539
 	 * @param boolean  $force_save_source Whether the payment source must be saved, like when dealing with a Subscription setup.
540 540
 	 * @return array                      Redirection data for `process_payment`.
541 541
 	 */
542
-	public function complete_free_order( $order, $prepared_source, $force_save_source ) {
543
-		if ( $force_save_source ) {
544
-			$intent_secret = $this->setup_intent( $order, $prepared_source );
542
+	public function complete_free_order($order, $prepared_source, $force_save_source) {
543
+		if ($force_save_source) {
544
+			$intent_secret = $this->setup_intent($order, $prepared_source);
545 545
 
546
-			if ( ! empty( $intent_secret ) ) {
546
+			if ( ! empty($intent_secret)) {
547 547
 				// `get_return_url()` must be called immediately before returning a value.
548 548
 				return array(
549 549
 					'result'              => 'success',
550
-					'redirect'            => $this->get_return_url( $order ),
550
+					'redirect'            => $this->get_return_url($order),
551 551
 					'setup_intent_secret' => $intent_secret,
552 552
 				);
553 553
 			}
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 		// Return thank you page redirect.
562 562
 		return array(
563 563
 			'result'   => 'success',
564
-			'redirect' => $this->get_return_url( $order ),
564
+			'redirect' => $this->get_return_url($order),
565 565
 		);
566 566
 	}
567 567
 
@@ -579,81 +579,81 @@  discard block
 block discarded – undo
579 579
 	 * @throws Exception If payment will not be accepted.
580 580
 	 * @return array|void
581 581
 	 */
582
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false ) {
582
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false) {
583 583
 		try {
584
-			$order = wc_get_order( $order_id );
584
+			$order = wc_get_order($order_id);
585 585
 
586 586
 			// ToDo: `process_pre_order` saves the source to the order for a later payment.
587 587
 			// This might not work well with PaymentIntents.
588
-			if ( $this->maybe_process_pre_orders( $order_id ) ) {
589
-				return $this->pre_orders->process_pre_order( $order_id );
588
+			if ($this->maybe_process_pre_orders($order_id)) {
589
+				return $this->pre_orders->process_pre_order($order_id);
590 590
 			}
591 591
 
592 592
 			// Check whether there is an existing intent.
593
-			$intent = $this->get_intent_from_order( $order );
594
-			if ( isset( $intent->object ) && 'setup_intent' === $intent->object ) {
593
+			$intent = $this->get_intent_from_order($order);
594
+			if (isset($intent->object) && 'setup_intent' === $intent->object) {
595 595
 				$intent = false; // This function can only deal with *payment* intents
596 596
 			}
597 597
 
598 598
 			$stripe_customer_id = null;
599
-			if ( $intent && ! empty( $intent->customer ) ) {
599
+			if ($intent && ! empty($intent->customer)) {
600 600
 				$stripe_customer_id = $intent->customer;
601 601
 			}
602 602
 
603 603
 			// For some payments the source should already be present in the order.
604
-			if ( $use_order_source ) {
605
-				$prepared_source = $this->prepare_order_source( $order );
604
+			if ($use_order_source) {
605
+				$prepared_source = $this->prepare_order_source($order);
606 606
 			} else {
607
-				$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source, $stripe_customer_id );
607
+				$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source, $stripe_customer_id);
608 608
 			}
609 609
 
610
-			$this->maybe_disallow_prepaid_card( $prepared_source );
611
-			$this->check_source( $prepared_source );
612
-			$this->save_source_to_order( $order, $prepared_source );
610
+			$this->maybe_disallow_prepaid_card($prepared_source);
611
+			$this->check_source($prepared_source);
612
+			$this->save_source_to_order($order, $prepared_source);
613 613
 
614
-			if ( 0 >= $order->get_total() ) {
615
-				return $this->complete_free_order( $order, $prepared_source, $force_save_source );
614
+			if (0 >= $order->get_total()) {
615
+				return $this->complete_free_order($order, $prepared_source, $force_save_source);
616 616
 			}
617 617
 
618 618
 			// This will throw exception if not valid.
619
-			$this->validate_minimum_order_amount( $order );
619
+			$this->validate_minimum_order_amount($order);
620 620
 
621
-			WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
621
+			WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
622 622
 
623
-			if ( $intent ) {
624
-				$intent = $this->update_existing_intent( $intent, $order, $prepared_source );
623
+			if ($intent) {
624
+				$intent = $this->update_existing_intent($intent, $order, $prepared_source);
625 625
 			} else {
626
-				$intent = $this->create_intent( $order, $prepared_source );
626
+				$intent = $this->create_intent($order, $prepared_source);
627 627
 			}
628 628
 
629 629
 			// Confirm the intent after locking the order to make sure webhooks will not interfere.
630
-			if ( empty( $intent->error ) ) {
631
-				$this->lock_order_payment( $order, $intent );
632
-				$intent = $this->confirm_intent( $intent, $order, $prepared_source );
630
+			if (empty($intent->error)) {
631
+				$this->lock_order_payment($order, $intent);
632
+				$intent = $this->confirm_intent($intent, $order, $prepared_source);
633 633
 			}
634 634
 
635
-			if ( ! empty( $intent->error ) ) {
636
-				$this->maybe_remove_non_existent_customer( $intent->error, $order );
635
+			if ( ! empty($intent->error)) {
636
+				$this->maybe_remove_non_existent_customer($intent->error, $order);
637 637
 
638 638
 				// We want to retry.
639
-				if ( $this->is_retryable_error( $intent->error ) ) {
640
-					return $this->retry_after_error( $intent, $order, $retry, $force_save_source, $previous_error, $use_order_source );
639
+				if ($this->is_retryable_error($intent->error)) {
640
+					return $this->retry_after_error($intent, $order, $retry, $force_save_source, $previous_error, $use_order_source);
641 641
 				}
642 642
 
643
-				$this->unlock_order_payment( $order );
644
-				$this->throw_localized_message( $intent, $order );
643
+				$this->unlock_order_payment($order);
644
+				$this->throw_localized_message($intent, $order);
645 645
 			}
646 646
 
647
-			if ( ! empty( $intent ) ) {
647
+			if ( ! empty($intent)) {
648 648
 				// Use the last charge within the intent to proceed.
649
-				$response = end( $intent->charges->data );
649
+				$response = end($intent->charges->data);
650 650
 
651 651
 				// If the intent requires a 3DS flow, redirect to it.
652
-				if ( 'requires_action' === $intent->status ) {
653
-					$this->unlock_order_payment( $order );
652
+				if ('requires_action' === $intent->status) {
653
+					$this->unlock_order_payment($order);
654 654
 
655
-					if ( is_wc_endpoint_url( 'order-pay' ) ) {
656
-						$redirect_url = add_query_arg( 'wc-stripe-confirmation', 1, $order->get_checkout_payment_url( false ) );
655
+					if (is_wc_endpoint_url('order-pay')) {
656
+						$redirect_url = add_query_arg('wc-stripe-confirmation', 1, $order->get_checkout_payment_url(false));
657 657
 
658 658
 						return array(
659 659
 							'result'   => 'success',
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
 
669 669
 						return array(
670 670
 							'result'                => 'success',
671
-							'redirect'              => $this->get_return_url( $order ),
671
+							'redirect'              => $this->get_return_url($order),
672 672
 							'payment_intent_secret' => $intent->client_secret,
673 673
 						);
674 674
 					}
@@ -676,30 +676,30 @@  discard block
 block discarded – undo
676 676
 			}
677 677
 
678 678
 			// Process valid response.
679
-			$this->process_response( $response, $order );
679
+			$this->process_response($response, $order);
680 680
 
681 681
 			// Remove cart.
682
-			if ( isset( WC()->cart ) ) {
682
+			if (isset(WC()->cart)) {
683 683
 				WC()->cart->empty_cart();
684 684
 			}
685 685
 
686 686
 			// Unlock the order.
687
-			$this->unlock_order_payment( $order );
687
+			$this->unlock_order_payment($order);
688 688
 
689 689
 			// Return thank you page redirect.
690 690
 			return array(
691 691
 				'result'   => 'success',
692
-				'redirect' => $this->get_return_url( $order ),
692
+				'redirect' => $this->get_return_url($order),
693 693
 			);
694 694
 
695
-		} catch ( WC_Stripe_Exception $e ) {
696
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
697
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
695
+		} catch (WC_Stripe_Exception $e) {
696
+			wc_add_notice($e->getLocalizedMessage(), 'error');
697
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
698 698
 
699
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
699
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
700 700
 
701 701
 			/* translators: error message */
702
-			$order->update_status( 'failed' );
702
+			$order->update_status('failed');
703 703
 
704 704
 			return array(
705 705
 				'result'   => 'fail',
@@ -715,17 +715,17 @@  discard block
 block discarded – undo
715 715
 	 *
716 716
 	 * @param int $order_id The ID of the order.
717 717
 	 */
718
-	public function display_order_fee( $order_id ) {
719
-		if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) {
718
+	public function display_order_fee($order_id) {
719
+		if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) {
720 720
 			return;
721 721
 		}
722 722
 
723
-		$order = wc_get_order( $order_id );
723
+		$order = wc_get_order($order_id);
724 724
 
725
-		$fee      = WC_Stripe_Helper::get_stripe_fee( $order );
726
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
725
+		$fee      = WC_Stripe_Helper::get_stripe_fee($order);
726
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
727 727
 
728
-		if ( ! $fee || ! $currency ) {
728
+		if ( ! $fee || ! $currency) {
729 729
 			return;
730 730
 		}
731 731
 
@@ -733,12 +733,12 @@  discard block
 block discarded – undo
733 733
 
734 734
 		<tr>
735 735
 			<td class="label stripe-fee">
736
-				<?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?>
737
-				<?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?>
736
+				<?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?>
737
+				<?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?>
738 738
 			</td>
739 739
 			<td width="1%"></td>
740 740
 			<td class="total">
741
-				-&nbsp;<?php echo wc_price( $fee, array( 'currency' => $currency ) ); // wpcs: xss ok. ?>
741
+				-&nbsp;<?php echo wc_price($fee, array('currency' => $currency)); // wpcs: xss ok. ?>
742 742
 			</td>
743 743
 		</tr>
744 744
 
@@ -752,17 +752,17 @@  discard block
 block discarded – undo
752 752
 	 *
753 753
 	 * @param int $order_id The ID of the order.
754 754
 	 */
755
-	public function display_order_payout( $order_id ) {
756
-		if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) {
755
+	public function display_order_payout($order_id) {
756
+		if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) {
757 757
 			return;
758 758
 		}
759 759
 
760
-		$order = wc_get_order( $order_id );
760
+		$order = wc_get_order($order_id);
761 761
 
762
-		$net      = WC_Stripe_Helper::get_stripe_net( $order );
763
-		$currency = WC_Stripe_Helper::get_stripe_currency( $order );
762
+		$net      = WC_Stripe_Helper::get_stripe_net($order);
763
+		$currency = WC_Stripe_Helper::get_stripe_currency($order);
764 764
 
765
-		if ( ! $net || ! $currency ) {
765
+		if ( ! $net || ! $currency) {
766 766
 			return;
767 767
 		}
768 768
 
@@ -770,12 +770,12 @@  discard block
 block discarded – undo
770 770
 
771 771
 		<tr>
772 772
 			<td class="label stripe-payout">
773
-				<?php echo wc_help_tip( __( 'This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?>
774
-				<?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?>
773
+				<?php echo wc_help_tip(__('This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?>
774
+				<?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?>
775 775
 			</td>
776 776
 			<td width="1%"></td>
777 777
 			<td class="total">
778
-				<?php echo wc_price( $net, array( 'currency' => $currency ) ); // wpcs: xss ok. ?>
778
+				<?php echo wc_price($net, array('currency' => $currency)); // wpcs: xss ok. ?>
779 779
 			</td>
780 780
 		</tr>
781 781
 
@@ -791,13 +791,13 @@  discard block
 block discarded – undo
791 791
 	 *
792 792
 	 * @return string The localized error message.
793 793
 	 */
794
-	public function get_localized_error_message_from_response( $response ) {
794
+	public function get_localized_error_message_from_response($response) {
795 795
 		$localized_messages = WC_Stripe_Helper::get_localized_messages();
796 796
 
797
-		if ( 'card_error' === $response->error->type ) {
798
-			$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
797
+		if ('card_error' === $response->error->type) {
798
+			$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
799 799
 		} else {
800
-			$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
800
+			$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
801 801
 		}
802 802
 
803 803
 		return $localized_message;
@@ -811,12 +811,12 @@  discard block
 block discarded – undo
811 811
 	 * @param  WC_Order $order     The order to add a note to.
812 812
 	 * @throws WC_Stripe_Exception An exception with the right message.
813 813
 	 */
814
-	public function throw_localized_message( $response, $order ) {
815
-		$localized_message = $this->get_localized_error_message_from_response( $response );
814
+	public function throw_localized_message($response, $order) {
815
+		$localized_message = $this->get_localized_error_message_from_response($response);
816 816
 
817
-		$order->add_order_note( $localized_message );
817
+		$order->add_order_note($localized_message);
818 818
 
819
-		throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
819
+		throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
820 820
 	}
821 821
 
822 822
 	/**
@@ -832,22 +832,22 @@  discard block
 block discarded – undo
832 832
 	 * @throws WC_Stripe_Exception        If the payment is not accepted.
833 833
 	 * @return array|void
834 834
 	 */
835
-	public function retry_after_error( $response, $order, $retry, $force_save_source, $previous_error, $use_order_source ) {
836
-		if ( ! $retry ) {
837
-			$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
838
-			$order->add_order_note( $localized_message );
839
-			throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.
835
+	public function retry_after_error($response, $order, $retry, $force_save_source, $previous_error, $use_order_source) {
836
+		if ( ! $retry) {
837
+			$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
838
+			$order->add_order_note($localized_message);
839
+			throw new WC_Stripe_Exception(print_r($response, true), $localized_message); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.
840 840
 		}
841 841
 
842 842
 		// Don't do anymore retries after this.
843
-		if ( 5 <= $this->retry_interval ) {
844
-			return $this->process_payment( $order->get_id(), false, $force_save_source, $response->error, $previous_error );
843
+		if (5 <= $this->retry_interval) {
844
+			return $this->process_payment($order->get_id(), false, $force_save_source, $response->error, $previous_error);
845 845
 		}
846 846
 
847
-		sleep( $this->retry_interval );
847
+		sleep($this->retry_interval);
848 848
 		$this->retry_interval++;
849 849
 
850
-		return $this->process_payment( $order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source );
850
+		return $this->process_payment($order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source);
851 851
 	}
852 852
 
853 853
 	/**
@@ -858,23 +858,23 @@  discard block
 block discarded – undo
858 858
 	 * @param WC_Payment_Gateway[] $gateways A list of all available gateways.
859 859
 	 * @return WC_Payment_Gateway[]          Either the same list or an empty one in the right conditions.
860 860
 	 */
861
-	public function prepare_order_pay_page( $gateways ) {
862
-		if ( ! is_wc_endpoint_url( 'order-pay' ) || ! isset( $_GET['wc-stripe-confirmation'] ) ) { // wpcs: csrf ok.
861
+	public function prepare_order_pay_page($gateways) {
862
+		if ( ! is_wc_endpoint_url('order-pay') || ! isset($_GET['wc-stripe-confirmation'])) { // wpcs: csrf ok.
863 863
 			return $gateways;
864 864
 		}
865 865
 
866 866
 		try {
867 867
 			$this->prepare_intent_for_order_pay_page();
868
-		} catch ( WC_Stripe_Exception $e ) {
868
+		} catch (WC_Stripe_Exception $e) {
869 869
 			// Just show the full order pay page if there was a problem preparing the Payment Intent
870 870
 			return $gateways;
871 871
 		}
872 872
 
873
-		add_filter( 'woocommerce_checkout_show_terms', '__return_false' );
874
-		add_filter( 'woocommerce_pay_order_button_html', '__return_false' );
875
-		add_filter( 'woocommerce_available_payment_gateways', '__return_empty_array' );
876
-		add_filter( 'woocommerce_no_available_payment_methods_message', array( $this, 'change_no_available_methods_message' ) );
877
-		add_action( 'woocommerce_pay_order_after_submit', array( $this, 'render_payment_intent_inputs' ) );
873
+		add_filter('woocommerce_checkout_show_terms', '__return_false');
874
+		add_filter('woocommerce_pay_order_button_html', '__return_false');
875
+		add_filter('woocommerce_available_payment_gateways', '__return_empty_array');
876
+		add_filter('woocommerce_no_available_payment_methods_message', array($this, 'change_no_available_methods_message'));
877
+		add_action('woocommerce_pay_order_after_submit', array($this, 'render_payment_intent_inputs'));
878 878
 
879 879
 		return array();
880 880
 	}
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
 	 * @return string the new message.
888 888
 	 */
889 889
 	public function change_no_available_methods_message() {
890
-		return wpautop( __( "Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe' ) );
890
+		return wpautop(__("Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe'));
891 891
 	}
892 892
 
893 893
 	/**
@@ -898,19 +898,19 @@  discard block
 block discarded – undo
898 898
 	 * @throws WC_Stripe_Exception
899 899
 	 * @since 4.3
900 900
 	 */
901
-	public function prepare_intent_for_order_pay_page( $order = null ) {
902
-		if ( ! isset( $order ) || empty( $order ) ) {
903
-			$order = wc_get_order( absint( get_query_var( 'order-pay' ) ) );
901
+	public function prepare_intent_for_order_pay_page($order = null) {
902
+		if ( ! isset($order) || empty($order)) {
903
+			$order = wc_get_order(absint(get_query_var('order-pay')));
904 904
 		}
905
-		$intent = $this->get_intent_from_order( $order );
905
+		$intent = $this->get_intent_from_order($order);
906 906
 
907
-		if ( ! $intent ) {
908
-			throw new WC_Stripe_Exception( 'Payment Intent not found', __( 'Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe' ) );
907
+		if ( ! $intent) {
908
+			throw new WC_Stripe_Exception('Payment Intent not found', __('Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe'));
909 909
 		}
910 910
 
911
-		if ( 'requires_payment_method' === $intent->status && isset( $intent->last_payment_error )
912
-		     && 'authentication_required' === $intent->last_payment_error->code ) {
913
-			$level3_data = $this->get_level3_data_from_order( $order );
911
+		if ('requires_payment_method' === $intent->status && isset($intent->last_payment_error)
912
+		     && 'authentication_required' === $intent->last_payment_error->code) {
913
+			$level3_data = $this->get_level3_data_from_order($order);
914 914
 			$intent      = WC_Stripe_API::request_with_level3_data(
915 915
 				array(
916 916
 					'payment_method' => $intent->last_payment_error->source->id,
@@ -920,8 +920,8 @@  discard block
 block discarded – undo
920 920
 				$order
921 921
 			);
922 922
 
923
-			if ( isset( $intent->error ) ) {
924
-				throw new WC_Stripe_Exception( print_r( $intent, true ), $intent->error->message );
923
+			if (isset($intent->error)) {
924
+				throw new WC_Stripe_Exception(print_r($intent, true), $intent->error->message);
925 925
 			}
926 926
 		}
927 927
 
@@ -936,26 +936,26 @@  discard block
 block discarded – undo
936 936
 	 * @throws WC_Stripe_Exception
937 937
 	 * @since 4.2
938 938
 	 */
939
-	public function render_payment_intent_inputs( $order = null ) {
940
-		if ( ! isset( $order ) || empty( $order ) ) {
941
-			$order = wc_get_order( absint( get_query_var( 'order-pay' ) ) );
939
+	public function render_payment_intent_inputs($order = null) {
940
+		if ( ! isset($order) || empty($order)) {
941
+			$order = wc_get_order(absint(get_query_var('order-pay')));
942 942
 		}
943
-		if ( ! isset( $this->order_pay_intent ) ) {
944
-			$this->prepare_intent_for_order_pay_page( $order );
943
+		if ( ! isset($this->order_pay_intent)) {
944
+			$this->prepare_intent_for_order_pay_page($order);
945 945
 		}
946 946
 
947 947
 		$verification_url = add_query_arg(
948 948
 			array(
949 949
 				'order'            => $order->get_id(),
950
-				'nonce'            => wp_create_nonce( 'wc_stripe_confirm_pi' ),
951
-				'redirect_to'      => rawurlencode( $this->get_return_url( $order ) ),
950
+				'nonce'            => wp_create_nonce('wc_stripe_confirm_pi'),
951
+				'redirect_to'      => rawurlencode($this->get_return_url($order)),
952 952
 				'is_pay_for_order' => true,
953 953
 			),
954
-			WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' )
954
+			WC_AJAX::get_endpoint('wc_stripe_verify_intent')
955 955
 		);
956 956
 
957
-		echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr( $this->order_pay_intent->client_secret ) . '" />';
958
-		echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr( $verification_url ) . '" />';
957
+		echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr($this->order_pay_intent->client_secret) . '" />';
958
+		echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr($verification_url) . '" />';
959 959
 	}
960 960
 
961 961
 	/**
@@ -965,11 +965,11 @@  discard block
 block discarded – undo
965 965
 	 * @param WC_Payment_Token $token Payment Token.
966 966
 	 * @return string                 Generated payment method HTML
967 967
 	 */
968
-	public function get_saved_payment_method_option_html( $token ) {
969
-		$html          = parent::get_saved_payment_method_option_html( $token );
968
+	public function get_saved_payment_method_option_html($token) {
969
+		$html          = parent::get_saved_payment_method_option_html($token);
970 970
 		$error_wrapper = '<div class="stripe-source-errors" role="alert"></div>';
971 971
 
972
-		return preg_replace( '~</(\w+)>\s*$~', "$error_wrapper</$1>", $html );
972
+		return preg_replace('~</(\w+)>\s*$~', "$error_wrapper</$1>", $html);
973 973
 	}
974 974
 
975 975
 	/**
@@ -979,18 +979,18 @@  discard block
 block discarded – undo
979 979
 	 * @since 4.2.0
980 980
 	 * @param int $order_id The ID that will be used for the thank you page.
981 981
 	 */
982
-	public function check_intent_status_on_order_page( $order_id ) {
983
-		if ( empty( $order_id ) || absint( $order_id ) <= 0 ) {
982
+	public function check_intent_status_on_order_page($order_id) {
983
+		if (empty($order_id) || absint($order_id) <= 0) {
984 984
 			return;
985 985
 		}
986 986
 
987
-		$order = wc_get_order( absint( $order_id ) );
987
+		$order = wc_get_order(absint($order_id));
988 988
 
989
-		if ( ! $order ) {
989
+		if ( ! $order) {
990 990
 			return;
991 991
 		}
992 992
 
993
-		$this->verify_intent_after_checkout( $order );
993
+		$this->verify_intent_after_checkout($order);
994 994
 	}
995 995
 
996 996
 	/**
@@ -1004,8 +1004,8 @@  discard block
 block discarded – undo
1004 1004
 	 * @param int   $order_id The ID of the order which is being paid for.
1005 1005
 	 * @return array
1006 1006
 	 */
1007
-	public function modify_successful_payment_result( $result, $order_id ) {
1008
-		if ( ! isset( $result['payment_intent_secret'] ) && ! isset( $result['setup_intent_secret'] ) ) {
1007
+	public function modify_successful_payment_result($result, $order_id) {
1008
+		if ( ! isset($result['payment_intent_secret']) && ! isset($result['setup_intent_secret'])) {
1009 1009
 			// Only redirects with intents need to be modified.
1010 1010
 			return $result;
1011 1011
 		}
@@ -1014,16 +1014,16 @@  discard block
 block discarded – undo
1014 1014
 		$verification_url = add_query_arg(
1015 1015
 			array(
1016 1016
 				'order'       => $order_id,
1017
-				'nonce'       => wp_create_nonce( 'wc_stripe_confirm_pi' ),
1018
-				'redirect_to' => rawurlencode( $result['redirect'] ),
1017
+				'nonce'       => wp_create_nonce('wc_stripe_confirm_pi'),
1018
+				'redirect_to' => rawurlencode($result['redirect']),
1019 1019
 			),
1020
-			WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' )
1020
+			WC_AJAX::get_endpoint('wc_stripe_verify_intent')
1021 1021
 		);
1022 1022
 
1023
-		if ( isset( $result['payment_intent_secret'] ) ) {
1024
-			$redirect = sprintf( '#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode( $verification_url ) );
1025
-		} else if ( isset( $result['setup_intent_secret'] ) ) {
1026
-			$redirect = sprintf( '#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode( $verification_url ) );
1023
+		if (isset($result['payment_intent_secret'])) {
1024
+			$redirect = sprintf('#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode($verification_url));
1025
+		} else if (isset($result['setup_intent_secret'])) {
1026
+			$redirect = sprintf('#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode($verification_url));
1027 1027
 		}
1028 1028
 
1029 1029
 		return array(
@@ -1035,8 +1035,8 @@  discard block
 block discarded – undo
1035 1035
 	/**
1036 1036
 	 * Proceed with current request using new login session (to ensure consistent nonce).
1037 1037
 	 */
1038
-	public function set_cookie_on_current_request( $cookie ) {
1039
-		$_COOKIE[ LOGGED_IN_COOKIE ] = $cookie;
1038
+	public function set_cookie_on_current_request($cookie) {
1039
+		$_COOKIE[LOGGED_IN_COOKIE] = $cookie;
1040 1040
 	}
1041 1041
 
1042 1042
 	/**
@@ -1046,48 +1046,48 @@  discard block
 block discarded – undo
1046 1046
 	 * @since 4.2.0
1047 1047
 	 * @param WC_Order $order The order which is in a transitional state.
1048 1048
 	 */
1049
-	public function verify_intent_after_checkout( $order ) {
1049
+	public function verify_intent_after_checkout($order) {
1050 1050
 		$payment_method = $order->get_payment_method();
1051
-		if ( $payment_method !== $this->id ) {
1051
+		if ($payment_method !== $this->id) {
1052 1052
 			// If this is not the payment method, an intent would not be available.
1053 1053
 			return;
1054 1054
 		}
1055 1055
 
1056
-		$intent = $this->get_intent_from_order( $order );
1057
-		if ( ! $intent ) {
1056
+		$intent = $this->get_intent_from_order($order);
1057
+		if ( ! $intent) {
1058 1058
 			// No intent, redirect to the order received page for further actions.
1059 1059
 			return;
1060 1060
 		}
1061 1061
 
1062 1062
 		// A webhook might have modified or locked the order while the intent was retreived. This ensures we are reading the right status.
1063
-		clean_post_cache( $order->get_id() );
1064
-		$order = wc_get_order( $order->get_id() );
1063
+		clean_post_cache($order->get_id());
1064
+		$order = wc_get_order($order->get_id());
1065 1065
 
1066
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
1066
+		if ( ! $order->has_status(array('pending', 'failed'))) {
1067 1067
 			// If payment has already been completed, this function is redundant.
1068 1068
 			return;
1069 1069
 		}
1070 1070
 
1071
-		if ( $this->lock_order_payment( $order, $intent ) ) {
1071
+		if ($this->lock_order_payment($order, $intent)) {
1072 1072
 			return;
1073 1073
 		}
1074 1074
 
1075
-		if ( 'setup_intent' === $intent->object && 'succeeded' === $intent->status ) {
1075
+		if ('setup_intent' === $intent->object && 'succeeded' === $intent->status) {
1076 1076
 			WC()->cart->empty_cart();
1077
-			if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) {
1078
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
1077
+			if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) {
1078
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
1079 1079
 			} else {
1080 1080
 				$order->payment_complete();
1081 1081
 			}
1082
-		} else if ( 'succeeded' === $intent->status || 'requires_capture' === $intent->status ) {
1082
+		} else if ('succeeded' === $intent->status || 'requires_capture' === $intent->status) {
1083 1083
 			// Proceed with the payment completion.
1084
-			$this->handle_intent_verification_success( $order, $intent );
1085
-		} else if ( 'requires_payment_method' === $intent->status ) {
1084
+			$this->handle_intent_verification_success($order, $intent);
1085
+		} else if ('requires_payment_method' === $intent->status) {
1086 1086
 			// `requires_payment_method` means that SCA got denied for the current payment method.
1087
-			$this->handle_intent_verification_failure( $order, $intent );
1087
+			$this->handle_intent_verification_failure($order, $intent);
1088 1088
 		}
1089 1089
 
1090
-		$this->unlock_order_payment( $order );
1090
+		$this->unlock_order_payment($order);
1091 1091
 	}
1092 1092
 
1093 1093
 	/**
@@ -1097,8 +1097,8 @@  discard block
 block discarded – undo
1097 1097
 	 * @param WC_Order $order The order whose verification succeeded.
1098 1098
 	 * @param stdClass $intent The Payment Intent object.
1099 1099
 	 */
1100
-	protected function handle_intent_verification_success( $order, $intent ) {
1101
-		$this->process_response( end( $intent->charges->data ), $order );
1100
+	protected function handle_intent_verification_success($order, $intent) {
1101
+		$this->process_response(end($intent->charges->data), $order);
1102 1102
 	}
1103 1103
 
1104 1104
 	/**
@@ -1108,8 +1108,8 @@  discard block
 block discarded – undo
1108 1108
 	 * @param WC_Order $order The order whose verification failed.
1109 1109
 	 * @param stdClass $intent The Payment Intent object.
1110 1110
 	 */
1111
-	protected function handle_intent_verification_failure( $order, $intent ) {
1112
-		$this->failed_sca_auth( $order, $intent );
1111
+	protected function handle_intent_verification_failure($order, $intent) {
1112
+		$this->failed_sca_auth($order, $intent);
1113 1113
 	}
1114 1114
 
1115 1115
 	/**
@@ -1119,18 +1119,18 @@  discard block
 block discarded – undo
1119 1119
 	 * @param WC_Order $order  The order which should be checked.
1120 1120
 	 * @param object   $intent The intent, associated with the order.
1121 1121
 	 */
1122
-	public function failed_sca_auth( $order, $intent ) {
1122
+	public function failed_sca_auth($order, $intent) {
1123 1123
 		// If the order has already failed, do not repeat the same message.
1124
-		if ( $order->has_status( 'failed' ) ) {
1124
+		if ($order->has_status('failed')) {
1125 1125
 			return;
1126 1126
 		}
1127 1127
 
1128 1128
 		// Load the right message and update the status.
1129
-		$status_message = isset( $intent->last_payment_error )
1129
+		$status_message = isset($intent->last_payment_error)
1130 1130
 			/* translators: 1) The error message that was received from Stripe. */
1131
-			? sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $intent->last_payment_error->message )
1132
-			: __( 'Stripe SCA authentication failed.', 'woocommerce-gateway-stripe' );
1133
-		$order->update_status( 'failed', $status_message );
1131
+			? sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $intent->last_payment_error->message)
1132
+			: __('Stripe SCA authentication failed.', 'woocommerce-gateway-stripe');
1133
+		$order->update_status('failed', $status_message);
1134 1134
 	}
1135 1135
 
1136 1136
 	/**
@@ -1141,10 +1141,10 @@  discard block
 block discarded – undo
1141 1141
 	 *
1142 1142
 	 * @return string Checkout URL for the given order.
1143 1143
 	 */
1144
-	public function get_checkout_payment_url( $pay_url, $order ) {
1144
+	public function get_checkout_payment_url($pay_url, $order) {
1145 1145
 		global $wp;
1146
-		if ( isset( $_GET['wc-stripe-confirmation'] ) && isset( $wp->query_vars['order-pay'] ) && $wp->query_vars['order-pay'] == $order->get_id() ) {
1147
-			$pay_url = add_query_arg( 'wc-stripe-confirmation', 1, $pay_url );
1146
+		if (isset($_GET['wc-stripe-confirmation']) && isset($wp->query_vars['order-pay']) && $wp->query_vars['order-pay'] == $order->get_id()) {
1147
+			$pay_url = add_query_arg('wc-stripe-confirmation', 1, $pay_url);
1148 1148
 		}
1149 1149
 		return $pay_url;
1150 1150
 	}
@@ -1154,63 +1154,63 @@  discard block
 block discarded – undo
1154 1154
 	 */
1155 1155
 	public function process_admin_options() {
1156 1156
 		// Load all old values before the new settings get saved.
1157
-		$old_publishable_key      = $this->get_option( 'publishable_key' );
1158
-		$old_secret_key           = $this->get_option( 'secret_key' );
1159
-		$old_test_publishable_key = $this->get_option( 'test_publishable_key' );
1160
-		$old_test_secret_key      = $this->get_option( 'test_secret_key' );
1157
+		$old_publishable_key      = $this->get_option('publishable_key');
1158
+		$old_secret_key           = $this->get_option('secret_key');
1159
+		$old_test_publishable_key = $this->get_option('test_publishable_key');
1160
+		$old_test_secret_key      = $this->get_option('test_secret_key');
1161 1161
 
1162 1162
 		parent::process_admin_options();
1163 1163
 
1164 1164
 		// Load all old values after the new settings have been saved.
1165
-		$new_publishable_key      = $this->get_option( 'publishable_key' );
1166
-		$new_secret_key           = $this->get_option( 'secret_key' );
1167
-		$new_test_publishable_key = $this->get_option( 'test_publishable_key' );
1168
-		$new_test_secret_key      = $this->get_option( 'test_secret_key' );
1165
+		$new_publishable_key      = $this->get_option('publishable_key');
1166
+		$new_secret_key           = $this->get_option('secret_key');
1167
+		$new_test_publishable_key = $this->get_option('test_publishable_key');
1168
+		$new_test_secret_key      = $this->get_option('test_secret_key');
1169 1169
 
1170 1170
 		// Checks whether a value has transitioned from a non-empty value to a new one.
1171
-		$has_changed = function( $old_value, $new_value ) {
1172
-			return ! empty( $old_value ) && ( $old_value !== $new_value );
1171
+		$has_changed = function($old_value, $new_value) {
1172
+			return ! empty($old_value) && ($old_value !== $new_value);
1173 1173
 		};
1174 1174
 
1175 1175
 		// Look for updates.
1176 1176
 		if (
1177
-			$has_changed( $old_publishable_key, $new_publishable_key )
1178
-			|| $has_changed( $old_secret_key, $new_secret_key )
1179
-			|| $has_changed( $old_test_publishable_key, $new_test_publishable_key )
1180
-			|| $has_changed( $old_test_secret_key, $new_test_secret_key )
1177
+			$has_changed($old_publishable_key, $new_publishable_key)
1178
+			|| $has_changed($old_secret_key, $new_secret_key)
1179
+			|| $has_changed($old_test_publishable_key, $new_test_publishable_key)
1180
+			|| $has_changed($old_test_secret_key, $new_test_secret_key)
1181 1181
 		) {
1182
-			update_option( 'wc_stripe_show_changed_keys_notice', 'yes' );
1182
+			update_option('wc_stripe_show_changed_keys_notice', 'yes');
1183 1183
 		}
1184 1184
 	}
1185 1185
 
1186
-	public function validate_publishable_key_field( $key, $value ) {
1187
-		$value = $this->validate_text_field( $key, $value );
1188
-		if ( ! empty( $value ) && ! preg_match( '/^pk_live_/', $value ) ) {
1189
-			throw new Exception( __( 'The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1186
+	public function validate_publishable_key_field($key, $value) {
1187
+		$value = $this->validate_text_field($key, $value);
1188
+		if ( ! empty($value) && ! preg_match('/^pk_live_/', $value)) {
1189
+			throw new Exception(__('The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe'));
1190 1190
 		}
1191 1191
 		return $value;
1192 1192
 	}
1193 1193
 
1194
-	public function validate_secret_key_field( $key, $value ) {
1195
-		$value = $this->validate_text_field( $key, $value );
1196
-		if ( ! empty( $value ) && ! preg_match( '/^[rs]k_live_/', $value ) ) {
1197
-			throw new Exception( __( 'The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1194
+	public function validate_secret_key_field($key, $value) {
1195
+		$value = $this->validate_text_field($key, $value);
1196
+		if ( ! empty($value) && ! preg_match('/^[rs]k_live_/', $value)) {
1197
+			throw new Exception(__('The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe'));
1198 1198
 		}
1199 1199
 		return $value;
1200 1200
 	}
1201 1201
 
1202
-	public function validate_test_publishable_key_field( $key, $value ) {
1203
-		$value = $this->validate_text_field( $key, $value );
1204
-		if ( ! empty( $value ) && ! preg_match( '/^pk_test_/', $value ) ) {
1205
-			throw new Exception( __( 'The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1202
+	public function validate_test_publishable_key_field($key, $value) {
1203
+		$value = $this->validate_text_field($key, $value);
1204
+		if ( ! empty($value) && ! preg_match('/^pk_test_/', $value)) {
1205
+			throw new Exception(__('The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe'));
1206 1206
 		}
1207 1207
 		return $value;
1208 1208
 	}
1209 1209
 
1210
-	public function validate_test_secret_key_field( $key, $value ) {
1211
-		$value = $this->validate_text_field( $key, $value );
1212
-		if ( ! empty( $value ) && ! preg_match( '/^[rs]k_test_/', $value ) ) {
1213
-			throw new Exception( __( 'The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1210
+	public function validate_test_secret_key_field($key, $value) {
1211
+		$value = $this->validate_text_field($key, $value);
1212
+		if ( ! empty($value) && ! preg_match('/^[rs]k_test_/', $value)) {
1213
+			throw new Exception(__('The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe'));
1214 1214
 		}
1215 1215
 		return $value;
1216 1216
 	}
@@ -1222,10 +1222,10 @@  discard block
 block discarded – undo
1222 1222
 	 * @param $settings WC_Settings_API settings to be filtered
1223 1223
 	 * @return Filtered settings
1224 1224
 	 */
1225
-	public function settings_api_sanitized_fields( $settings ) {
1226
-		if ( is_array( $settings ) ) {
1227
-			if ( array_key_exists( 'statement_descriptor', $settings ) ) {
1228
-				$settings['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $settings['statement_descriptor']);
1225
+	public function settings_api_sanitized_fields($settings) {
1226
+		if (is_array($settings)) {
1227
+			if (array_key_exists('statement_descriptor', $settings)) {
1228
+				$settings['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($settings['statement_descriptor']);
1229 1229
 			}
1230 1230
 		}
1231 1231
 		return $settings;
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +260 added lines, -260 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
 
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	public function __construct() {
41 41
 		$this->retry_interval = 2;
42
-		$stripe_settings      = get_option( 'woocommerce_stripe_settings', array() );
43
-		$this->testmode       = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false;
44
-		$secret_key           = ( $this->testmode ? 'test_' : '' ) . 'webhook_secret';
45
-		$this->secret         = ! empty( $stripe_settings[ $secret_key ] ) ? $stripe_settings[ $secret_key ] : false;
42
+		$stripe_settings      = get_option('woocommerce_stripe_settings', array());
43
+		$this->testmode       = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false;
44
+		$secret_key           = ($this->testmode ? 'test_' : '') . 'webhook_secret';
45
+		$this->secret         = ! empty($stripe_settings[$secret_key]) ? $stripe_settings[$secret_key] : false;
46 46
 
47
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
47
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
48 48
 	}
49 49
 
50 50
 	/**
@@ -54,26 +54,26 @@  discard block
 block discarded – undo
54 54
 	 * @version 4.0.0
55 55
 	 */
56 56
 	public function check_for_webhook() {
57
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
58
-			|| ! isset( $_GET['wc-api'] )
59
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
57
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
58
+			|| ! isset($_GET['wc-api'])
59
+			|| ('wc_stripe' !== $_GET['wc-api'])
60 60
 		) {
61 61
 			return;
62 62
 		}
63 63
 
64
-		$request_body    = file_get_contents( 'php://input' );
65
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
64
+		$request_body    = file_get_contents('php://input');
65
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
66 66
 
67 67
 		// Validate it to make sure it is legit.
68
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
69
-			$this->process_webhook( $request_body );
70
-			status_header( 200 );
68
+		if ($this->is_valid_request($request_headers, $request_body)) {
69
+			$this->process_webhook($request_body);
70
+			status_header(200);
71 71
 			exit;
72 72
 		} else {
73
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
73
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
74 74
 			// A webhook endpoint must return a 2xx HTTP status code.
75 75
 			// @see https://stripe.com/docs/webhooks/build#return-a-2xx-status-code-quickly
76
-			status_header( 204 );
76
+			status_header(204);
77 77
 			exit;
78 78
 		}
79 79
 	}
@@ -87,34 +87,34 @@  discard block
 block discarded – undo
87 87
 	 * @param string $request_body The request body from Stripe.
88 88
 	 * @return bool
89 89
 	 */
90
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
91
-		if ( null === $request_headers || null === $request_body ) {
90
+	public function is_valid_request($request_headers = null, $request_body = null) {
91
+		if (null === $request_headers || null === $request_body) {
92 92
 			return false;
93 93
 		}
94 94
 
95
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
95
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
96 96
 			return false;
97 97
 		}
98 98
 
99
-		if ( ! empty( $this->secret ) ) {
99
+		if ( ! empty($this->secret)) {
100 100
 			// Check for a valid signature.
101 101
 			$signature_format = '/^t=(?P<timestamp>\d+)(?P<signatures>(,v\d+=[a-z0-9]+){1,2})$/';
102
-			if ( empty( $request_headers['STRIPE-SIGNATURE'] ) || ! preg_match( $signature_format, $request_headers['STRIPE-SIGNATURE'], $matches ) ) {
102
+			if (empty($request_headers['STRIPE-SIGNATURE']) || ! preg_match($signature_format, $request_headers['STRIPE-SIGNATURE'], $matches)) {
103 103
 				return false;
104 104
 			}
105 105
 
106 106
 			// Verify the timestamp.
107
-			$timestamp = intval( $matches['timestamp'] );
108
-			if ( abs( $timestamp - time() ) > 5 * MINUTE_IN_SECONDS ) {
107
+			$timestamp = intval($matches['timestamp']);
108
+			if (abs($timestamp - time()) > 5 * MINUTE_IN_SECONDS) {
109 109
 				return false;
110 110
 			}
111 111
 
112 112
 			// Generate the expected signature.
113 113
 			$signed_payload     = $timestamp . '.' . $request_body;
114
-			$expected_signature = hash_hmac( 'sha256', $signed_payload, $this->secret );
114
+			$expected_signature = hash_hmac('sha256', $signed_payload, $this->secret);
115 115
 
116 116
 			// Check if the expected signature is present.
117
-			if ( ! preg_match( '/,v\d+=' . preg_quote( $expected_signature, '/' ) . '/', $matches['signatures'] ) ) {
117
+			if ( ! preg_match('/,v\d+=' . preg_quote($expected_signature, '/') . '/', $matches['signatures'])) {
118 118
 				return false;
119 119
 			}
120 120
 		}
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
 	 * @version 4.0.0
132 132
 	 */
133 133
 	public function get_request_headers() {
134
-		if ( ! function_exists( 'getallheaders' ) ) {
134
+		if ( ! function_exists('getallheaders')) {
135 135
 			$headers = array();
136 136
 
137
-			foreach ( $_SERVER as $name => $value ) {
138
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
139
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
137
+			foreach ($_SERVER as $name => $value) {
138
+				if ('HTTP_' === substr($name, 0, 5)) {
139
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
140 140
 				}
141 141
 			}
142 142
 
@@ -155,30 +155,30 @@  discard block
 block discarded – undo
155 155
 	 * @param object $notification
156 156
 	 * @param bool $retry
157 157
 	 */
158
-	public function process_webhook_payment( $notification, $retry = true ) {
158
+	public function process_webhook_payment($notification, $retry = true) {
159 159
 		// The following 3 payment methods are synchronous so does not need to be handle via webhook.
160
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) {
160
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) {
161 161
 			return;
162 162
 		}
163 163
 
164
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
164
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
165 165
 
166
-		if ( ! $order ) {
167
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
166
+		if ( ! $order) {
167
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
168 168
 			return;
169 169
 		}
170 170
 
171 171
 		$order_id  = $order->get_id();
172 172
 		$source_id = $notification->data->object->id;
173 173
 
174
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
174
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
175 175
 
176 176
 		try {
177
-			if ( $order->has_status( array( 'processing', 'completed' ) ) ) {
177
+			if ($order->has_status(array('processing', 'completed'))) {
178 178
 				return;
179 179
 			}
180 180
 
181
-			if ( $order->has_status( 'on-hold' ) && ! $is_pending_receiver ) {
181
+			if ($order->has_status('on-hold') && ! $is_pending_receiver) {
182 182
 				return;
183 183
 			}
184 184
 
@@ -186,89 +186,89 @@  discard block
 block discarded – undo
186 186
 			$response = null;
187 187
 
188 188
 			// This will throw exception if not valid.
189
-			$this->validate_minimum_order_amount( $order );
189
+			$this->validate_minimum_order_amount($order);
190 190
 
191
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
191
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
192 192
 
193 193
 			// Prep source object.
194 194
 			$source_object           = new stdClass();
195 195
 			$source_object->token_id = '';
196
-			$source_object->customer = $this->get_stripe_customer_id( $order );
196
+			$source_object->customer = $this->get_stripe_customer_id($order);
197 197
 			$source_object->source   = $source_id;
198 198
 
199 199
 			// Make the request.
200
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
200
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
201 201
 			$headers  = $response['headers'];
202 202
 			$response = $response['body'];
203 203
 
204
-			if ( ! empty( $response->error ) ) {
204
+			if ( ! empty($response->error)) {
205 205
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
206
-				if ( $this->is_no_such_customer_error( $response->error ) ) {
207
-					delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
208
-					$order->delete_meta_data( '_stripe_customer_id' );
206
+				if ($this->is_no_such_customer_error($response->error)) {
207
+					delete_user_option($order->get_customer_id(), '_stripe_customer_id');
208
+					$order->delete_meta_data('_stripe_customer_id');
209 209
 					$order->save();
210 210
 				}
211 211
 
212
-				if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
212
+				if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
213 213
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
214
-					$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
214
+					$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
215 215
 					$wc_token->delete();
216
-					$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
217
-					$order->add_order_note( $localized_message );
218
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
216
+					$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
217
+					$order->add_order_note($localized_message);
218
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
219 219
 				}
220 220
 
221 221
 				// We want to retry.
222
-				if ( $this->is_retryable_error( $response->error ) ) {
223
-					if ( $retry ) {
222
+				if ($this->is_retryable_error($response->error)) {
223
+					if ($retry) {
224 224
 						// Don't do anymore retries after this.
225
-						if ( 5 <= $this->retry_interval ) {
225
+						if (5 <= $this->retry_interval) {
226 226
 
227
-							return $this->process_webhook_payment( $notification, false );
227
+							return $this->process_webhook_payment($notification, false);
228 228
 						}
229 229
 
230
-						sleep( $this->retry_interval );
230
+						sleep($this->retry_interval);
231 231
 
232 232
 						$this->retry_interval++;
233
-						return $this->process_webhook_payment( $notification, true );
233
+						return $this->process_webhook_payment($notification, true);
234 234
 					} else {
235
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
236
-						$order->add_order_note( $localized_message );
237
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
235
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
236
+						$order->add_order_note($localized_message);
237
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
238 238
 					}
239 239
 				}
240 240
 
241 241
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
242 242
 
243
-				if ( 'card_error' === $response->error->type ) {
244
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
243
+				if ('card_error' === $response->error->type) {
244
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
245 245
 				} else {
246
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
246
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
247 247
 				}
248 248
 
249
-				$order->add_order_note( $localized_message );
249
+				$order->add_order_note($localized_message);
250 250
 
251
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
251
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
252 252
 			}
253 253
 
254 254
 			// To prevent double processing the order on WC side.
255
-			if ( ! $this->is_original_request( $headers ) ) {
255
+			if ( ! $this->is_original_request($headers)) {
256 256
 				return;
257 257
 			}
258 258
 
259
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
259
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
260 260
 
261
-			$this->process_response( $response, $order );
261
+			$this->process_response($response, $order);
262 262
 
263
-		} catch ( WC_Stripe_Exception $e ) {
264
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
263
+		} catch (WC_Stripe_Exception $e) {
264
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
265 265
 
266
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e );
266
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e);
267 267
 
268
-			$statuses = array( 'pending', 'failed' );
268
+			$statuses = array('pending', 'failed');
269 269
 
270
-			if ( $order->has_status( $statuses ) ) {
271
-				$this->send_failed_order_email( $order_id );
270
+			if ($order->has_status($statuses)) {
271
+				$this->send_failed_order_email($order_id);
272 272
 			}
273 273
 		}
274 274
 	}
@@ -281,28 +281,28 @@  discard block
 block discarded – undo
281 281
 	 * @since 4.0.0
282 282
 	 * @param object $notification
283 283
 	 */
284
-	public function process_webhook_dispute( $notification ) {
285
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
284
+	public function process_webhook_dispute($notification) {
285
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
286 286
 
287
-		if ( ! $order ) {
288
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
287
+		if ( ! $order) {
288
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
289 289
 			return;
290 290
 		}
291 291
 
292
-		$order->update_meta_data( '_stripe_status_before_hold', $order->get_status() );
292
+		$order->update_meta_data('_stripe_status_before_hold', $order->get_status());
293 293
 
294 294
 		/* translators: 1) The URL to the order. */
295
-		$message = sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) );
296
-		if ( ! $order->get_meta( '_stripe_status_final', false ) ) {
297
-			$order->update_status( 'on-hold', $message );
295
+		$message = sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order));
296
+		if ( ! $order->get_meta('_stripe_status_final', false)) {
297
+			$order->update_status('on-hold', $message);
298 298
 		} else {
299
-			$order->add_order_note( $message );
299
+			$order->add_order_note($message);
300 300
 		}
301 301
 
302
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
302
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
303 303
 
304 304
 		$order_id = $order->get_id();
305
-		$this->send_failed_order_email( $order_id );
305
+		$this->send_failed_order_email($order_id);
306 306
 	}
307 307
 
308 308
 	/**
@@ -311,34 +311,34 @@  discard block
 block discarded – undo
311 311
 	 * @since 4.4.1
312 312
 	 * @param object $notification
313 313
 	 */
314
-	public function process_webhook_dispute_closed( $notification ) {
315
-		$order  = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
314
+	public function process_webhook_dispute_closed($notification) {
315
+		$order  = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
316 316
 		$status = $notification->data->object->status;
317 317
 
318
-		if ( ! $order ) {
319
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
318
+		if ( ! $order) {
319
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
320 320
 			return;
321 321
 		}
322 322
 
323
-		if ( 'lost' === $status ) {
324
-			$message = __( 'The dispute was lost or accepted.', 'woocommerce-gateway-stripe' );
325
-		} elseif ( 'won' === $status ) {
326
-			$message = __( 'The dispute was resolved in your favor.', 'woocommerce-gateway-stripe' );
327
-		} elseif ( 'warning_closed' === $status ) {
328
-			$message = __( 'The inquiry or retrieval was closed.', 'woocommerce-gateway-stripe' );
323
+		if ('lost' === $status) {
324
+			$message = __('The dispute was lost or accepted.', 'woocommerce-gateway-stripe');
325
+		} elseif ('won' === $status) {
326
+			$message = __('The dispute was resolved in your favor.', 'woocommerce-gateway-stripe');
327
+		} elseif ('warning_closed' === $status) {
328
+			$message = __('The inquiry or retrieval was closed.', 'woocommerce-gateway-stripe');
329 329
 		} else {
330 330
 			return;
331 331
 		}
332 332
 
333
-		if ( apply_filters( 'wc_stripe_webhook_dispute_change_order_status', true, $order, $notification ) ) {
333
+		if (apply_filters('wc_stripe_webhook_dispute_change_order_status', true, $order, $notification)) {
334 334
 			// Mark final so that order status is not overridden by out-of-sequence events.
335
-			$order->update_meta_data( '_stripe_status_final', true );
335
+			$order->update_meta_data('_stripe_status_final', true);
336 336
 
337 337
 			// Fail order if dispute is lost, or else revert to pre-dispute status.
338
-			$order_status = 'lost' === $status ? 'failed' : $order->get_meta( '_stripe_status_before_hold', 'processing' );
339
-			$order->update_status( $order_status, $message );
338
+			$order_status = 'lost' === $status ? 'failed' : $order->get_meta('_stripe_status_before_hold', 'processing');
339
+			$order->update_status($order_status, $message);
340 340
 		} else {
341
-			$order->add_order_note( $message );
341
+			$order->add_order_note($message);
342 342
 		}
343 343
 	}
344 344
 
@@ -350,43 +350,43 @@  discard block
 block discarded – undo
350 350
 	 * @version 4.0.0
351 351
 	 * @param object $notification
352 352
 	 */
353
-	public function process_webhook_capture( $notification ) {
354
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
353
+	public function process_webhook_capture($notification) {
354
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
355 355
 
356
-		if ( ! $order ) {
357
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
356
+		if ( ! $order) {
357
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
358 358
 			return;
359 359
 		}
360 360
 
361
-		if ( 'stripe' === $order->get_payment_method() ) {
361
+		if ('stripe' === $order->get_payment_method()) {
362 362
 			$charge   = $order->get_transaction_id();
363
-			$captured = $order->get_meta( '_stripe_charge_captured', true );
363
+			$captured = $order->get_meta('_stripe_charge_captured', true);
364 364
 
365
-			if ( $charge && 'no' === $captured ) {
366
-				$order->update_meta_data( '_stripe_charge_captured', 'yes' );
365
+			if ($charge && 'no' === $captured) {
366
+				$order->update_meta_data('_stripe_charge_captured', 'yes');
367 367
 
368 368
 				// Store other data such as fees
369
-				$order->set_transaction_id( $notification->data->object->id );
369
+				$order->set_transaction_id($notification->data->object->id);
370 370
 
371
-				if ( isset( $notification->data->object->balance_transaction ) ) {
372
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
371
+				if (isset($notification->data->object->balance_transaction)) {
372
+					$this->update_fees($order, $notification->data->object->balance_transaction);
373 373
 				}
374 374
 
375 375
 				// Check and see if capture is partial.
376
-				if ( $this->is_partial_capture( $notification ) ) {
377
-					$partial_amount = $this->get_partial_amount_to_charge( $notification );
378
-					$order->set_total( $partial_amount );
379
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
376
+				if ($this->is_partial_capture($notification)) {
377
+					$partial_amount = $this->get_partial_amount_to_charge($notification);
378
+					$order->set_total($partial_amount);
379
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
380 380
 					/* translators: partial captured amount */
381
-					$order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) );
381
+					$order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount));
382 382
 				} else {
383
-					$order->payment_complete( $notification->data->object->id );
383
+					$order->payment_complete($notification->data->object->id);
384 384
 
385 385
 					/* translators: transaction id */
386
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
386
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
387 387
 				}
388 388
 
389
-				if ( is_callable( array( $order, 'save' ) ) ) {
389
+				if (is_callable(array($order, 'save'))) {
390 390
 					$order->save();
391 391
 				}
392 392
 			}
@@ -401,41 +401,41 @@  discard block
 block discarded – undo
401 401
 	 * @version 4.0.0
402 402
 	 * @param object $notification
403 403
 	 */
404
-	public function process_webhook_charge_succeeded( $notification ) {
404
+	public function process_webhook_charge_succeeded($notification) {
405 405
 		// Ignore the notification for charges, created through PaymentIntents.
406
-		if ( isset( $notification->data->object->payment_intent ) && $notification->data->object->payment_intent ) {
406
+		if (isset($notification->data->object->payment_intent) && $notification->data->object->payment_intent) {
407 407
 			return;
408 408
 		}
409 409
 
410 410
 		// The following payment methods are synchronous so does not need to be handle via webhook.
411
-		if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) {
411
+		if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) {
412 412
 			return;
413 413
 		}
414 414
 
415
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
415
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
416 416
 
417
-		if ( ! $order ) {
418
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
417
+		if ( ! $order) {
418
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
419 419
 			return;
420 420
 		}
421 421
 
422
-		if ( ! $order->has_status( 'on-hold' ) ) {
422
+		if ( ! $order->has_status('on-hold')) {
423 423
 			return;
424 424
 		}
425 425
 
426 426
 		// Store other data such as fees
427
-		$order->set_transaction_id( $notification->data->object->id );
427
+		$order->set_transaction_id($notification->data->object->id);
428 428
 
429
-		if ( isset( $notification->data->object->balance_transaction ) ) {
430
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
429
+		if (isset($notification->data->object->balance_transaction)) {
430
+			$this->update_fees($order, $notification->data->object->balance_transaction);
431 431
 		}
432 432
 
433
-		$order->payment_complete( $notification->data->object->id );
433
+		$order->payment_complete($notification->data->object->id);
434 434
 
435 435
 		/* translators: transaction id */
436
-		$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
436
+		$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
437 437
 
438
-		if ( is_callable( array( $order, 'save' ) ) ) {
438
+		if (is_callable(array($order, 'save'))) {
439 439
 			$order->save();
440 440
 		}
441 441
 	}
@@ -447,27 +447,27 @@  discard block
 block discarded – undo
447 447
 	 * @since 4.1.5 Can handle any fail payments from any methods.
448 448
 	 * @param object $notification
449 449
 	 */
450
-	public function process_webhook_charge_failed( $notification ) {
451
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
450
+	public function process_webhook_charge_failed($notification) {
451
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
452 452
 
453
-		if ( ! $order ) {
454
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
453
+		if ( ! $order) {
454
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
455 455
 			return;
456 456
 		}
457 457
 
458 458
 		// If order status is already in failed status don't continue.
459
-		if ( $order->has_status( 'failed' ) ) {
459
+		if ($order->has_status('failed')) {
460 460
 			return;
461 461
 		}
462 462
 
463
-		$message = __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' );
464
-		if ( ! $order->get_meta( '_stripe_status_final', false ) ) {
465
-			$order->update_status( 'failed', $message );
463
+		$message = __('This payment failed to clear.', 'woocommerce-gateway-stripe');
464
+		if ( ! $order->get_meta('_stripe_status_final', false)) {
465
+			$order->update_status('failed', $message);
466 466
 		} else {
467
-			$order->add_order_note( $message );
467
+			$order->add_order_note($message);
468 468
 		}
469 469
 
470
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
470
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
471 471
 	}
472 472
 
473 473
 	/**
@@ -478,33 +478,33 @@  discard block
 block discarded – undo
478 478
 	 * @since 4.1.15 Add check to make sure order is processed by Stripe.
479 479
 	 * @param object $notification
480 480
 	 */
481
-	public function process_webhook_source_canceled( $notification ) {
482
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
481
+	public function process_webhook_source_canceled($notification) {
482
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
483 483
 
484 484
 		// If can't find order by charge ID, try source ID.
485
-		if ( ! $order ) {
486
-			$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
485
+		if ( ! $order) {
486
+			$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
487 487
 
488
-			if ( ! $order ) {
489
-				WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id );
488
+			if ( ! $order) {
489
+				WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id);
490 490
 				return;
491 491
 			}
492 492
 		}
493 493
 
494 494
 		// Don't proceed if payment method isn't Stripe.
495
-		if ( 'stripe' !== $order->get_payment_method() ) {
496
-			WC_Stripe_Logger::log( 'Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id() );
495
+		if ('stripe' !== $order->get_payment_method()) {
496
+			WC_Stripe_Logger::log('Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id());
497 497
 			return;
498 498
 		}
499 499
 
500
-		$message = __( 'This payment was cancelled.', 'woocommerce-gateway-stripe' );
501
-		if ( ! $order->has_status( 'cancelled' ) && ! $order->get_meta( '_stripe_status_final', false ) ) {
502
-			$order->update_status( 'cancelled', $message );
500
+		$message = __('This payment was cancelled.', 'woocommerce-gateway-stripe');
501
+		if ( ! $order->has_status('cancelled') && ! $order->get_meta('_stripe_status_final', false)) {
502
+			$order->update_status('cancelled', $message);
503 503
 		} else {
504
-			$order->add_order_note( $message );
504
+			$order->add_order_note($message);
505 505
 		}
506 506
 
507
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
507
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
508 508
 	}
509 509
 
510 510
 	/**
@@ -514,59 +514,59 @@  discard block
 block discarded – undo
514 514
 	 * @version 4.0.0
515 515
 	 * @param object $notification
516 516
 	 */
517
-	public function process_webhook_refund( $notification ) {
518
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
517
+	public function process_webhook_refund($notification) {
518
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
519 519
 
520
-		if ( ! $order ) {
521
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
520
+		if ( ! $order) {
521
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
522 522
 			return;
523 523
 		}
524 524
 
525 525
 		$order_id = $order->get_id();
526 526
 
527
-		if ( 'stripe' === $order->get_payment_method() ) {
527
+		if ('stripe' === $order->get_payment_method()) {
528 528
 			$charge    = $order->get_transaction_id();
529
-			$captured  = $order->get_meta( '_stripe_charge_captured', true );
530
-			$refund_id = $order->get_meta( '_stripe_refund_id', true );
529
+			$captured  = $order->get_meta('_stripe_charge_captured', true);
530
+			$refund_id = $order->get_meta('_stripe_refund_id', true);
531 531
 
532 532
 			// If the refund ID matches, don't continue to prevent double refunding.
533
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
533
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
534 534
 				return;
535 535
 			}
536 536
 
537 537
 			// Only refund captured charge.
538
-			if ( $charge ) {
539
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
538
+			if ($charge) {
539
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
540 540
 
541 541
 				// Create the refund.
542 542
 				$refund = wc_create_refund(
543 543
 					array(
544 544
 						'order_id' => $order_id,
545
-						'amount'   => $this->get_refund_amount( $notification ),
545
+						'amount'   => $this->get_refund_amount($notification),
546 546
 						'reason'   => $reason,
547 547
 					)
548 548
 				);
549 549
 
550
-				if ( is_wp_error( $refund ) ) {
551
-					WC_Stripe_Logger::log( $refund->get_error_message() );
550
+				if (is_wp_error($refund)) {
551
+					WC_Stripe_Logger::log($refund->get_error_message());
552 552
 				}
553 553
 
554
-				$order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id );
554
+				$order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id);
555 555
 
556
-				$amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 );
556
+				$amount = wc_price($notification->data->object->refunds->data[0]->amount / 100);
557 557
 
558
-				if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
559
-					$amount = wc_price( $notification->data->object->refunds->data[0]->amount );
558
+				if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
559
+					$amount = wc_price($notification->data->object->refunds->data[0]->amount);
560 560
 				}
561 561
 
562
-				if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) {
563
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
562
+				if (isset($notification->data->object->refunds->data[0]->balance_transaction)) {
563
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
564 564
 				}
565 565
 
566 566
 				/* translators: 1) dollar amount 2) transaction id 3) refund message */
567
-				$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $notification->data->object->refunds->data[0]->id, $reason ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
567
+				$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe'), $amount, $notification->data->object->refunds->data[0]->id, $reason) : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
568 568
 
569
-				$order->add_order_note( $refund_message );
569
+				$order->add_order_note($refund_message);
570 570
 			}
571 571
 		}
572 572
 	}
@@ -577,32 +577,32 @@  discard block
 block discarded – undo
577 577
 	 * @since 4.0.6
578 578
 	 * @param object $notification
579 579
 	 */
580
-	public function process_review_opened( $notification ) {
581
-		if ( isset( $notification->data->object->payment_intent ) ) {
582
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
580
+	public function process_review_opened($notification) {
581
+		if (isset($notification->data->object->payment_intent)) {
582
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
583 583
 
584
-			if ( ! $order ) {
585
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
584
+			if ( ! $order) {
585
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
586 586
 				return;
587 587
 			}
588 588
 		} else {
589
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
589
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
590 590
 
591
-			if ( ! $order ) {
592
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge );
591
+			if ( ! $order) {
592
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge);
593 593
 				return;
594 594
 			}
595 595
 		}
596 596
 
597
-		$order->update_meta_data( '_stripe_status_before_hold', $order->get_status() );
597
+		$order->update_meta_data('_stripe_status_before_hold', $order->get_status());
598 598
 
599 599
 		/* translators: 1) The URL to the order. 2) The reason type. */
600
-		$message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason );
600
+		$message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason);
601 601
 
602
-		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) && ! $order->get_meta( '_stripe_status_final', false ) ) {
603
-			$order->update_status( 'on-hold', $message );
602
+		if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification) && ! $order->get_meta('_stripe_status_final', false)) {
603
+			$order->update_status('on-hold', $message);
604 604
 		} else {
605
-			$order->add_order_note( $message );
605
+			$order->add_order_note($message);
606 606
 		}
607 607
 	}
608 608
 
@@ -612,34 +612,34 @@  discard block
 block discarded – undo
612 612
 	 * @since 4.0.6
613 613
 	 * @param object $notification
614 614
 	 */
615
-	public function process_review_closed( $notification ) {
616
-		if ( isset( $notification->data->object->payment_intent ) ) {
617
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
615
+	public function process_review_closed($notification) {
616
+		if (isset($notification->data->object->payment_intent)) {
617
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
618 618
 
619
-			if ( ! $order ) {
620
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
619
+			if ( ! $order) {
620
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
621 621
 				return;
622 622
 			}
623 623
 		} else {
624
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
624
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
625 625
 
626
-			if ( ! $order ) {
627
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge );
626
+			if ( ! $order) {
627
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge);
628 628
 				return;
629 629
 			}
630 630
 		}
631 631
 
632 632
 		/* translators: 1) The reason type. */
633
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
633
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
634 634
 
635 635
 		if (
636
-			$order->has_status( 'on-hold' ) &&
637
-			apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) &&
638
-			! $order->get_meta( '_stripe_status_final', false )
636
+			$order->has_status('on-hold') &&
637
+			apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification) &&
638
+			! $order->get_meta('_stripe_status_final', false)
639 639
 		) {
640
-			$order->update_status( $order->get_meta( '_stripe_status_before_hold', 'processing' ), $message );
640
+			$order->update_status($order->get_meta('_stripe_status_before_hold', 'processing'), $message);
641 641
 		} else {
642
-			$order->add_order_note( $message );
642
+			$order->add_order_note($message);
643 643
 		}
644 644
 	}
645 645
 
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 	 * @version 4.0.0
651 651
 	 * @param object $notification
652 652
 	 */
653
-	public function is_partial_capture( $notification ) {
653
+	public function is_partial_capture($notification) {
654 654
 		return 0 < $notification->data->object->amount_refunded;
655 655
 	}
656 656
 
@@ -661,11 +661,11 @@  discard block
 block discarded – undo
661 661
 	 * @version 4.0.0
662 662
 	 * @param object $notification
663 663
 	 */
664
-	public function get_refund_amount( $notification ) {
665
-		if ( $this->is_partial_capture( $notification ) ) {
664
+	public function get_refund_amount($notification) {
665
+		if ($this->is_partial_capture($notification)) {
666 666
 			$amount = $notification->data->object->refunds->data[0]->amount / 100;
667 667
 
668
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
668
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
669 669
 				$amount = $notification->data->object->refunds->data[0]->amount;
670 670
 			}
671 671
 
@@ -682,12 +682,12 @@  discard block
 block discarded – undo
682 682
 	 * @version 4.0.0
683 683
 	 * @param object $notification
684 684
 	 */
685
-	public function get_partial_amount_to_charge( $notification ) {
686
-		if ( $this->is_partial_capture( $notification ) ) {
687
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
685
+	public function get_partial_amount_to_charge($notification) {
686
+		if ($this->is_partial_capture($notification)) {
687
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
688 688
 
689
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
690
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
689
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
690
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
691 691
 			}
692 692
 
693 693
 			return $amount;
@@ -696,75 +696,75 @@  discard block
 block discarded – undo
696 696
 		return false;
697 697
 	}
698 698
 
699
-	public function process_payment_intent_success( $notification ) {
699
+	public function process_payment_intent_success($notification) {
700 700
 		$intent = $notification->data->object;
701
-		$order = WC_Stripe_Helper::get_order_by_intent_id( $intent->id );
701
+		$order = WC_Stripe_Helper::get_order_by_intent_id($intent->id);
702 702
 
703
-		if ( ! $order ) {
704
-			WC_Stripe_Logger::log( 'Could not find order via intent ID: ' . $intent->id );
703
+		if ( ! $order) {
704
+			WC_Stripe_Logger::log('Could not find order via intent ID: ' . $intent->id);
705 705
 			return;
706 706
 		}
707 707
 
708
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
708
+		if ( ! $order->has_status(array('pending', 'failed'))) {
709 709
 			return;
710 710
 		}
711 711
 
712
-		if ( $this->lock_order_payment( $order, $intent ) ) {
712
+		if ($this->lock_order_payment($order, $intent)) {
713 713
 			return;
714 714
 		}
715 715
 
716 716
 		$order_id = $order->get_id();
717
-		if ( 'payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type ) {
718
-			$charge = end( $intent->charges->data );
719
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
717
+		if ('payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type) {
718
+			$charge = end($intent->charges->data);
719
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
720 720
 
721
-			do_action( 'wc_gateway_stripe_process_payment', $charge, $order );
721
+			do_action('wc_gateway_stripe_process_payment', $charge, $order);
722 722
 
723 723
 			// Process valid response.
724
-			$this->process_response( $charge, $order );
724
+			$this->process_response($charge, $order);
725 725
 
726 726
 		} else {
727 727
 			$error_message = $intent->last_payment_error ? $intent->last_payment_error->message : "";
728 728
 
729 729
 			/* translators: 1) The error message that was received from Stripe. */
730
-			$message = sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message );
730
+			$message = sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message);
731 731
 
732
-			if ( ! $order->get_meta( '_stripe_status_final', false ) ) {
733
-				$order->update_status( 'failed', $message );
732
+			if ( ! $order->get_meta('_stripe_status_final', false)) {
733
+				$order->update_status('failed', $message);
734 734
 			} else {
735
-				$order->add_order_note( $message );
735
+				$order->add_order_note($message);
736 736
 			}
737 737
 
738
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
738
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
739 739
 
740
-			$this->send_failed_order_email( $order_id );
740
+			$this->send_failed_order_email($order_id);
741 741
 		}
742 742
 
743
-		$this->unlock_order_payment( $order );
743
+		$this->unlock_order_payment($order);
744 744
 	}
745 745
 
746
-	public function process_setup_intent( $notification ) {
746
+	public function process_setup_intent($notification) {
747 747
 		$intent = $notification->data->object;
748
-		$order = WC_Stripe_Helper::get_order_by_setup_intent_id( $intent->id );
748
+		$order = WC_Stripe_Helper::get_order_by_setup_intent_id($intent->id);
749 749
 
750
-		if ( ! $order ) {
751
-			WC_Stripe_Logger::log( 'Could not find order via setup intent ID: ' . $intent->id );
750
+		if ( ! $order) {
751
+			WC_Stripe_Logger::log('Could not find order via setup intent ID: ' . $intent->id);
752 752
 			return;
753 753
 		}
754 754
 
755
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
755
+		if ( ! $order->has_status(array('pending', 'failed'))) {
756 756
 			return;
757 757
 		}
758 758
 
759
-		if ( $this->lock_order_payment( $order, $intent ) ) {
759
+		if ($this->lock_order_payment($order, $intent)) {
760 760
 			return;
761 761
 		}
762 762
 
763 763
 		$order_id = $order->get_id();
764
-		if ( 'setup_intent.succeeded' === $notification->type ) {
765
-			WC_Stripe_Logger::log( "Stripe SetupIntent $intent->id succeeded for order $order_id" );
766
-			if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) {
767
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
764
+		if ('setup_intent.succeeded' === $notification->type) {
765
+			WC_Stripe_Logger::log("Stripe SetupIntent $intent->id succeeded for order $order_id");
766
+			if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) {
767
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
768 768
 			} else {
769 769
 				$order->payment_complete();
770 770
 			}
@@ -772,18 +772,18 @@  discard block
 block discarded – undo
772 772
 			$error_message = $intent->last_setup_error ? $intent->last_setup_error->message : "";
773 773
 
774 774
 			/* translators: 1) The error message that was received from Stripe. */
775
-			$message = sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message );
775
+			$message = sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message);
776 776
 
777
-			if ( ! $order->get_meta( '_stripe_status_final', false ) ) {
778
-				$order->update_status( 'failed', $message );
777
+			if ( ! $order->get_meta('_stripe_status_final', false)) {
778
+				$order->update_status('failed', $message);
779 779
 			} else {
780
-				$order->add_order_note( $message );
780
+				$order->add_order_note($message);
781 781
 			}
782 782
 
783
-			$this->send_failed_order_email( $order_id );
783
+			$this->send_failed_order_email($order_id);
784 784
 		}
785 785
 
786
-		$this->unlock_order_payment( $order );
786
+		$this->unlock_order_payment($order);
787 787
 	}
788 788
 
789 789
 	/**
@@ -793,59 +793,59 @@  discard block
 block discarded – undo
793 793
 	 * @version 4.0.0
794 794
 	 * @param string $request_body
795 795
 	 */
796
-	public function process_webhook( $request_body ) {
797
-		$notification = json_decode( $request_body );
796
+	public function process_webhook($request_body) {
797
+		$notification = json_decode($request_body);
798 798
 
799
-		switch ( $notification->type ) {
799
+		switch ($notification->type) {
800 800
 			case 'source.chargeable':
801
-				$this->process_webhook_payment( $notification );
801
+				$this->process_webhook_payment($notification);
802 802
 				break;
803 803
 
804 804
 			case 'source.canceled':
805
-				$this->process_webhook_source_canceled( $notification );
805
+				$this->process_webhook_source_canceled($notification);
806 806
 				break;
807 807
 
808 808
 			case 'charge.succeeded':
809
-				$this->process_webhook_charge_succeeded( $notification );
809
+				$this->process_webhook_charge_succeeded($notification);
810 810
 				break;
811 811
 
812 812
 			case 'charge.failed':
813
-				$this->process_webhook_charge_failed( $notification );
813
+				$this->process_webhook_charge_failed($notification);
814 814
 				break;
815 815
 
816 816
 			case 'charge.captured':
817
-				$this->process_webhook_capture( $notification );
817
+				$this->process_webhook_capture($notification);
818 818
 				break;
819 819
 
820 820
 			case 'charge.dispute.created':
821
-				$this->process_webhook_dispute( $notification );
821
+				$this->process_webhook_dispute($notification);
822 822
 				break;
823 823
 
824 824
 			case 'charge.dispute.closed':
825
-				$this->process_webhook_dispute_closed( $notification );
825
+				$this->process_webhook_dispute_closed($notification);
826 826
 				break;
827 827
 
828 828
 			case 'charge.refunded':
829
-				$this->process_webhook_refund( $notification );
829
+				$this->process_webhook_refund($notification);
830 830
 				break;
831 831
 
832 832
 			case 'review.opened':
833
-				$this->process_review_opened( $notification );
833
+				$this->process_review_opened($notification);
834 834
 				break;
835 835
 
836 836
 			case 'review.closed':
837
-				$this->process_review_closed( $notification );
837
+				$this->process_review_closed($notification);
838 838
 				break;
839 839
 
840 840
 			case 'payment_intent.succeeded':
841 841
 			case 'payment_intent.payment_failed':
842 842
 			case 'payment_intent.amount_capturable_updated':
843
-				$this->process_payment_intent_success( $notification );
843
+				$this->process_payment_intent_success($notification);
844 844
 				break;
845 845
 
846 846
 			case 'setup_intent.succeeded':
847 847
 			case 'setup_intent.setup_failed':
848
-				$this->process_setup_intent( $notification );
848
+				$this->process_setup_intent($notification);
849 849
 
850 850
 		}
851 851
 	}
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	public function display_admin_settings_webhook_description() {
23 23
 		/* translators: 1) webhook url */
24
-		return sprintf( __( 'You must add the following webhook endpoint <strong style="background-color:#ddd;">&nbsp;%s&nbsp;</strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::get_webhook_url() );
24
+		return sprintf(__('You must add the following webhook endpoint <strong style="background-color:#ddd;">&nbsp;%s&nbsp;</strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::get_webhook_url());
25 25
 	}
26 26
 
27 27
 	/**
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 				<input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
36 36
 				<label for="wc-%1$s-new-payment-method" style="display:inline;">%2$s</label>
37 37
 			</p>',
38
-			esc_attr( $this->id ),
39
-			esc_html( apply_filters( 'wc_stripe_save_to_account_text', __( 'Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe' ) ) )
38
+			esc_attr($this->id),
39
+			esc_html(apply_filters('wc_stripe_save_to_account_text', __('Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe')))
40 40
 		);
41 41
 	}
42 42
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 * @since 4.0.5
48 48
 	 * @param array $error
49 49
 	 */
50
-	public function is_retryable_error( $error ) {
50
+	public function is_retryable_error($error) {
51 51
 		return (
52 52
 			'invalid_request_error' === $error->type ||
53 53
 			'idempotency_error' === $error->type ||
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
 	 * @since 4.1.0
65 65
 	 * @param array $error
66 66
 	 */
67
-	public function is_same_idempotency_error( $error ) {
67
+	public function is_same_idempotency_error($error) {
68 68
 		return (
69 69
 			$error &&
70 70
 			'idempotency_error' === $error->type &&
71
-			preg_match( '/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message )
71
+			preg_match('/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message)
72 72
 		);
73 73
 	}
74 74
 
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
 	 * @since 4.1.0
80 80
 	 * @param array $error
81 81
 	 */
82
-	public function is_no_such_customer_error( $error ) {
82
+	public function is_no_such_customer_error($error) {
83 83
 		return (
84 84
 			$error &&
85 85
 			'invalid_request_error' === $error->type &&
86
-			preg_match( '/No such customer/i', $error->message )
86
+			preg_match('/No such customer/i', $error->message)
87 87
 		);
88 88
 	}
89 89
 
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
 	 * @since 4.1.0
95 95
 	 * @param array $error
96 96
 	 */
97
-	public function is_no_such_token_error( $error ) {
97
+	public function is_no_such_token_error($error) {
98 98
 		return (
99 99
 			$error &&
100 100
 			'invalid_request_error' === $error->type &&
101
-			preg_match( '/No such token/i', $error->message )
101
+			preg_match('/No such token/i', $error->message)
102 102
 		);
103 103
 	}
104 104
 
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 	 * @since 4.1.0
110 110
 	 * @param array $error
111 111
 	 */
112
-	public function is_no_such_source_error( $error ) {
112
+	public function is_no_such_source_error($error) {
113 113
 		return (
114 114
 			$error &&
115 115
 			'invalid_request_error' === $error->type &&
116
-			preg_match( '/No such source/i', $error->message )
116
+			preg_match('/No such source/i', $error->message)
117 117
 		);
118 118
 	}
119 119
 
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
 	 * @since 4.1.0
125 125
 	 * @param array $error
126 126
 	 */
127
-	public function is_no_linked_source_error( $error ) {
127
+	public function is_no_linked_source_error($error) {
128 128
 		return (
129 129
 			$error &&
130 130
 			'invalid_request_error' === $error->type &&
131
-			preg_match( '/does not have a linked source with ID/i', $error->message )
131
+			preg_match('/does not have a linked source with ID/i', $error->message)
132 132
 		);
133 133
 	}
134 134
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * @param object $error
142 142
 	 * @return bool
143 143
 	 */
144
-	public function need_update_idempotency_key( $source_object, $error ) {
144
+	public function need_update_idempotency_key($source_object, $error) {
145 145
 		return (
146 146
 			$error &&
147 147
 			1 < $this->retry_interval &&
148
-			! empty( $source_object ) &&
148
+			! empty($source_object) &&
149 149
 			'chargeable' === $source_object->status &&
150
-			self::is_same_idempotency_error( $error )
150
+			self::is_same_idempotency_error($error)
151 151
 		);
152 152
 	}
153 153
 
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
 		// NOTE: updates to this function should be added to are_keys_set()
162 162
 		// in includes/payment-methods/class-wc-stripe-payment-request.php
163 163
 
164
-		if ( $this->testmode ) {
165
-			return preg_match( '/^pk_test_/', $this->publishable_key )
166
-				&& preg_match( '/^[rs]k_test_/', $this->secret_key );
164
+		if ($this->testmode) {
165
+			return preg_match('/^pk_test_/', $this->publishable_key)
166
+				&& preg_match('/^[rs]k_test_/', $this->secret_key);
167 167
 		} else {
168
-			return preg_match( '/^pk_live_/', $this->publishable_key )
169
-			    && preg_match( '/^[rs]k_live_/', $this->secret_key );
168
+			return preg_match('/^pk_live_/', $this->publishable_key)
169
+			    && preg_match('/^[rs]k_live_/', $this->secret_key);
170 170
 		}
171 171
 	}
172 172
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 * @since 4.1.3
177 177
 	 */
178 178
 	public function is_available() {
179
-		if ( 'yes' === $this->enabled ) {
179
+		if ('yes' === $this->enabled) {
180 180
 			return $this->are_keys_set();
181 181
 		}
182 182
 
@@ -191,12 +191,12 @@  discard block
 block discarded – undo
191 191
 	 * @param int $order_id
192 192
 	 * @return bool
193 193
 	 */
194
-	public function maybe_process_pre_orders( $order_id ) {
194
+	public function maybe_process_pre_orders($order_id) {
195 195
 		return (
196 196
 			WC_Stripe_Helper::is_pre_orders_exists() &&
197
-			$this->pre_orders->is_pre_order( $order_id ) &&
198
-			WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) &&
199
-			! is_wc_endpoint_url( 'order-pay' )
197
+			$this->pre_orders->is_pre_order($order_id) &&
198
+			WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id) &&
199
+			! is_wc_endpoint_url('order-pay')
200 200
 		);
201 201
 	}
202 202
 
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 	 * @version 4.0.0
241 241
 	 * @param object $order
242 242
 	 */
243
-	public function validate_minimum_order_amount( $order ) {
244
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
243
+	public function validate_minimum_order_amount($order) {
244
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
245 245
 			/* translators: 1) dollar amount */
246
-			throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
246
+			throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
247 247
 		}
248 248
 	}
249 249
 
@@ -253,14 +253,14 @@  discard block
 block discarded – undo
253 253
 	 * @since 4.0.0
254 254
 	 * @version 4.0.0
255 255
 	 */
256
-	public function get_transaction_url( $order ) {
257
-		if ( $this->testmode ) {
256
+	public function get_transaction_url($order) {
257
+		if ($this->testmode) {
258 258
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
259 259
 		} else {
260 260
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
261 261
 		}
262 262
 
263
-		return parent::get_transaction_url( $order );
263
+		return parent::get_transaction_url($order);
264 264
 	}
265 265
 
266 266
 	/**
@@ -269,12 +269,12 @@  discard block
 block discarded – undo
269 269
 	 * @since 4.0.0
270 270
 	 * @version 4.0.0
271 271
 	 */
272
-	public function get_stripe_customer_id( $order ) {
273
-		$customer = get_user_option( '_stripe_customer_id', $order->get_customer_id() );
272
+	public function get_stripe_customer_id($order) {
273
+		$customer = get_user_option('_stripe_customer_id', $order->get_customer_id());
274 274
 
275
-		if ( empty( $customer ) ) {
275
+		if (empty($customer)) {
276 276
 			// Try to get it via the order.
277
-			return $order->get_meta( '_stripe_customer_id', true );
277
+			return $order->get_meta('_stripe_customer_id', true);
278 278
 		} else {
279 279
 			return $customer;
280 280
 		}
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
 	 * @param object $order
291 291
 	 * @param int $id Stripe session id.
292 292
 	 */
293
-	public function get_stripe_return_url( $order = null, $id = null ) {
294
-		if ( is_object( $order ) ) {
295
-			if ( empty( $id ) ) {
293
+	public function get_stripe_return_url($order = null, $id = null) {
294
+		if (is_object($order)) {
295
+			if (empty($id)) {
296 296
 				$id = uniqid();
297 297
 			}
298 298
 
@@ -303,10 +303,10 @@  discard block
 block discarded – undo
303 303
 				'order_id'       => $order_id,
304 304
 			);
305 305
 
306
-			return wp_sanitize_redirect( esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ) );
306
+			return wp_sanitize_redirect(esc_url_raw(add_query_arg($args, $this->get_return_url($order))));
307 307
 		}
308 308
 
309
-		return wp_sanitize_redirect( esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ) );
309
+		return wp_sanitize_redirect(esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())));
310 310
 	}
311 311
 
312 312
 	/**
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
 	 * @param  int  $order_id
315 315
 	 * @return boolean
316 316
 	 */
317
-	public function has_subscription( $order_id ) {
318
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
317
+	public function has_subscription($order_id) {
318
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
319 319
 	}
320 320
 
321 321
 	/**
@@ -327,41 +327,41 @@  discard block
 block discarded – undo
327 327
 	 * @param  object $prepared_source
328 328
 	 * @return array()
329 329
 	 */
330
-	public function generate_payment_request( $order, $prepared_source ) {
331
-		$settings              = get_option( 'woocommerce_stripe_settings', array() );
332
-		$statement_descriptor  = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
333
-		$capture               = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
330
+	public function generate_payment_request($order, $prepared_source) {
331
+		$settings              = get_option('woocommerce_stripe_settings', array());
332
+		$statement_descriptor  = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
333
+		$capture               = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
334 334
 		$post_data             = array();
335
-		$post_data['currency'] = strtolower( $order->get_currency() );
336
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
335
+		$post_data['currency'] = strtolower($order->get_currency());
336
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
337 337
 		/* translators: 1) blog name 2) order number */
338
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
338
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
339 339
 		$billing_email            = $order->get_billing_email();
340 340
 		$billing_first_name       = $order->get_billing_first_name();
341 341
 		$billing_last_name        = $order->get_billing_last_name();
342 342
 
343
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
343
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
344 344
 			$post_data['receipt_email'] = $billing_email;
345 345
 		}
346 346
 
347
-		switch ( $order->get_payment_method() ) {
347
+		switch ($order->get_payment_method()) {
348 348
 			case 'stripe':
349
-				if ( ! empty( $statement_descriptor ) ) {
350
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
349
+				if ( ! empty($statement_descriptor)) {
350
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
351 351
 				}
352 352
 
353 353
 				$post_data['capture'] = $capture ? 'true' : 'false';
354 354
 				break;
355 355
 			case 'stripe_sepa':
356
-				if ( ! empty( $statement_descriptor ) ) {
357
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
356
+				if ( ! empty($statement_descriptor)) {
357
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
358 358
 				}
359 359
 				break;
360 360
 		}
361 361
 
362
-		if ( method_exists( $order, 'get_shipping_postcode' ) && ! empty( $order->get_shipping_postcode() ) ) {
362
+		if (method_exists($order, 'get_shipping_postcode') && ! empty($order->get_shipping_postcode())) {
363 363
 			$post_data['shipping'] = array(
364
-				'name'    => trim( $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name() ),
364
+				'name'    => trim($order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name()),
365 365
 				'address' => array(
366 366
 					'line1'       => $order->get_shipping_address_1(),
367 367
 					'line2'       => $order->get_shipping_address_2(),
@@ -376,25 +376,25 @@  discard block
 block discarded – undo
376 376
 		$post_data['expand[]'] = 'balance_transaction';
377 377
 
378 378
 		$metadata = array(
379
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
380
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
379
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
380
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
381 381
 			'order_id' => $order->get_order_number(),
382
-			'site_url' => esc_url( get_site_url() ),
382
+			'site_url' => esc_url(get_site_url()),
383 383
 		);
384 384
 
385
-		if ( $this->has_subscription( $order->get_id() ) ) {
385
+		if ($this->has_subscription($order->get_id())) {
386 386
 			$metadata += array(
387 387
 				'payment_type' => 'recurring',
388 388
 			);
389 389
 		}
390 390
 
391
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source );
391
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source);
392 392
 
393
-		if ( $prepared_source->customer ) {
393
+		if ($prepared_source->customer) {
394 394
 			$post_data['customer'] = $prepared_source->customer;
395 395
 		}
396 396
 
397
-		if ( $prepared_source->source ) {
397
+		if ($prepared_source->source) {
398 398
 			$post_data['source'] = $prepared_source->source;
399 399
 		}
400 400
 
@@ -406,72 +406,72 @@  discard block
 block discarded – undo
406 406
 		 * @param WC_Order $order
407 407
 		 * @param object $source
408 408
 		 */
409
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source );
409
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source);
410 410
 	}
411 411
 
412 412
 	/**
413 413
 	 * Store extra meta data for an order from a Stripe Response.
414 414
 	 */
415
-	public function process_response( $response, $order ) {
416
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
415
+	public function process_response($response, $order) {
416
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
417 417
 
418 418
 		$order_id = $order->get_id();
419
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
419
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
420 420
 
421 421
 		// Store charge data.
422
-		$order->update_meta_data( '_stripe_charge_captured', $captured );
422
+		$order->update_meta_data('_stripe_charge_captured', $captured);
423 423
 
424
-		if ( isset( $response->balance_transaction ) ) {
425
-			$this->update_fees( $order, is_string( $response->balance_transaction ) ? $response->balance_transaction : $response->balance_transaction->id );
424
+		if (isset($response->balance_transaction)) {
425
+			$this->update_fees($order, is_string($response->balance_transaction) ? $response->balance_transaction : $response->balance_transaction->id);
426 426
 		}
427 427
 
428
-		if ( 'yes' === $captured ) {
428
+		if ('yes' === $captured) {
429 429
 			/**
430 430
 			 * Charge can be captured but in a pending state. Payment methods
431 431
 			 * that are asynchronous may take couple days to clear. Webhook will
432 432
 			 * take care of the status changes.
433 433
 			 */
434
-			if ( 'pending' === $response->status ) {
435
-				$order_stock_reduced = $order->get_meta( '_order_stock_reduced', true );
434
+			if ('pending' === $response->status) {
435
+				$order_stock_reduced = $order->get_meta('_order_stock_reduced', true);
436 436
 
437
-				if ( ! $order_stock_reduced ) {
438
-					wc_reduce_stock_levels( $order_id );
437
+				if ( ! $order_stock_reduced) {
438
+					wc_reduce_stock_levels($order_id);
439 439
 				}
440 440
 
441
-				$order->set_transaction_id( $response->id );
441
+				$order->set_transaction_id($response->id);
442 442
 				/* translators: transaction id */
443
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
443
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
444 444
 			}
445 445
 
446
-			if ( 'succeeded' === $response->status ) {
447
-				$order->payment_complete( $response->id );
446
+			if ('succeeded' === $response->status) {
447
+				$order->payment_complete($response->id);
448 448
 
449 449
 				/* translators: transaction id */
450
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
451
-				$order->add_order_note( $message );
450
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
451
+				$order->add_order_note($message);
452 452
 			}
453 453
 
454
-			if ( 'failed' === $response->status ) {
455
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
456
-				$order->add_order_note( $localized_message );
457
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
454
+			if ('failed' === $response->status) {
455
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
456
+				$order->add_order_note($localized_message);
457
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
458 458
 			}
459 459
 		} else {
460
-			$order->set_transaction_id( $response->id );
460
+			$order->set_transaction_id($response->id);
461 461
 
462
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
463
-				wc_reduce_stock_levels( $order_id );
462
+			if ($order->has_status(array('pending', 'failed'))) {
463
+				wc_reduce_stock_levels($order_id);
464 464
 			}
465 465
 
466 466
 			/* translators: transaction id */
467
-			$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 ) );
467
+			$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));
468 468
 		}
469 469
 
470
-		if ( is_callable( array( $order, 'save' ) ) ) {
470
+		if (is_callable(array($order, 'save'))) {
471 471
 			$order->save();
472 472
 		}
473 473
 
474
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
474
+		do_action('wc_gateway_stripe_process_response', $response, $order);
475 475
 
476 476
 		return $response;
477 477
 	}
@@ -484,10 +484,10 @@  discard block
 block discarded – undo
484 484
 	 * @param int $order_id
485 485
 	 * @return null
486 486
 	 */
487
-	public function send_failed_order_email( $order_id ) {
487
+	public function send_failed_order_email($order_id) {
488 488
 		$emails = WC()->mailer()->get_emails();
489
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
490
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
489
+		if ( ! empty($emails) && ! empty($order_id)) {
490
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
491 491
 		}
492 492
 	}
493 493
 
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 	 * @param object $order
500 500
 	 * @return object $details
501 501
 	 */
502
-	public function get_owner_details( $order ) {
502
+	public function get_owner_details($order) {
503 503
 		$billing_first_name = $order->get_billing_first_name();
504 504
 		$billing_last_name  = $order->get_billing_last_name();
505 505
 
@@ -509,15 +509,15 @@  discard block
 block discarded – undo
509 509
 		$email = $order->get_billing_email();
510 510
 		$phone = $order->get_billing_phone();
511 511
 
512
-		if ( ! empty( $phone ) ) {
512
+		if ( ! empty($phone)) {
513 513
 			$details['phone'] = $phone;
514 514
 		}
515 515
 
516
-		if ( ! empty( $name ) ) {
516
+		if ( ! empty($name)) {
517 517
 			$details['name'] = $name;
518 518
 		}
519 519
 
520
-		if ( ! empty( $email ) ) {
520
+		if ( ! empty($email)) {
521 521
 			$details['email'] = $email;
522 522
 		}
523 523
 
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
 		$details['address']['postal_code'] = $order->get_billing_postcode();
529 529
 		$details['address']['country']     = $order->get_billing_country();
530 530
 
531
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
531
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
532 532
 	}
533 533
 
534 534
 	/**
@@ -537,15 +537,15 @@  discard block
 block discarded – undo
537 537
 	 * @since 4.0.3
538 538
 	 * @param string $source_id The source ID to get source object for.
539 539
 	 */
540
-	public function get_source_object( $source_id = '' ) {
541
-		if ( empty( $source_id ) ) {
540
+	public function get_source_object($source_id = '') {
541
+		if (empty($source_id)) {
542 542
 			return '';
543 543
 		}
544 544
 
545
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
545
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
546 546
 
547
-		if ( ! empty( $source_object->error ) ) {
548
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
547
+		if ( ! empty($source_object->error)) {
548
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
549 549
 		}
550 550
 
551 551
 		return $source_object;
@@ -558,10 +558,10 @@  discard block
 block discarded – undo
558 558
 	 * @param object $source_object
559 559
 	 * @return bool
560 560
 	 */
561
-	public function is_prepaid_card( $source_object ) {
561
+	public function is_prepaid_card($source_object) {
562 562
 		return (
563 563
 			$source_object
564
-			&& ( 'token' === $source_object->object || 'source' === $source_object->object )
564
+			&& ('token' === $source_object->object || 'source' === $source_object->object)
565 565
 			&& 'prepaid' === $source_object->card->funding
566 566
 		);
567 567
 	}
@@ -573,8 +573,8 @@  discard block
 block discarded – undo
573 573
 	 * @param string $source_id
574 574
 	 * @return bool
575 575
 	 */
576
-	public function is_type_legacy_card( $source_id ) {
577
-		return ( preg_match( '/^card_/', $source_id ) );
576
+	public function is_type_legacy_card($source_id) {
577
+		return (preg_match('/^card_/', $source_id));
578 578
 	}
579 579
 
580 580
 	/**
@@ -584,9 +584,9 @@  discard block
 block discarded – undo
584 584
 	 * @return bool
585 585
 	 */
586 586
 	public function is_using_saved_payment_method() {
587
-		$payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
587
+		$payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
588 588
 
589
-		return ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
589
+		return (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']);
590 590
 	}
591 591
 
592 592
 	/**
@@ -602,64 +602,64 @@  discard block
 block discarded – undo
602 602
 	 * @throws Exception When card was not added or for and invalid card.
603 603
 	 * @return object
604 604
 	 */
605
-	public function prepare_source( $user_id, $force_save_source = false, $existing_customer_id = null ) {
606
-		$customer = new WC_Stripe_Customer( $user_id );
607
-		if ( ! empty( $existing_customer_id ) ) {
608
-			$customer->set_id( $existing_customer_id );
605
+	public function prepare_source($user_id, $force_save_source = false, $existing_customer_id = null) {
606
+		$customer = new WC_Stripe_Customer($user_id);
607
+		if ( ! empty($existing_customer_id)) {
608
+			$customer->set_id($existing_customer_id);
609 609
 		}
610 610
 
611
-		$force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
611
+		$force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
612 612
 		$source_object     = '';
613 613
 		$source_id         = '';
614 614
 		$wc_token_id       = false;
615
-		$payment_method    = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
615
+		$payment_method    = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
616 616
 		$is_token          = false;
617 617
 
618 618
 		// New CC info was entered and we have a new source to process.
619
-		if ( ! empty( $_POST['stripe_source'] ) ) {
620
-			$source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) );
619
+		if ( ! empty($_POST['stripe_source'])) {
620
+			$source_object = self::get_source_object(wc_clean($_POST['stripe_source']));
621 621
 			$source_id     = $source_object->id;
622 622
 
623 623
 			// This checks to see if customer opted to save the payment method to file.
624
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
624
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
625 625
 
626 626
 			/**
627 627
 			 * This is true if the user wants to store the card to their account.
628 628
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
629 629
 			 * actually reusable. Either that or force_save_source is true.
630 630
 			 */
631
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
632
-				$response = $customer->add_source( $source_object->id );
631
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
632
+				$response = $customer->add_source($source_object->id);
633 633
 
634
-				if ( ! empty( $response->error ) ) {
635
-					throw new WC_Stripe_Exception( print_r( $response, true ), $this->get_localized_error_message_from_response( $response ) );
634
+				if ( ! empty($response->error)) {
635
+					throw new WC_Stripe_Exception(print_r($response, true), $this->get_localized_error_message_from_response($response));
636 636
 				}
637 637
 			}
638
-		} elseif ( $this->is_using_saved_payment_method() ) {
638
+		} elseif ($this->is_using_saved_payment_method()) {
639 639
 			// Use an existing token, and then process the payment.
640
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
641
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
640
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
641
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
642 642
 
643
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
644
-				WC()->session->set( 'refresh_totals', true );
645
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
643
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
644
+				WC()->session->set('refresh_totals', true);
645
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
646 646
 			}
647 647
 
648 648
 			$source_id = $wc_token->get_token();
649 649
 
650
-			if ( $this->is_type_legacy_card( $source_id ) ) {
650
+			if ($this->is_type_legacy_card($source_id)) {
651 651
 				$is_token = true;
652 652
 			}
653
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
654
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
655
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
653
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
654
+			$stripe_token     = wc_clean($_POST['stripe_token']);
655
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
656 656
 
657 657
 			// This is true if the user wants to store the card to their account.
658
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
659
-				$response = $customer->add_source( $stripe_token );
658
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
659
+				$response = $customer->add_source($stripe_token);
660 660
 
661
-				if ( ! empty( $response->error ) ) {
662
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
661
+				if ( ! empty($response->error)) {
662
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
663 663
 				}
664 664
 				$source_id    = $response;
665 665
 			} else {
@@ -669,15 +669,15 @@  discard block
 block discarded – undo
669 669
 		}
670 670
 
671 671
 		$customer_id = $customer->get_id();
672
-		if ( ! $customer_id ) {
673
-			$customer->set_id( $customer->create_customer() );
672
+		if ( ! $customer_id) {
673
+			$customer->set_id($customer->create_customer());
674 674
 			$customer_id = $customer->get_id();
675 675
 		} else {
676 676
 			$customer_id = $customer->update_customer();
677 677
 		}
678 678
 
679
-		if ( empty( $source_object ) && ! $is_token ) {
680
-			$source_object = self::get_source_object( $source_id );
679
+		if (empty($source_object) && ! $is_token) {
680
+			$source_object = self::get_source_object($source_id);
681 681
 		}
682 682
 
683 683
 		return (object) array(
@@ -701,39 +701,39 @@  discard block
 block discarded – undo
701 701
 	 * @param object $order
702 702
 	 * @return object
703 703
 	 */
704
-	public function prepare_order_source( $order = null ) {
704
+	public function prepare_order_source($order = null) {
705 705
 		$stripe_customer = new WC_Stripe_Customer();
706 706
 		$stripe_source   = false;
707 707
 		$token_id        = false;
708 708
 		$source_object   = false;
709 709
 
710
-		if ( $order ) {
710
+		if ($order) {
711 711
 			$order_id = $order->get_id();
712 712
 
713
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
713
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
714 714
 
715
-			if ( $stripe_customer_id ) {
716
-				$stripe_customer->set_id( $stripe_customer_id );
715
+			if ($stripe_customer_id) {
716
+				$stripe_customer->set_id($stripe_customer_id);
717 717
 			}
718 718
 
719
-			$source_id = $order->get_meta( '_stripe_source_id', true );
719
+			$source_id = $order->get_meta('_stripe_source_id', true);
720 720
 
721 721
 			// Since 4.0.0, we changed card to source so we need to account for that.
722
-			if ( empty( $source_id ) ) {
723
-				$source_id = $order->get_meta( '_stripe_card_id', true );
722
+			if (empty($source_id)) {
723
+				$source_id = $order->get_meta('_stripe_card_id', true);
724 724
 
725 725
 				// Take this opportunity to update the key name.
726
-				$order->update_meta_data( '_stripe_source_id', $source_id );
726
+				$order->update_meta_data('_stripe_source_id', $source_id);
727 727
 
728
-				if ( is_callable( array( $order, 'save' ) ) ) {
728
+				if (is_callable(array($order, 'save'))) {
729 729
 					$order->save();
730 730
 				}
731 731
 			}
732 732
 
733
-			if ( $source_id ) {
733
+			if ($source_id) {
734 734
 				$stripe_source = $source_id;
735
-				$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
736
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
735
+				$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
736
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
737 737
 				/*
738 738
 				 * We can attempt to charge the customer's default source
739 739
 				 * by sending empty source id.
@@ -758,17 +758,17 @@  discard block
 block discarded – undo
758 758
 	 * @param WC_Order $order For to which the source applies.
759 759
 	 * @param stdClass $source Source information.
760 760
 	 */
761
-	public function save_source_to_order( $order, $source ) {
761
+	public function save_source_to_order($order, $source) {
762 762
 		// Store source in the order.
763
-		if ( $source->customer ) {
764
-			$order->update_meta_data( '_stripe_customer_id', $source->customer );
763
+		if ($source->customer) {
764
+			$order->update_meta_data('_stripe_customer_id', $source->customer);
765 765
 		}
766 766
 
767
-		if ( $source->source ) {
768
-			$order->update_meta_data( '_stripe_source_id', $source->source );
767
+		if ($source->source) {
768
+			$order->update_meta_data('_stripe_source_id', $source->source);
769 769
 		}
770 770
 
771
-		if ( is_callable( array( $order, 'save' ) ) ) {
771
+		if (is_callable(array($order, 'save'))) {
772 772
 			$order->save();
773 773
 		}
774 774
 	}
@@ -782,36 +782,36 @@  discard block
 block discarded – undo
782 782
 	 * @param object $order The order object
783 783
 	 * @param int $balance_transaction_id
784 784
 	 */
785
-	public function update_fees( $order, $balance_transaction_id ) {
786
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
785
+	public function update_fees($order, $balance_transaction_id) {
786
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
787 787
 
788
-		if ( empty( $balance_transaction->error ) ) {
789
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
788
+		if (empty($balance_transaction->error)) {
789
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
790 790
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
791 791
 				// values are in the local currency of the Stripe account, not from WC.
792
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
793
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
792
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
793
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
794 794
 
795 795
 				// Current data fee & net.
796
-				$fee_current = WC_Stripe_Helper::get_stripe_fee( $order );
797
-				$net_current = WC_Stripe_Helper::get_stripe_net( $order );
796
+				$fee_current = WC_Stripe_Helper::get_stripe_fee($order);
797
+				$net_current = WC_Stripe_Helper::get_stripe_net($order);
798 798
 
799 799
 				// Calculation.
800 800
 				$fee = (float) $fee_current + (float) $fee_refund;
801 801
 				$net = (float) $net_current + (float) $net_refund;
802 802
 
803
-				WC_Stripe_Helper::update_stripe_fee( $order, $fee );
804
-				WC_Stripe_Helper::update_stripe_net( $order, $net );
803
+				WC_Stripe_Helper::update_stripe_fee($order, $fee);
804
+				WC_Stripe_Helper::update_stripe_net($order, $net);
805 805
 
806
-				$currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null;
807
-				WC_Stripe_Helper::update_stripe_currency( $order, $currency );
806
+				$currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null;
807
+				WC_Stripe_Helper::update_stripe_currency($order, $currency);
808 808
 
809
-				if ( is_callable( array( $order, 'save' ) ) ) {
809
+				if (is_callable(array($order, 'save'))) {
810 810
 					$order->save();
811 811
 				}
812 812
 			}
813 813
 		} else {
814
-			WC_Stripe_Logger::log( 'Unable to update fees/net meta for order: ' . $order->get_id() );
814
+			WC_Stripe_Logger::log('Unable to update fees/net meta for order: ' . $order->get_id());
815 815
 		}
816 816
 	}
817 817
 
@@ -824,36 +824,36 @@  discard block
 block discarded – undo
824 824
 	 * @param  float $amount
825 825
 	 * @return bool
826 826
 	 */
827
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
828
-		$order = wc_get_order( $order_id );
827
+	public function process_refund($order_id, $amount = null, $reason = '') {
828
+		$order = wc_get_order($order_id);
829 829
 
830
-		if ( ! $order ) {
830
+		if ( ! $order) {
831 831
 			return false;
832 832
 		}
833 833
 
834 834
 		$request = array();
835 835
 
836 836
 		$order_currency = $order->get_currency();
837
-		$captured       = $order->get_meta( '_stripe_charge_captured', true );
837
+		$captured       = $order->get_meta('_stripe_charge_captured', true);
838 838
 		$charge_id      = $order->get_transaction_id();
839 839
 
840
-		if ( ! $charge_id ) {
840
+		if ( ! $charge_id) {
841 841
 			return false;
842 842
 		}
843 843
 
844
-		if ( ! is_null( $amount ) ) {
845
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
844
+		if ( ! is_null($amount)) {
845
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
846 846
 		}
847 847
 
848 848
 		// If order is only authorized, don't pass amount.
849
-		if ( 'yes' !== $captured ) {
850
-			unset( $request['amount'] );
849
+		if ('yes' !== $captured) {
850
+			unset($request['amount']);
851 851
 		}
852 852
 
853
-		if ( $reason ) {
853
+		if ($reason) {
854 854
 			// Trim the refund reason to a max of 500 characters due to Stripe limits: https://stripe.com/docs/api/metadata.
855
-			if ( strlen( $reason ) > 500 ) {
856
-				$reason = function_exists( 'mb_substr' ) ? mb_substr( $reason, 0, 450 ) : substr( $reason, 0, 450 );
855
+			if (strlen($reason) > 500) {
856
+				$reason = function_exists('mb_substr') ? mb_substr($reason, 0, 450) : substr($reason, 0, 450);
857 857
 				// Add some explainer text indicating where to find the full refund reason.
858 858
 				$reason = $reason . '... [See WooCommerce order page for full text.]';
859 859
 			}
@@ -864,60 +864,60 @@  discard block
 block discarded – undo
864 864
 		}
865 865
 
866 866
 		$request['charge'] = $charge_id;
867
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$charge_id} for the amount of {$amount}" );
867
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$charge_id} for the amount of {$amount}");
868 868
 
869
-		$request = apply_filters( 'wc_stripe_refund_request', $request, $order );
869
+		$request = apply_filters('wc_stripe_refund_request', $request, $order);
870 870
 
871
-		$intent = $this->get_intent_from_order( $order );
871
+		$intent = $this->get_intent_from_order($order);
872 872
 		$intent_cancelled = false;
873
-		if ( $intent ) {
873
+		if ($intent) {
874 874
 			// If the order has a Payment Intent pending capture, then the Intent itself must be refunded (cancelled), not the Charge
875
-			if ( ! empty( $intent->error ) ) {
875
+			if ( ! empty($intent->error)) {
876 876
 				$response = $intent;
877 877
 				$intent_cancelled = true;
878
-			} elseif ( 'requires_capture' === $intent->status ) {
878
+			} elseif ('requires_capture' === $intent->status) {
879 879
 				$result = WC_Stripe_API::request(
880 880
 					array(),
881 881
 					'payment_intents/' . $intent->id . '/cancel'
882 882
 				);
883 883
 				$intent_cancelled = true;
884 884
 
885
-				if ( ! empty( $result->error ) ) {
885
+				if ( ! empty($result->error)) {
886 886
 					$response = $result;
887 887
 				} else {
888
-					$charge = end( $result->charges->data );
889
-					$response = end( $charge->refunds->data );
888
+					$charge = end($result->charges->data);
889
+					$response = end($charge->refunds->data);
890 890
 				}
891 891
 			}
892 892
 		}
893 893
 
894
-		if ( ! $intent_cancelled ) {
895
-			$response = WC_Stripe_API::request( $request, 'refunds' );
894
+		if ( ! $intent_cancelled) {
895
+			$response = WC_Stripe_API::request($request, 'refunds');
896 896
 		}
897 897
 
898
-		if ( ! empty( $response->error ) ) {
899
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
898
+		if ( ! empty($response->error)) {
899
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
900 900
 
901 901
 			return $response;
902 902
 
903
-		} elseif ( ! empty( $response->id ) ) {
904
-			$order->update_meta_data( '_stripe_refund_id', $response->id );
903
+		} elseif ( ! empty($response->id)) {
904
+			$order->update_meta_data('_stripe_refund_id', $response->id);
905 905
 
906
-			$amount = wc_price( $response->amount / 100 );
906
+			$amount = wc_price($response->amount / 100);
907 907
 
908
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
909
-				$amount = wc_price( $response->amount );
908
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
909
+				$amount = wc_price($response->amount);
910 910
 			}
911 911
 
912
-			if ( isset( $response->balance_transaction ) ) {
913
-				$this->update_fees( $order, $response->balance_transaction );
912
+			if (isset($response->balance_transaction)) {
913
+				$this->update_fees($order, $response->balance_transaction);
914 914
 			}
915 915
 
916 916
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
917
-			$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' );
917
+			$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe');
918 918
 
919
-			$order->add_order_note( $refund_message );
920
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) );
919
+			$order->add_order_note($refund_message);
920
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message)));
921 921
 
922 922
 			return true;
923 923
 		}
@@ -932,46 +932,46 @@  discard block
 block discarded – undo
932 932
 	 */
933 933
 	public function add_payment_method() {
934 934
 		$error     = false;
935
-		$error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' );
935
+		$error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe');
936 936
 		$source_id = '';
937 937
 
938
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
938
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
939 939
 			$error = true;
940 940
 		}
941 941
 
942
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
942
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
943 943
 
944
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
944
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
945 945
 
946
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
946
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
947 947
 
948
-		if ( isset( $source_object ) ) {
949
-			if ( ! empty( $source_object->error ) ) {
948
+		if (isset($source_object)) {
949
+			if ( ! empty($source_object->error)) {
950 950
 				$error = true;
951 951
 			}
952 952
 
953 953
 			$source_id = $source_object->id;
954
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
955
-			$source_id = wc_clean( $_POST['stripe_token'] );
954
+		} elseif (isset($_POST['stripe_token'])) {
955
+			$source_id = wc_clean($_POST['stripe_token']);
956 956
 		}
957 957
 
958
-		$response = $stripe_customer->add_source( $source_id );
958
+		$response = $stripe_customer->add_source($source_id);
959 959
 
960
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
960
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
961 961
 			$error = true;
962 962
 		}
963 963
 
964
-		if ( $error ) {
965
-			wc_add_notice( $error_msg, 'error' );
966
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
964
+		if ($error) {
965
+			wc_add_notice($error_msg, 'error');
966
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
967 967
 			return;
968 968
 		}
969 969
 
970
-		do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object );
970
+		do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object);
971 971
 
972 972
 		return array(
973 973
 			'result'   => 'success',
974
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
974
+			'redirect' => wc_get_endpoint_url('payment-methods'),
975 975
 		);
976 976
 	}
977 977
 
@@ -988,10 +988,10 @@  discard block
 block discarded – undo
988 988
 		 * Stripe expects Norwegian to only be passed NO.
989 989
 		 * But WP has different dialects.
990 990
 		 */
991
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
991
+		if ('NO' === substr($locale, 3, 2)) {
992 992
 			$locale = 'no';
993 993
 		} else {
994
-			$locale = substr( get_locale(), 0, 2 );
994
+			$locale = substr(get_locale(), 0, 2);
995 995
 		}
996 996
 
997 997
 		return $locale;
@@ -1005,9 +1005,9 @@  discard block
 block discarded – undo
1005 1005
 	 * @param string $idempotency_key
1006 1006
 	 * @param array $request
1007 1007
 	 */
1008
-	public function change_idempotency_key( $idempotency_key, $request ) {
1009
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
1010
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
1008
+	public function change_idempotency_key($idempotency_key, $request) {
1009
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
1010
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
1011 1011
 		$count    = $this->retry_interval;
1012 1012
 
1013 1013
 		return $request['metadata']['order_id'] . '-' . $count . '-' . $source;
@@ -1021,8 +1021,8 @@  discard block
 block discarded – undo
1021 1021
 	 * @since 4.0.6
1022 1022
 	 * @param array $headers
1023 1023
 	 */
1024
-	public function is_original_request( $headers ) {
1025
-		if ( $headers['original-request'] === $headers['request-id'] ) {
1024
+	public function is_original_request($headers) {
1025
+		if ($headers['original-request'] === $headers['request-id']) {
1026 1026
 			return true;
1027 1027
 		}
1028 1028
 
@@ -1036,31 +1036,31 @@  discard block
 block discarded – undo
1036 1036
 	 * @param object   $prepared_source The source that is used for the payment.
1037 1037
 	 * @return array                    The arguments for the request.
1038 1038
 	 */
1039
-	public function generate_create_intent_request( $order, $prepared_source ) {
1039
+	public function generate_create_intent_request($order, $prepared_source) {
1040 1040
 		// The request for a charge contains metadata for the intent.
1041
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1041
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1042 1042
 
1043 1043
 		$request = array(
1044 1044
 			'source'               => $prepared_source->source,
1045
-			'amount'               => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
1046
-			'currency'             => strtolower( $order->get_currency() ),
1045
+			'amount'               => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
1046
+			'currency'             => strtolower($order->get_currency()),
1047 1047
 			'description'          => $full_request['description'],
1048 1048
 			'metadata'             => $full_request['metadata'],
1049
-			'capture_method'       => ( 'true' === $full_request['capture'] ) ? 'automatic' : 'manual',
1049
+			'capture_method'       => ('true' === $full_request['capture']) ? 'automatic' : 'manual',
1050 1050
 			'payment_method_types' => array(
1051 1051
 				'card',
1052 1052
 			),
1053 1053
 		);
1054 1054
 
1055
-		if ( $prepared_source->customer ) {
1055
+		if ($prepared_source->customer) {
1056 1056
 			$request['customer'] = $prepared_source->customer;
1057 1057
 		}
1058 1058
 
1059
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1059
+		if (isset($full_request['statement_descriptor'])) {
1060 1060
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1061 1061
 		}
1062 1062
 
1063
-		if ( isset( $full_request['shipping'] ) ) {
1063
+		if (isset($full_request['shipping'])) {
1064 1064
 			$request['shipping'] = $full_request['shipping'];
1065 1065
 		}
1066 1066
 
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
 		 * @param WC_Order $order
1073 1073
 		 * @param object $source
1074 1074
 		 */
1075
-		return apply_filters( 'wc_stripe_generate_create_intent_request', $request, $order, $prepared_source );
1075
+		return apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source);
1076 1076
 	}
1077 1077
 
1078 1078
 	/**
@@ -1081,27 +1081,27 @@  discard block
 block discarded – undo
1081 1081
 	 * @param WC_Order $order The order that is being paid for.
1082 1082
 	 * @return array          The level 3 data to send to Stripe.
1083 1083
 	 */
1084
-	public function get_level3_data_from_order( $order ) {
1084
+	public function get_level3_data_from_order($order) {
1085 1085
 		// Get the order items. Don't need their keys, only their values.
1086 1086
 		// Order item IDs are used as keys in the original order items array.
1087
-		$order_items = array_values( $order->get_items( [ 'line_item', 'fee' ] ) );
1087
+		$order_items = array_values($order->get_items(['line_item', 'fee']));
1088 1088
 		$currency    = $order->get_currency();
1089 1089
 
1090
-		$stripe_line_items = array_map( function( $item ) use ( $currency ) {
1091
-			if ( is_a( $item, 'WC_Order_Item_Product' ) ) {
1090
+		$stripe_line_items = array_map(function($item) use ($currency) {
1091
+			if (is_a($item, 'WC_Order_Item_Product')) {
1092 1092
 				$product_id = $item->get_variation_id()
1093 1093
 					? $item->get_variation_id()
1094 1094
 					: $item->get_product_id();
1095 1095
 				$subtotal   = $item->get_subtotal();
1096 1096
 			} else {
1097
-				$product_id = substr( sanitize_title( $item->get_name() ), 0, 12 );
1097
+				$product_id = substr(sanitize_title($item->get_name()), 0, 12);
1098 1098
 				$subtotal   = $item->get_total();
1099 1099
 			}
1100
-			$product_description = substr( $item->get_name(), 0, 26 );
1100
+			$product_description = substr($item->get_name(), 0, 26);
1101 1101
 			$quantity            = $item->get_quantity();
1102
-			$unit_cost           = WC_Stripe_Helper::get_stripe_amount( ( $subtotal / $quantity ), $currency );
1103
-			$tax_amount          = WC_Stripe_Helper::get_stripe_amount( $item->get_total_tax(), $currency );
1104
-			$discount_amount     = WC_Stripe_Helper::get_stripe_amount( $subtotal - $item->get_total(), $currency );
1102
+			$unit_cost           = WC_Stripe_Helper::get_stripe_amount(($subtotal / $quantity), $currency);
1103
+			$tax_amount          = WC_Stripe_Helper::get_stripe_amount($item->get_total_tax(), $currency);
1104
+			$discount_amount     = WC_Stripe_Helper::get_stripe_amount($subtotal - $item->get_total(), $currency);
1105 1105
 
1106 1106
 			return (object) array(
1107 1107
 				'product_code'        => (string) $product_id, // Up to 12 characters that uniquely identify the product.
@@ -1115,19 +1115,19 @@  discard block
 block discarded – undo
1115 1115
 
1116 1116
 		$level3_data = array(
1117 1117
 			'merchant_reference'   => $order->get_id(), // An alphanumeric string of up to  characters in length. This unique value is assigned by the merchant to identify the order. Also known as an “Order ID”.
1118
-			'shipping_amount'      => WC_Stripe_Helper::get_stripe_amount( (float) $order->get_shipping_total() + (float) $order->get_shipping_tax(), $currency), // The shipping cost, in cents, as a non-negative integer.
1118
+			'shipping_amount'      => WC_Stripe_Helper::get_stripe_amount((float) $order->get_shipping_total() + (float) $order->get_shipping_tax(), $currency), // The shipping cost, in cents, as a non-negative integer.
1119 1119
 			'line_items'           => $stripe_line_items,
1120 1120
 		);
1121 1121
 
1122 1122
 		// The customer’s U.S. shipping ZIP code.
1123 1123
 		$shipping_address_zip = $order->get_shipping_postcode();
1124
-		if ( $this->is_valid_us_zip_code( $shipping_address_zip ) ) {
1124
+		if ($this->is_valid_us_zip_code($shipping_address_zip)) {
1125 1125
 			$level3_data['shipping_address_zip'] = $shipping_address_zip;
1126 1126
 		}
1127 1127
 
1128 1128
 		// The merchant’s U.S. shipping ZIP code.
1129
-		$store_postcode = get_option( 'woocommerce_store_postcode' );
1130
-		if ( $this->is_valid_us_zip_code( $store_postcode ) ) {
1129
+		$store_postcode = get_option('woocommerce_store_postcode');
1130
+		if ($this->is_valid_us_zip_code($store_postcode)) {
1131 1131
 			$level3_data['shipping_from_zip'] = $store_postcode;
1132 1132
 		}
1133 1133
 
@@ -1141,20 +1141,20 @@  discard block
 block discarded – undo
1141 1141
 	 * @param object   $prepared_source The source that is used for the payment.
1142 1142
 	 * @return object                   An intent or an error.
1143 1143
 	 */
1144
-	public function create_intent( $order, $prepared_source ) {
1145
-		$request = $this->generate_create_intent_request( $order, $prepared_source );
1144
+	public function create_intent($order, $prepared_source) {
1145
+		$request = $this->generate_create_intent_request($order, $prepared_source);
1146 1146
 
1147 1147
 		// Create an intent that awaits an action.
1148
-		$intent = WC_Stripe_API::request( $request, 'payment_intents' );
1149
-		if ( ! empty( $intent->error ) ) {
1148
+		$intent = WC_Stripe_API::request($request, 'payment_intents');
1149
+		if ( ! empty($intent->error)) {
1150 1150
 			return $intent;
1151 1151
 		}
1152 1152
 
1153 1153
 		$order_id = $order->get_id();
1154
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id initiated for order $order_id" );
1154
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id initiated for order $order_id");
1155 1155
 
1156 1156
 		// Save the intent ID to the order.
1157
-		$this->save_intent_to_order( $order, $intent );
1157
+		$this->save_intent_to_order($order, $intent);
1158 1158
 
1159 1159
 		return $intent;
1160 1160
 	}
@@ -1167,33 +1167,33 @@  discard block
 block discarded – undo
1167 1167
 	 * @param object   $prepared_source Currently selected source.
1168 1168
 	 * @return object                   An updated intent.
1169 1169
 	 */
1170
-	public function update_existing_intent( $intent, $order, $prepared_source ) {
1170
+	public function update_existing_intent($intent, $order, $prepared_source) {
1171 1171
 		$request = array();
1172 1172
 
1173
-		if ( $prepared_source->source !== $intent->source ) {
1173
+		if ($prepared_source->source !== $intent->source) {
1174 1174
 			$request['source'] = $prepared_source->source;
1175 1175
 		}
1176 1176
 
1177
-		$new_amount = WC_Stripe_Helper::get_stripe_amount( $order->get_total() );
1178
-		if ( $intent->amount !== $new_amount ) {
1177
+		$new_amount = WC_Stripe_Helper::get_stripe_amount($order->get_total());
1178
+		if ($intent->amount !== $new_amount) {
1179 1179
 			$request['amount'] = $new_amount;
1180 1180
 		}
1181 1181
 
1182
-		if ( $prepared_source->customer && $intent->customer !== $prepared_source->customer ) {
1182
+		if ($prepared_source->customer && $intent->customer !== $prepared_source->customer) {
1183 1183
 			$request['customer'] = $prepared_source->customer;
1184 1184
 		}
1185 1185
 
1186
-		if ( $this->has_subscription( $order ) ) {
1186
+		if ($this->has_subscription($order)) {
1187 1187
 			// If this is a failed subscription order payment, the intent should be
1188 1188
 			// prepared for future usage.
1189 1189
 			$request['setup_future_usage'] = 'off_session';
1190 1190
 		}
1191 1191
 
1192
-		if ( empty( $request ) ) {
1192
+		if (empty($request)) {
1193 1193
 			return $intent;
1194 1194
 		}
1195 1195
 
1196
-		$level3_data = $this->get_level3_data_from_order( $order );
1196
+		$level3_data = $this->get_level3_data_from_order($order);
1197 1197
 		return WC_Stripe_API::request_with_level3_data(
1198 1198
 			$request,
1199 1199
 			"payment_intents/$intent->id",
@@ -1211,8 +1211,8 @@  discard block
 block discarded – undo
1211 1211
 	 * @param object   $prepared_source The source that is being charged.
1212 1212
 	 * @return object                   Either an error or the updated intent.
1213 1213
 	 */
1214
-	public function confirm_intent( $intent, $order, $prepared_source ) {
1215
-		if ( 'requires_confirmation' !== $intent->status ) {
1214
+	public function confirm_intent($intent, $order, $prepared_source) {
1215
+		if ('requires_confirmation' !== $intent->status) {
1216 1216
 			return $intent;
1217 1217
 		}
1218 1218
 
@@ -1221,7 +1221,7 @@  discard block
 block discarded – undo
1221 1221
 			'source' => $prepared_source->source,
1222 1222
 		);
1223 1223
 
1224
-		$level3_data = $this->get_level3_data_from_order( $order );
1224
+		$level3_data = $this->get_level3_data_from_order($order);
1225 1225
 		$confirmed_intent = WC_Stripe_API::request_with_level3_data(
1226 1226
 			$confirm_request,
1227 1227
 			"payment_intents/$intent->id/confirm",
@@ -1229,16 +1229,16 @@  discard block
 block discarded – undo
1229 1229
 			$order
1230 1230
 		);
1231 1231
 
1232
-		if ( ! empty( $confirmed_intent->error ) ) {
1232
+		if ( ! empty($confirmed_intent->error)) {
1233 1233
 			return $confirmed_intent;
1234 1234
 		}
1235 1235
 
1236 1236
 		// Save a note about the status of the intent.
1237 1237
 		$order_id = $order->get_id();
1238
-		if ( 'succeeded' === $confirmed_intent->status ) {
1239
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
1240
-		} elseif ( 'requires_action' === $confirmed_intent->status ) {
1241
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id requires authentication for order $order_id" );
1238
+		if ('succeeded' === $confirmed_intent->status) {
1239
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
1240
+		} elseif ('requires_action' === $confirmed_intent->status) {
1241
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id requires authentication for order $order_id");
1242 1242
 		}
1243 1243
 
1244 1244
 		return $confirmed_intent;
@@ -1251,10 +1251,10 @@  discard block
 block discarded – undo
1251 1251
 	 * @param WC_Order $order For to which the source applies.
1252 1252
 	 * @param stdClass $intent Payment intent information.
1253 1253
 	 */
1254
-	public function save_intent_to_order( $order, $intent ) {
1255
-		$order->update_meta_data( '_stripe_intent_id', $intent->id );
1254
+	public function save_intent_to_order($order, $intent) {
1255
+		$order->update_meta_data('_stripe_intent_id', $intent->id);
1256 1256
 
1257
-		if ( is_callable( array( $order, 'save' ) ) ) {
1257
+		if (is_callable(array($order, 'save'))) {
1258 1258
 			$order->save();
1259 1259
 		}
1260 1260
 	}
@@ -1266,18 +1266,18 @@  discard block
 block discarded – undo
1266 1266
 	 * @param WC_Order $order The order to retrieve an intent for.
1267 1267
 	 * @return obect|bool     Either the intent object or `false`.
1268 1268
 	 */
1269
-	public function get_intent_from_order( $order ) {
1270
-		$intent_id = $order->get_meta( '_stripe_intent_id' );
1269
+	public function get_intent_from_order($order) {
1270
+		$intent_id = $order->get_meta('_stripe_intent_id');
1271 1271
 
1272
-		if ( $intent_id ) {
1273
-			return $this->get_intent( 'payment_intents', $intent_id );
1272
+		if ($intent_id) {
1273
+			return $this->get_intent('payment_intents', $intent_id);
1274 1274
 		}
1275 1275
 
1276 1276
 		// The order doesn't have a payment intent, but it may have a setup intent.
1277
-		$intent_id = $order->get_meta( '_stripe_setup_intent' );
1277
+		$intent_id = $order->get_meta('_stripe_setup_intent');
1278 1278
 
1279
-		if ( $intent_id ) {
1280
-			return $this->get_intent( 'setup_intents', $intent_id );
1279
+		if ($intent_id) {
1280
+			return $this->get_intent('setup_intents', $intent_id);
1281 1281
 		}
1282 1282
 
1283 1283
 		return false;
@@ -1291,15 +1291,15 @@  discard block
 block discarded – undo
1291 1291
 	 * @return object|bool 			Either the intent object or `false`.
1292 1292
 	 * @throws Exception 			Throws exception for unknown $intent_type.
1293 1293
 	 */
1294
-	private function get_intent( $intent_type, $intent_id ) {
1295
-		if ( ! in_array( $intent_type, [ 'payment_intents', 'setup_intents' ] ) ) {
1296
-			throw new Exception( "Failed to get intent of type $intent_type. Type is not allowed" );
1294
+	private function get_intent($intent_type, $intent_id) {
1295
+		if ( ! in_array($intent_type, ['payment_intents', 'setup_intents'])) {
1296
+			throw new Exception("Failed to get intent of type $intent_type. Type is not allowed");
1297 1297
 		}
1298 1298
 
1299
-		$response = WC_Stripe_API::request( array(), "$intent_type/$intent_id", 'GET' );
1299
+		$response = WC_Stripe_API::request(array(), "$intent_type/$intent_id", 'GET');
1300 1300
 
1301
-		if ( $response && isset( $response->{ 'error' } ) ) {
1302
-			$error_response_message = print_r( $response, true );
1301
+		if ($response && isset($response->{ 'error' } )) {
1302
+			$error_response_message = print_r($response, true);
1303 1303
 			WC_Stripe_Logger::log("Failed to get Stripe intent $intent_type/$intent_id.");
1304 1304
 			WC_Stripe_Logger::log("Response: $error_response_message");
1305 1305
 			return false;
@@ -1316,18 +1316,18 @@  discard block
 block discarded – undo
1316 1316
 	 * @param stdClass $intent The intent that is being processed.
1317 1317
 	 * @return bool            A flag that indicates whether the order is already locked.
1318 1318
 	 */
1319
-	public function lock_order_payment( $order, $intent = null ) {
1319
+	public function lock_order_payment($order, $intent = null) {
1320 1320
 		$order_id       = $order->get_id();
1321 1321
 		$transient_name = 'wc_stripe_processing_intent_' . $order_id;
1322
-		$processing     = get_transient( $transient_name );
1322
+		$processing     = get_transient($transient_name);
1323 1323
 
1324 1324
 		// Block the process if the same intent is already being handled.
1325
-		if ( "-1" === $processing || ( isset( $intent->id ) && $processing === $intent->id ) ) {
1325
+		if ("-1" === $processing || (isset($intent->id) && $processing === $intent->id)) {
1326 1326
 			return true;
1327 1327
 		}
1328 1328
 
1329 1329
 		// Save the new intent as a transient, eventually overwriting another one.
1330
-		set_transient( $transient_name, empty( $intent ) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS );
1330
+		set_transient($transient_name, empty($intent) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS);
1331 1331
 
1332 1332
 		return false;
1333 1333
 	}
@@ -1338,9 +1338,9 @@  discard block
 block discarded – undo
1338 1338
 	 * @since 4.2
1339 1339
 	 * @param WC_Order $order The order that is being unlocked.
1340 1340
 	 */
1341
-	public function unlock_order_payment( $order ) {
1341
+	public function unlock_order_payment($order) {
1342 1342
 		$order_id = $order->get_id();
1343
-		delete_transient( 'wc_stripe_processing_intent_' . $order_id );
1343
+		delete_transient('wc_stripe_processing_intent_' . $order_id);
1344 1344
 	}
1345 1345
 
1346 1346
 	/**
@@ -1350,9 +1350,9 @@  discard block
 block discarded – undo
1350 1350
 	 * @param object $response The response from Stripe.
1351 1351
 	 * @return boolean Whether or not it's a 'authentication_required' error
1352 1352
 	 */
1353
-	public function is_authentication_required_for_payment( $response ) {
1354
-		return ( ! empty( $response->error ) && 'authentication_required' === $response->error->code )
1355
-			|| ( ! empty( $response->last_payment_error ) && 'authentication_required' === $response->last_payment_error->code );
1353
+	public function is_authentication_required_for_payment($response) {
1354
+		return ( ! empty($response->error) && 'authentication_required' === $response->error->code)
1355
+			|| ( ! empty($response->last_payment_error) && 'authentication_required' === $response->last_payment_error->code);
1356 1356
 	}
1357 1357
 
1358 1358
 	/**
@@ -1362,18 +1362,18 @@  discard block
 block discarded – undo
1362 1362
 	 * @param object   $prepared_source The source, entered/chosen by the customer.
1363 1363
 	 * @return string                   The client secret of the intent, used for confirmation in JS.
1364 1364
 	 */
1365
-	public function setup_intent( $order, $prepared_source ) {
1365
+	public function setup_intent($order, $prepared_source) {
1366 1366
 		$order_id     = $order->get_id();
1367
-		$setup_intent = WC_Stripe_API::request( array(
1367
+		$setup_intent = WC_Stripe_API::request(array(
1368 1368
 			'payment_method' => $prepared_source->source,
1369 1369
 			'customer'       => $prepared_source->customer,
1370 1370
 			'confirm'        => 'true',
1371
-		), 'setup_intents' );
1371
+		), 'setup_intents');
1372 1372
 
1373
-		if ( is_wp_error( $setup_intent ) ) {
1374
-			WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) );
1375
-		} elseif ( 'requires_action' === $setup_intent->status ) {
1376
-			$order->update_meta_data( '_stripe_setup_intent', $setup_intent->id );
1373
+		if (is_wp_error($setup_intent)) {
1374
+			WC_Stripe_Logger::log("Unable to create SetupIntent for Order #$order_id: " . print_r($setup_intent, true));
1375
+		} elseif ('requires_action' === $setup_intent->status) {
1376
+			$order->update_meta_data('_stripe_setup_intent', $setup_intent->id);
1377 1377
 			$order->save();
1378 1378
 
1379 1379
 			return $setup_intent->client_secret;
@@ -1388,12 +1388,12 @@  discard block
 block discarded – undo
1388 1388
 	 * @param float    $amount          The amount to charge. If not specified, it will be read from the order.
1389 1389
 	 * @return object                   An intent or an error.
1390 1390
 	 */
1391
-	public function create_and_confirm_intent_for_off_session( $order, $prepared_source, $amount = NULL ) {
1391
+	public function create_and_confirm_intent_for_off_session($order, $prepared_source, $amount = NULL) {
1392 1392
 		// The request for a charge contains metadata for the intent.
1393
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1393
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1394 1394
 
1395 1395
 		$request = array(
1396
-			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount( $amount, $full_request['currency'] ) : $full_request['amount'],
1396
+			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount($amount, $full_request['currency']) : $full_request['amount'],
1397 1397
 			'currency'             => $full_request['currency'],
1398 1398
 			'description'          => $full_request['description'],
1399 1399
 			'metadata'             => $full_request['metadata'],
@@ -1405,17 +1405,17 @@  discard block
 block discarded – undo
1405 1405
 			'confirmation_method'  => 'automatic',
1406 1406
 		);
1407 1407
 
1408
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1408
+		if (isset($full_request['statement_descriptor'])) {
1409 1409
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1410 1410
 		}
1411 1411
 
1412
-		if ( isset( $full_request['customer'] ) ) {
1412
+		if (isset($full_request['customer'])) {
1413 1413
 			$request['customer'] = $full_request['customer'];
1414 1414
 		}
1415 1415
 
1416
-		if ( isset( $full_request['source'] ) ) {
1417
-			$is_source = 'src_' === substr( $full_request['source'], 0, 4 );
1418
-			$request[ $is_source ? 'source' : 'payment_method' ] = $full_request['source'];
1416
+		if (isset($full_request['source'])) {
1417
+			$is_source = 'src_' === substr($full_request['source'], 0, 4);
1418
+			$request[$is_source ? 'source' : 'payment_method'] = $full_request['source'];
1419 1419
 		}
1420 1420
 
1421 1421
 		/**
@@ -1426,38 +1426,38 @@  discard block
 block discarded – undo
1426 1426
 		 * @param WC_Order $order
1427 1427
 		 * @param object $source
1428 1428
 		 */
1429
-		$request = apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source );
1429
+		$request = apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source);
1430 1430
 
1431
-		if ( isset( $full_request['shipping'] ) ) {
1431
+		if (isset($full_request['shipping'])) {
1432 1432
 			$request['shipping'] = $full_request['shipping'];
1433 1433
 		}
1434 1434
 
1435
-		$level3_data = $this->get_level3_data_from_order( $order );
1435
+		$level3_data = $this->get_level3_data_from_order($order);
1436 1436
 		$intent = WC_Stripe_API::request_with_level3_data(
1437 1437
 			$request,
1438 1438
 			'payment_intents',
1439 1439
 			$level3_data,
1440 1440
 			$order
1441 1441
 		);
1442
-		$is_authentication_required = $this->is_authentication_required_for_payment( $intent );
1442
+		$is_authentication_required = $this->is_authentication_required_for_payment($intent);
1443 1443
 
1444
-		if ( ! empty( $intent->error ) && ! $is_authentication_required ) {
1444
+		if ( ! empty($intent->error) && ! $is_authentication_required) {
1445 1445
 			return $intent;
1446 1446
 		}
1447 1447
 
1448
-		$intent_id      = ( ! empty( $intent->error )
1448
+		$intent_id = ( ! empty($intent->error)
1449 1449
 			? $intent->error->payment_intent->id
1450 1450
 			: $intent->id
1451 1451
 		);
1452
-		$payment_intent = ( ! empty( $intent->error )
1452
+		$payment_intent = ( ! empty($intent->error)
1453 1453
 			? $intent->error->payment_intent
1454 1454
 			: $intent
1455 1455
 		);
1456
-		$order_id       = $order->get_id();
1457
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent_id initiated for order $order_id" );
1456
+		$order_id = $order->get_id();
1457
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent_id initiated for order $order_id");
1458 1458
 
1459 1459
 		// Save the intent ID to the order.
1460
-		$this->save_intent_to_order( $order, $payment_intent );
1460
+		$this->save_intent_to_order($order, $payment_intent);
1461 1461
 
1462 1462
 		return $intent;
1463 1463
 	}
@@ -1468,13 +1468,13 @@  discard block
 block discarded – undo
1468 1468
 	 * Fix renewal for existing subscriptions affected by https://github.com/woocommerce/woocommerce-gateway-stripe/issues/1072.
1469 1469
 	 * @param int $order_id subscription renewal order id.
1470 1470
 	 */
1471
-	public function ensure_subscription_has_customer_id( $order_id ) {
1472
-		$subscriptions_ids = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => 'any' ) );
1473
-		foreach( $subscriptions_ids as $subscription_id => $subscription ) {
1474
-			if ( ! metadata_exists( 'post', $subscription_id, '_stripe_customer_id' ) ) {
1475
-				$stripe_customer = new WC_Stripe_Customer( $subscription->get_user_id() );
1476
-				update_post_meta( $subscription_id, '_stripe_customer_id', $stripe_customer->get_id() );
1477
-				update_post_meta( $order_id, '_stripe_customer_id', $stripe_customer->get_id() );
1471
+	public function ensure_subscription_has_customer_id($order_id) {
1472
+		$subscriptions_ids = wcs_get_subscriptions_for_order($order_id, array('order_type' => 'any'));
1473
+		foreach ($subscriptions_ids as $subscription_id => $subscription) {
1474
+			if ( ! metadata_exists('post', $subscription_id, '_stripe_customer_id')) {
1475
+				$stripe_customer = new WC_Stripe_Customer($subscription->get_user_id());
1476
+				update_post_meta($subscription_id, '_stripe_customer_id', $stripe_customer->get_id());
1477
+				update_post_meta($order_id, '_stripe_customer_id', $stripe_customer->get_id());
1478 1478
 			}
1479 1479
 		}
1480 1480
 	}
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
 	 * @param string $zip The ZIP code to verify.
1485 1485
 	 * @return boolean
1486 1486
 	 */
1487
-	public function is_valid_us_zip_code( $zip ) {
1488
-		return ! empty( $zip ) && preg_match( '/^\d{5,5}(-\d{4,4})?$/', $zip );
1487
+	public function is_valid_us_zip_code($zip) {
1488
+		return ! empty($zip) && preg_match('/^\d{5,5}(-\d{4,4})?$/', $zip);
1489 1489
 	}
1490 1490
 }
Please login to merge, or discard this patch.