Completed
Pull Request — master (#1224)
by
unknown
02:13
created
includes/admin/stripe-settings.php 1 patch
Spacing   +67 added lines, -67 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
 
@@ -7,182 +7,182 @@  discard block
 block discarded – undo
7 7
 	'wc_stripe_settings',
8 8
 	array(
9 9
 		'enabled'                       => array(
10
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
11
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
10
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
11
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
12 12
 			'type'        => 'checkbox',
13 13
 			'description' => '',
14 14
 			'default'     => 'no',
15 15
 		),
16 16
 		'title'                         => array(
17
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
17
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
18 18
 			'type'        => 'text',
19
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
20
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
19
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
20
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
21 21
 			'desc_tip'    => true,
22 22
 		),
23 23
 		'description'                   => array(
24
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
24
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
25 25
 			'type'        => 'text',
26
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
27
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
26
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
27
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
28 28
 			'desc_tip'    => true,
29 29
 		),
30 30
 		'testmode'                      => array(
31
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
32
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
31
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
32
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
33 33
 			'type'        => 'checkbox',
34
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
34
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
35 35
 			'default'     => 'yes',
36 36
 			'desc_tip'    => true,
37 37
 		),
38 38
 		'test_publishable_key'          => array(
39
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
39
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
40 40
 			'type'        => 'text',
41
-			'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_test_" will be saved.', 'woocommerce-gateway-stripe' ),
41
+			'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_test_" will be saved.', 'woocommerce-gateway-stripe'),
42 42
 			'default'     => '',
43 43
 			'desc_tip'    => true,
44 44
 		),
45 45
 		'test_secret_key'               => array(
46
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
46
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
47 47
 			'type'        => 'password',
48
-			'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_test_" or "rk_test_" will be saved.', 'woocommerce-gateway-stripe' ),
48
+			'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_test_" or "rk_test_" will be saved.', 'woocommerce-gateway-stripe'),
49 49
 			'default'     => '',
50 50
 			'desc_tip'    => true,
51 51
 		),
52 52
 		'publishable_key'               => array(
53
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
53
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
54 54
 			'type'        => 'text',
55
-			'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_live_" will be saved.', 'woocommerce-gateway-stripe' ),
55
+			'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_live_" will be saved.', 'woocommerce-gateway-stripe'),
56 56
 			'default'     => '',
57 57
 			'desc_tip'    => true,
58 58
 		),
59 59
 		'secret_key'                    => array(
60
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
60
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
61 61
 			'type'        => 'password',
62
-			'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_live_" or "rk_live_" will be saved.', 'woocommerce-gateway-stripe' ),
62
+			'description' => __('Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_live_" or "rk_live_" will be saved.', 'woocommerce-gateway-stripe'),
63 63
 			'default'     => '',
64 64
 			'desc_tip'    => true,
65 65
 		),
66 66
 		'webhook'                       => array(
67
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
67
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
68 68
 			'type'        => 'title',
69 69
 			/* translators: webhook URL */
70 70
 			'description' => $this->display_admin_settings_webhook_description(),
71 71
 		),
72 72
 		'test_webhook_secret'           => array(
73
-			'title'       => __( 'Test Webhook Secret', 'woocommerce-gateway-stripe' ),
73
+			'title'       => __('Test Webhook Secret', 'woocommerce-gateway-stripe'),
74 74
 			'type'        => 'password',
75
-			'description' => __( 'Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe' ),
75
+			'description' => __('Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe'),
76 76
 			'default'     => '',
77 77
 			'desc_tip'    => true,
78 78
 		),
79 79
 		'webhook_secret'               => array(
80
-			'title'       => __( 'Webhook Secret', 'woocommerce-gateway-stripe' ),
80
+			'title'       => __('Webhook Secret', 'woocommerce-gateway-stripe'),
81 81
 			'type'        => 'password',
82
-			'description' => __( 'Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe' ),
82
+			'description' => __('Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe'),
83 83
 			'default'     => '',
84 84
 			'desc_tip'    => true,
85 85
 		),
86 86
 		'inline_cc_form'                => array(
87
-			'title'       => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ),
87
+			'title'       => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'),
88 88
 			'type'        => 'checkbox',
89
-			'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ),
89
+			'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'),
90 90
 			'default'     => 'no',
91 91
 			'desc_tip'    => true,
92 92
 		),
93 93
 		'statement_descriptor'          => array(
94
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
94
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
95 95
 			'type'        => 'text',
96
-			'description' => __( 'Statement descriptors are limited to 22 characters, cannot use the special characters >, <, ", \, \', *, and must not consist solely of numbers. This will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ),
96
+			'description' => __('Statement descriptors are limited to 22 characters, cannot use the special characters >, <, ", \, \', *, and must not consist solely of numbers. This will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'),
97 97
 			'default'     => '',
98 98
 			'desc_tip'    => true,
99 99
 		),
100 100
 		'capture'                       => array(
101
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
102
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
101
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
102
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
103 103
 			'type'        => 'checkbox',
104
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
104
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
105 105
 			'default'     => 'yes',
106 106
 			'desc_tip'    => true,
107 107
 		),
108 108
 		'payment_request'               => array(
109
-			'title'       => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ),
109
+			'title'       => __('Payment Request Buttons', 'woocommerce-gateway-stripe'),
110 110
 			/* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */
111
-			'label'       => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ),
111
+			'label'       => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'),
112 112
 			'type'        => 'checkbox',
113
-			'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ),
113
+			'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'),
114 114
 			'default'     => 'yes',
115 115
 			'desc_tip'    => true,
116 116
 		),
117 117
 		'payment_request_button_type'   => array(
118
-			'title'       => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ),
119
-			'label'       => __( 'Button Type', 'woocommerce-gateway-stripe' ),
118
+			'title'       => __('Payment Request Button Type', 'woocommerce-gateway-stripe'),
119
+			'label'       => __('Button Type', 'woocommerce-gateway-stripe'),
120 120
 			'type'        => 'select',
121
-			'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ),
121
+			'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'),
122 122
 			'default'     => 'buy',
123 123
 			'desc_tip'    => true,
124 124
 			'options'     => array(
125
-				'default' => __( 'Default', 'woocommerce-gateway-stripe' ),
126
-				'buy'     => __( 'Buy', 'woocommerce-gateway-stripe' ),
127
-				'donate'  => __( 'Donate', 'woocommerce-gateway-stripe' ),
128
-				'branded' => __( 'Branded', 'woocommerce-gateway-stripe' ),
129
-				'custom'  => __( 'Custom', 'woocommerce-gateway-stripe' ),
125
+				'default' => __('Default', 'woocommerce-gateway-stripe'),
126
+				'buy'     => __('Buy', 'woocommerce-gateway-stripe'),
127
+				'donate'  => __('Donate', 'woocommerce-gateway-stripe'),
128
+				'branded' => __('Branded', 'woocommerce-gateway-stripe'),
129
+				'custom'  => __('Custom', 'woocommerce-gateway-stripe'),
130 130
 			),
131 131
 		),
132 132
 		'payment_request_button_theme'  => array(
133
-			'title'       => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ),
134
-			'label'       => __( 'Button Theme', 'woocommerce-gateway-stripe' ),
133
+			'title'       => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'),
134
+			'label'       => __('Button Theme', 'woocommerce-gateway-stripe'),
135 135
 			'type'        => 'select',
136
-			'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ),
136
+			'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'),
137 137
 			'default'     => 'dark',
138 138
 			'desc_tip'    => true,
139 139
 			'options'     => array(
140
-				'dark'          => __( 'Dark', 'woocommerce-gateway-stripe' ),
141
-				'light'         => __( 'Light', 'woocommerce-gateway-stripe' ),
142
-				'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ),
140
+				'dark'          => __('Dark', 'woocommerce-gateway-stripe'),
141
+				'light'         => __('Light', 'woocommerce-gateway-stripe'),
142
+				'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'),
143 143
 			),
144 144
 		),
145 145
 		'payment_request_button_height' => array(
146
-			'title'       => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ),
147
-			'label'       => __( 'Button Height', 'woocommerce-gateway-stripe' ),
146
+			'title'       => __('Payment Request Button Height', 'woocommerce-gateway-stripe'),
147
+			'label'       => __('Button Height', 'woocommerce-gateway-stripe'),
148 148
 			'type'        => 'text',
149
-			'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ),
149
+			'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'),
150 150
 			'default'     => '44',
151 151
 			'desc_tip'    => true,
152 152
 		),
153 153
 		'payment_request_button_label' => array(
154
-			'title'       => __( 'Payment Request Button Label', 'woocommerce-gateway-stripe' ),
155
-			'label'       => __( 'Button Label', 'woocommerce-gateway-stripe' ),
154
+			'title'       => __('Payment Request Button Label', 'woocommerce-gateway-stripe'),
155
+			'label'       => __('Button Label', 'woocommerce-gateway-stripe'),
156 156
 			'type'        => 'text',
157
-			'description' => __( 'Enter the custom text you would like the button to have.', 'woocommerce-gateway-stripe' ),
158
-			'default'     => __( 'Buy now', 'woocommerce-gateway-stripe' ),
157
+			'description' => __('Enter the custom text you would like the button to have.', 'woocommerce-gateway-stripe'),
158
+			'default'     => __('Buy now', 'woocommerce-gateway-stripe'),
159 159
 			'desc_tip'    => true,
160 160
 		),
161 161
 		'payment_request_button_branded_type' => array(
162
-			'title'       => __( 'Payment Request Branded Button Label Format', 'woocommerce-gateway-stripe' ),
163
-			'label'       => __( 'Branded Button Label Format', 'woocommerce-gateway-stripe' ),
162
+			'title'       => __('Payment Request Branded Button Label Format', 'woocommerce-gateway-stripe'),
163
+			'label'       => __('Branded Button Label Format', 'woocommerce-gateway-stripe'),
164 164
 			'type'        => 'select',
165
-			'description' => __( 'Select the branded button label format.', 'woocommerce-gateway-stripe' ),
165
+			'description' => __('Select the branded button label format.', 'woocommerce-gateway-stripe'),
166 166
 			'default'     => 'long',
167 167
 			'desc_tip'    => true,
168 168
 			'options'     => array(
169
-				'short' => __( 'Logo only', 'woocommerce-gateway-stripe' ),
170
-				'long'  => __( 'Text and logo', 'woocommerce-gateway-stripe' ),
169
+				'short' => __('Logo only', 'woocommerce-gateway-stripe'),
170
+				'long'  => __('Text and logo', 'woocommerce-gateway-stripe'),
171 171
 			),
172 172
 		),
173 173
 		'saved_cards'                   => array(
174
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
175
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
174
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
175
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
176 176
 			'type'        => 'checkbox',
177
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
177
+			'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'),
178 178
 			'default'     => 'yes',
179 179
 			'desc_tip'    => true,
180 180
 		),
181 181
 		'logging'                       => array(
182
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
183
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
182
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
183
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
184 184
 			'type'        => 'checkbox',
185
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
185
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
186 186
 			'default'     => 'no',
187 187
 			'desc_tip'    => true,
188 188
 		),
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +234 added lines, -234 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
 		// Get/set the time we began monitoring the health of webhooks by fetching it.
50 50
 		// This should be roughly the same as the activation time of the version of the
@@ -59,32 +59,32 @@  discard block
 block discarded – undo
59 59
 	 * @version 4.0.0
60 60
 	 */
61 61
 	public function check_for_webhook() {
62
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
63
-			|| ! isset( $_GET['wc-api'] )
64
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
62
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
63
+			|| ! isset($_GET['wc-api'])
64
+			|| ('wc_stripe' !== $_GET['wc-api'])
65 65
 		) {
66 66
 			return;
67 67
 		}
68 68
 
69
-		$request_body    = file_get_contents( 'php://input' );
70
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
69
+		$request_body    = file_get_contents('php://input');
70
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
71 71
 
72 72
 		// Validate it to make sure it is legit.
73
-		$validation_result = $this->validate_request( $request_headers, $request_body );
74
-		if ( WC_Stripe_Webhook_State::VALIDATION_SUCCEEDED === $validation_result ) {
75
-			$this->process_webhook( $request_body );
73
+		$validation_result = $this->validate_request($request_headers, $request_body);
74
+		if (WC_Stripe_Webhook_State::VALIDATION_SUCCEEDED === $validation_result) {
75
+			$this->process_webhook($request_body);
76 76
 
77
-			$notification = json_decode( $request_body );
78
-			WC_Stripe_Webhook_State::set_last_webhook_success_at( $notification->created );
77
+			$notification = json_decode($request_body);
78
+			WC_Stripe_Webhook_State::set_last_webhook_success_at($notification->created);
79 79
 
80
-			status_header( 200 );
80
+			status_header(200);
81 81
 			exit;
82 82
 		} else {
83
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
84
-			WC_Stripe_Webhook_State::set_last_webhook_failure_at( current_time( 'timestamp', true ) );
85
-			WC_Stripe_Webhook_State::set_last_error_reason( $validation_result );
83
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
84
+			WC_Stripe_Webhook_State::set_last_webhook_failure_at(current_time('timestamp', true));
85
+			WC_Stripe_Webhook_State::set_last_error_reason($validation_result);
86 86
 
87
-			status_header( 400 );
87
+			status_header(400);
88 88
 			exit;
89 89
 		}
90 90
 	}
@@ -98,37 +98,37 @@  discard block
 block discarded – undo
98 98
 	 * @param string $request_body The request body from Stripe.
99 99
 	 * @return string The validation result (e.g. self::VALIDATION_SUCCEEDED )
100 100
 	 */
101
-	public function validate_request( $request_headers = null, $request_body = null ) {
102
-		if ( null === $request_headers ) {
101
+	public function validate_request($request_headers = null, $request_body = null) {
102
+		if (null === $request_headers) {
103 103
 			return WC_Stripe_Webhook_State::VALIDATION_FAILED_HEADERS_NULL;
104 104
 		}
105
-		if ( null === $request_body ) {
105
+		if (null === $request_body) {
106 106
 			return WC_Stripe_Webhook_State::VALIDATION_FAILED_BODY_NULL;
107 107
 		}
108 108
 
109
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
109
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
110 110
 			return WC_Stripe_Webhook_State::VALIDATION_FAILED_USER_AGENT_INVALID;
111 111
 		}
112 112
 
113
-		if ( ! empty( $this->secret ) ) {
113
+		if ( ! empty($this->secret)) {
114 114
 			// Check for a valid signature.
115 115
 			$signature_format = '/^t=(?P<timestamp>\d+)(?P<signatures>(,v\d+=[a-z0-9]+){1,2})$/';
116
-			if ( empty( $request_headers['STRIPE-SIGNATURE'] ) || ! preg_match( $signature_format, $request_headers['STRIPE-SIGNATURE'], $matches ) ) {
116
+			if (empty($request_headers['STRIPE-SIGNATURE']) || ! preg_match($signature_format, $request_headers['STRIPE-SIGNATURE'], $matches)) {
117 117
 				return WC_Stripe_Webhook_State::VALIDATION_FAILED_SIGNATURE_INVALID;
118 118
 			}
119 119
 
120 120
 			// Verify the timestamp.
121
-			$timestamp = intval( $matches['timestamp'] );
122
-			if ( abs( $timestamp - time() ) > 5 * MINUTE_IN_SECONDS ) {
121
+			$timestamp = intval($matches['timestamp']);
122
+			if (abs($timestamp - time()) > 5 * MINUTE_IN_SECONDS) {
123 123
 				return WC_Stripe_Webhook_State::VALIDATION_FAILED_TIMESTAMP_MISMATCH;
124 124
 			}
125 125
 
126 126
 			// Generate the expected signature.
127 127
 			$signed_payload     = $timestamp . '.' . $request_body;
128
-			$expected_signature = hash_hmac( 'sha256', $signed_payload, $this->secret );
128
+			$expected_signature = hash_hmac('sha256', $signed_payload, $this->secret);
129 129
 
130 130
 			// Check if the expected signature is present.
131
-			if ( ! preg_match( '/,v\d+=' . preg_quote( $expected_signature, '/' ) . '/', $matches['signatures'] ) ) {
131
+			if ( ! preg_match('/,v\d+=' . preg_quote($expected_signature, '/') . '/', $matches['signatures'])) {
132 132
 				return WC_Stripe_Webhook_State::VALIDATION_FAILED_SIGNATURE_MISMATCH;
133 133
 			}
134 134
 		}
@@ -145,12 +145,12 @@  discard block
 block discarded – undo
145 145
 	 * @version 4.0.0
146 146
 	 */
147 147
 	public function get_request_headers() {
148
-		if ( ! function_exists( 'getallheaders' ) ) {
148
+		if ( ! function_exists('getallheaders')) {
149 149
 			$headers = array();
150 150
 
151
-			foreach ( $_SERVER as $name => $value ) {
152
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
153
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
151
+			foreach ($_SERVER as $name => $value) {
152
+				if ('HTTP_' === substr($name, 0, 5)) {
153
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
154 154
 				}
155 155
 			}
156 156
 
@@ -169,30 +169,30 @@  discard block
 block discarded – undo
169 169
 	 * @param object $notification
170 170
 	 * @param bool $retry
171 171
 	 */
172
-	public function process_webhook_payment( $notification, $retry = true ) {
172
+	public function process_webhook_payment($notification, $retry = true) {
173 173
 		// The following 3 payment methods are synchronous so does not need to be handle via webhook.
174
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) {
174
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) {
175 175
 			return;
176 176
 		}
177 177
 
178
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
178
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
179 179
 
180
-		if ( ! $order ) {
181
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
180
+		if ( ! $order) {
181
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
182 182
 			return;
183 183
 		}
184 184
 
185 185
 		$order_id  = $order->get_id();
186 186
 		$source_id = $notification->data->object->id;
187 187
 
188
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
188
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
189 189
 
190 190
 		try {
191
-			if ( $order->has_status( array( 'processing', 'completed' ) ) ) {
191
+			if ($order->has_status(array('processing', 'completed'))) {
192 192
 				return;
193 193
 			}
194 194
 
195
-			if ( $order->has_status( 'on-hold' ) && ! $is_pending_receiver ) {
195
+			if ($order->has_status('on-hold') && ! $is_pending_receiver) {
196 196
 				return;
197 197
 			}
198 198
 
@@ -200,89 +200,89 @@  discard block
 block discarded – undo
200 200
 			$response = null;
201 201
 
202 202
 			// This will throw exception if not valid.
203
-			$this->validate_minimum_order_amount( $order );
203
+			$this->validate_minimum_order_amount($order);
204 204
 
205
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
205
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
206 206
 
207 207
 			// Prep source object.
208 208
 			$source_object           = new stdClass();
209 209
 			$source_object->token_id = '';
210
-			$source_object->customer = $this->get_stripe_customer_id( $order );
210
+			$source_object->customer = $this->get_stripe_customer_id($order);
211 211
 			$source_object->source   = $source_id;
212 212
 
213 213
 			// Make the request.
214
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
214
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
215 215
 			$headers  = $response['headers'];
216 216
 			$response = $response['body'];
217 217
 
218
-			if ( ! empty( $response->error ) ) {
218
+			if ( ! empty($response->error)) {
219 219
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
220
-				if ( $this->is_no_such_customer_error( $response->error ) ) {
221
-					delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
222
-					$order->delete_meta_data( '_stripe_customer_id' );
220
+				if ($this->is_no_such_customer_error($response->error)) {
221
+					delete_user_option($order->get_customer_id(), '_stripe_customer_id');
222
+					$order->delete_meta_data('_stripe_customer_id');
223 223
 					$order->save();
224 224
 				}
225 225
 
226
-				if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
226
+				if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
227 227
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
228
-					$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
228
+					$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
229 229
 					$wc_token->delete();
230
-					$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
231
-					$order->add_order_note( $localized_message );
232
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
230
+					$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
231
+					$order->add_order_note($localized_message);
232
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
233 233
 				}
234 234
 
235 235
 				// We want to retry.
236
-				if ( $this->is_retryable_error( $response->error ) ) {
237
-					if ( $retry ) {
236
+				if ($this->is_retryable_error($response->error)) {
237
+					if ($retry) {
238 238
 						// Don't do anymore retries after this.
239
-						if ( 5 <= $this->retry_interval ) {
239
+						if (5 <= $this->retry_interval) {
240 240
 
241
-							return $this->process_webhook_payment( $notification, false );
241
+							return $this->process_webhook_payment($notification, false);
242 242
 						}
243 243
 
244
-						sleep( $this->retry_interval );
244
+						sleep($this->retry_interval);
245 245
 
246 246
 						$this->retry_interval++;
247
-						return $this->process_webhook_payment( $notification, true );
247
+						return $this->process_webhook_payment($notification, true);
248 248
 					} else {
249
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
250
-						$order->add_order_note( $localized_message );
251
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
249
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
250
+						$order->add_order_note($localized_message);
251
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
252 252
 					}
253 253
 				}
254 254
 
255 255
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
256 256
 
257
-				if ( 'card_error' === $response->error->type ) {
258
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
257
+				if ('card_error' === $response->error->type) {
258
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
259 259
 				} else {
260
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
260
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
261 261
 				}
262 262
 
263
-				$order->add_order_note( $localized_message );
263
+				$order->add_order_note($localized_message);
264 264
 
265
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
265
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
266 266
 			}
267 267
 
268 268
 			// To prevent double processing the order on WC side.
269
-			if ( ! $this->is_original_request( $headers ) ) {
269
+			if ( ! $this->is_original_request($headers)) {
270 270
 				return;
271 271
 			}
272 272
 
273
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
273
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
274 274
 
275
-			$this->process_response( $response, $order );
275
+			$this->process_response($response, $order);
276 276
 
277
-		} catch ( WC_Stripe_Exception $e ) {
278
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
277
+		} catch (WC_Stripe_Exception $e) {
278
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
279 279
 
280
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e );
280
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e);
281 281
 
282
-			$statuses = array( 'pending', 'failed' );
282
+			$statuses = array('pending', 'failed');
283 283
 
284
-			if ( $order->has_status( $statuses ) ) {
285
-				$this->send_failed_order_email( $order_id );
284
+			if ($order->has_status($statuses)) {
285
+				$this->send_failed_order_email($order_id);
286 286
 			}
287 287
 		}
288 288
 	}
@@ -295,21 +295,21 @@  discard block
 block discarded – undo
295 295
 	 * @since 4.0.0
296 296
 	 * @param object $notification
297 297
 	 */
298
-	public function process_webhook_dispute( $notification ) {
299
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
298
+	public function process_webhook_dispute($notification) {
299
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
300 300
 
301
-		if ( ! $order ) {
302
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
301
+		if ( ! $order) {
302
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
303 303
 			return;
304 304
 		}
305 305
 
306 306
 		/* translators: 1) The URL to the order. */
307
-		$order->update_status( 'on-hold', sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ) );
307
+		$order->update_status('on-hold', sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order)));
308 308
 
309
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
309
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
310 310
 
311 311
 		$order_id = $order->get_id();
312
-		$this->send_failed_order_email( $order_id );
312
+		$this->send_failed_order_email($order_id);
313 313
 	}
314 314
 
315 315
 	/**
@@ -320,43 +320,43 @@  discard block
 block discarded – undo
320 320
 	 * @version 4.0.0
321 321
 	 * @param object $notification
322 322
 	 */
323
-	public function process_webhook_capture( $notification ) {
324
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
323
+	public function process_webhook_capture($notification) {
324
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
325 325
 
326
-		if ( ! $order ) {
327
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
326
+		if ( ! $order) {
327
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
328 328
 			return;
329 329
 		}
330 330
 
331
-		if ( 'stripe' === $order->get_payment_method() ) {
331
+		if ('stripe' === $order->get_payment_method()) {
332 332
 			$charge   = $order->get_transaction_id();
333
-			$captured = $order->get_meta( '_stripe_charge_captured', true );
333
+			$captured = $order->get_meta('_stripe_charge_captured', true);
334 334
 
335
-			if ( $charge && 'no' === $captured ) {
336
-				$order->update_meta_data( '_stripe_charge_captured', 'yes' );
335
+			if ($charge && 'no' === $captured) {
336
+				$order->update_meta_data('_stripe_charge_captured', 'yes');
337 337
 
338 338
 				// Store other data such as fees
339
-				$order->set_transaction_id( $notification->data->object->id );
339
+				$order->set_transaction_id($notification->data->object->id);
340 340
 
341
-				if ( isset( $notification->data->object->balance_transaction ) ) {
342
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
341
+				if (isset($notification->data->object->balance_transaction)) {
342
+					$this->update_fees($order, $notification->data->object->balance_transaction);
343 343
 				}
344 344
 
345 345
 				// Check and see if capture is partial.
346
-				if ( $this->is_partial_capture( $notification ) ) {
347
-					$partial_amount = $this->get_partial_amount_to_charge( $notification );
348
-					$order->set_total( $partial_amount );
349
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
346
+				if ($this->is_partial_capture($notification)) {
347
+					$partial_amount = $this->get_partial_amount_to_charge($notification);
348
+					$order->set_total($partial_amount);
349
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
350 350
 					/* translators: partial captured amount */
351
-					$order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) );
351
+					$order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount));
352 352
 				} else {
353
-					$order->payment_complete( $notification->data->object->id );
353
+					$order->payment_complete($notification->data->object->id);
354 354
 
355 355
 					/* translators: transaction id */
356
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
356
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
357 357
 				}
358 358
 
359
-				if ( is_callable( array( $order, 'save' ) ) ) {
359
+				if (is_callable(array($order, 'save'))) {
360 360
 					$order->save();
361 361
 				}
362 362
 			}
@@ -371,41 +371,41 @@  discard block
 block discarded – undo
371 371
 	 * @version 4.0.0
372 372
 	 * @param object $notification
373 373
 	 */
374
-	public function process_webhook_charge_succeeded( $notification ) {
374
+	public function process_webhook_charge_succeeded($notification) {
375 375
 		// Ignore the notification for charges, created through PaymentIntents.
376
-		if ( isset( $notification->data->object->payment_intent ) && $notification->data->object->payment_intent ) {
376
+		if (isset($notification->data->object->payment_intent) && $notification->data->object->payment_intent) {
377 377
 			return;
378 378
 		}
379 379
 
380 380
 		// The following payment methods are synchronous so does not need to be handle via webhook.
381
-		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 ) ) {
381
+		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)) {
382 382
 			return;
383 383
 		}
384 384
 
385
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
385
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
386 386
 
387
-		if ( ! $order ) {
388
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
387
+		if ( ! $order) {
388
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
389 389
 			return;
390 390
 		}
391 391
 
392
-		if ( ! $order->has_status( 'on-hold' ) ) {
392
+		if ( ! $order->has_status('on-hold')) {
393 393
 			return;
394 394
 		}
395 395
 
396 396
 		// Store other data such as fees
397
-		$order->set_transaction_id( $notification->data->object->id );
397
+		$order->set_transaction_id($notification->data->object->id);
398 398
 
399
-		if ( isset( $notification->data->object->balance_transaction ) ) {
400
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
399
+		if (isset($notification->data->object->balance_transaction)) {
400
+			$this->update_fees($order, $notification->data->object->balance_transaction);
401 401
 		}
402 402
 
403
-		$order->payment_complete( $notification->data->object->id );
403
+		$order->payment_complete($notification->data->object->id);
404 404
 
405 405
 		/* translators: transaction id */
406
-		$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
406
+		$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
407 407
 
408
-		if ( is_callable( array( $order, 'save' ) ) ) {
408
+		if (is_callable(array($order, 'save'))) {
409 409
 			$order->save();
410 410
 		}
411 411
 	}
@@ -417,22 +417,22 @@  discard block
 block discarded – undo
417 417
 	 * @since 4.1.5 Can handle any fail payments from any methods.
418 418
 	 * @param object $notification
419 419
 	 */
420
-	public function process_webhook_charge_failed( $notification ) {
421
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
420
+	public function process_webhook_charge_failed($notification) {
421
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
422 422
 
423
-		if ( ! $order ) {
424
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
423
+		if ( ! $order) {
424
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
425 425
 			return;
426 426
 		}
427 427
 
428 428
 		// If order status is already in failed status don't continue.
429
-		if ( $order->has_status( 'failed' ) ) {
429
+		if ($order->has_status('failed')) {
430 430
 			return;
431 431
 		}
432 432
 
433
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
433
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
434 434
 
435
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
435
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
436 436
 	}
437 437
 
438 438
 	/**
@@ -443,30 +443,30 @@  discard block
 block discarded – undo
443 443
 	 * @since 4.1.15 Add check to make sure order is processed by Stripe.
444 444
 	 * @param object $notification
445 445
 	 */
446
-	public function process_webhook_source_canceled( $notification ) {
447
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
446
+	public function process_webhook_source_canceled($notification) {
447
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
448 448
 
449 449
 		// If can't find order by charge ID, try source ID.
450
-		if ( ! $order ) {
451
-			$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
450
+		if ( ! $order) {
451
+			$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
452 452
 
453
-			if ( ! $order ) {
454
-				WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id );
453
+			if ( ! $order) {
454
+				WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id);
455 455
 				return;
456 456
 			}
457 457
 		}
458 458
 
459 459
 		// Don't proceed if payment method isn't Stripe.
460
-		if ( 'stripe' !== $order->get_payment_method() ) {
461
-			WC_Stripe_Logger::log( 'Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id() );
460
+		if ('stripe' !== $order->get_payment_method()) {
461
+			WC_Stripe_Logger::log('Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id());
462 462
 			return;
463 463
 		}
464 464
 
465
-		if ( ! $order->has_status( 'cancelled' ) ) {
466
-			$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
465
+		if ( ! $order->has_status('cancelled')) {
466
+			$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
467 467
 		}
468 468
 
469
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
469
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
470 470
 	}
471 471
 
472 472
 	/**
@@ -476,59 +476,59 @@  discard block
 block discarded – undo
476 476
 	 * @version 4.0.0
477 477
 	 * @param object $notification
478 478
 	 */
479
-	public function process_webhook_refund( $notification ) {
480
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
479
+	public function process_webhook_refund($notification) {
480
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
481 481
 
482
-		if ( ! $order ) {
483
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
482
+		if ( ! $order) {
483
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
484 484
 			return;
485 485
 		}
486 486
 
487 487
 		$order_id = $order->get_id();
488 488
 
489
-		if ( 'stripe' === $order->get_payment_method() ) {
489
+		if ('stripe' === $order->get_payment_method()) {
490 490
 			$charge    = $order->get_transaction_id();
491
-			$captured  = $order->get_meta( '_stripe_charge_captured', true );
492
-			$refund_id = $order->get_meta( '_stripe_refund_id', true );
491
+			$captured  = $order->get_meta('_stripe_charge_captured', true);
492
+			$refund_id = $order->get_meta('_stripe_refund_id', true);
493 493
 
494 494
 			// If the refund ID matches, don't continue to prevent double refunding.
495
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
495
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
496 496
 				return;
497 497
 			}
498 498
 
499 499
 			// Only refund captured charge.
500
-			if ( $charge ) {
501
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
500
+			if ($charge) {
501
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
502 502
 
503 503
 				// Create the refund.
504 504
 				$refund = wc_create_refund(
505 505
 					array(
506 506
 						'order_id' => $order_id,
507
-						'amount'   => $this->get_refund_amount( $notification ),
507
+						'amount'   => $this->get_refund_amount($notification),
508 508
 						'reason'   => $reason,
509 509
 					)
510 510
 				);
511 511
 
512
-				if ( is_wp_error( $refund ) ) {
513
-					WC_Stripe_Logger::log( $refund->get_error_message() );
512
+				if (is_wp_error($refund)) {
513
+					WC_Stripe_Logger::log($refund->get_error_message());
514 514
 				}
515 515
 
516
-				$order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id );
516
+				$order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id);
517 517
 
518
-				$amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 );
518
+				$amount = wc_price($notification->data->object->refunds->data[0]->amount / 100);
519 519
 
520
-				if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
521
-					$amount = wc_price( $notification->data->object->refunds->data[0]->amount );
520
+				if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
521
+					$amount = wc_price($notification->data->object->refunds->data[0]->amount);
522 522
 				}
523 523
 
524
-				if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) {
525
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
524
+				if (isset($notification->data->object->refunds->data[0]->balance_transaction)) {
525
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
526 526
 				}
527 527
 
528 528
 				/* translators: 1) dollar amount 2) transaction id 3) refund message */
529
-				$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' );
529
+				$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');
530 530
 
531
-				$order->add_order_note( $refund_message );
531
+				$order->add_order_note($refund_message);
532 532
 			}
533 533
 		}
534 534
 	}
@@ -539,30 +539,30 @@  discard block
 block discarded – undo
539 539
 	 * @since 4.0.6
540 540
 	 * @param object $notification
541 541
 	 */
542
-	public function process_review_opened( $notification ) {
543
-		if ( isset( $notification->data->object->payment_intent ) ) {
544
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
542
+	public function process_review_opened($notification) {
543
+		if (isset($notification->data->object->payment_intent)) {
544
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
545 545
 
546
-			if ( ! $order ) {
547
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
546
+			if ( ! $order) {
547
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
548 548
 				return;
549 549
 			}
550 550
 		} else {
551
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
551
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
552 552
 
553
-			if ( ! $order ) {
554
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge );
553
+			if ( ! $order) {
554
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge);
555 555
 				return;
556 556
 			}
557 557
 		}
558 558
 
559 559
 		/* translators: 1) The URL to the order. 2) The reason type. */
560
-		$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 );
560
+		$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);
561 561
 
562
-		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
563
-			$order->update_status( 'on-hold', $message );
562
+		if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
563
+			$order->update_status('on-hold', $message);
564 564
 		} else {
565
-			$order->add_order_note( $message );
565
+			$order->add_order_note($message);
566 566
 		}
567 567
 	}
568 568
 
@@ -572,34 +572,34 @@  discard block
 block discarded – undo
572 572
 	 * @since 4.0.6
573 573
 	 * @param object $notification
574 574
 	 */
575
-	public function process_review_closed( $notification ) {
576
-		if ( isset( $notification->data->object->payment_intent ) ) {
577
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
575
+	public function process_review_closed($notification) {
576
+		if (isset($notification->data->object->payment_intent)) {
577
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
578 578
 
579
-			if ( ! $order ) {
580
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
579
+			if ( ! $order) {
580
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
581 581
 				return;
582 582
 			}
583 583
 		} else {
584
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
584
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
585 585
 
586
-			if ( ! $order ) {
587
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge );
586
+			if ( ! $order) {
587
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge);
588 588
 				return;
589 589
 			}
590 590
 		}
591 591
 
592 592
 		/* translators: 1) The reason type. */
593
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
593
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
594 594
 
595
-		if ( $order->has_status( 'on-hold' ) ) {
596
-			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
597
-				$order->update_status( 'processing', $message );
595
+		if ($order->has_status('on-hold')) {
596
+			if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
597
+				$order->update_status('processing', $message);
598 598
 			} else {
599
-				$order->add_order_note( $message );
599
+				$order->add_order_note($message);
600 600
 			}
601 601
 		} else {
602
-			$order->add_order_note( $message );
602
+			$order->add_order_note($message);
603 603
 		}
604 604
 	}
605 605
 
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 	 * @version 4.0.0
611 611
 	 * @param object $notification
612 612
 	 */
613
-	public function is_partial_capture( $notification ) {
613
+	public function is_partial_capture($notification) {
614 614
 		return 0 < $notification->data->object->amount_refunded;
615 615
 	}
616 616
 
@@ -621,11 +621,11 @@  discard block
 block discarded – undo
621 621
 	 * @version 4.0.0
622 622
 	 * @param object $notification
623 623
 	 */
624
-	public function get_refund_amount( $notification ) {
625
-		if ( $this->is_partial_capture( $notification ) ) {
624
+	public function get_refund_amount($notification) {
625
+		if ($this->is_partial_capture($notification)) {
626 626
 			$amount = $notification->data->object->refunds->data[0]->amount / 100;
627 627
 
628
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
628
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
629 629
 				$amount = $notification->data->object->refunds->data[0]->amount;
630 630
 			}
631 631
 
@@ -642,12 +642,12 @@  discard block
 block discarded – undo
642 642
 	 * @version 4.0.0
643 643
 	 * @param object $notification
644 644
 	 */
645
-	public function get_partial_amount_to_charge( $notification ) {
646
-		if ( $this->is_partial_capture( $notification ) ) {
647
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
645
+	public function get_partial_amount_to_charge($notification) {
646
+		if ($this->is_partial_capture($notification)) {
647
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
648 648
 
649
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
650
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
649
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
650
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
651 651
 			}
652 652
 
653 653
 			return $amount;
@@ -656,69 +656,69 @@  discard block
 block discarded – undo
656 656
 		return false;
657 657
 	}
658 658
 
659
-	public function process_payment_intent_success( $notification ) {
659
+	public function process_payment_intent_success($notification) {
660 660
 		$intent = $notification->data->object;
661
-		$order = WC_Stripe_Helper::get_order_by_intent_id( $intent->id );
661
+		$order = WC_Stripe_Helper::get_order_by_intent_id($intent->id);
662 662
 
663
-		if ( ! $order ) {
664
-			WC_Stripe_Logger::log( 'Could not find order via intent ID: ' . $intent->id );
663
+		if ( ! $order) {
664
+			WC_Stripe_Logger::log('Could not find order via intent ID: ' . $intent->id);
665 665
 			return;
666 666
 		}
667 667
 
668
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
668
+		if ( ! $order->has_status(array('pending', 'failed'))) {
669 669
 			return;
670 670
 		}
671 671
 
672
-		if ( $this->lock_order_payment( $order, $intent ) ) {
672
+		if ($this->lock_order_payment($order, $intent)) {
673 673
 			return;
674 674
 		}
675 675
 
676 676
 		$order_id = $order->get_id();
677
-		if ( 'payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type ) {
678
-			$charge = end( $intent->charges->data );
679
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
677
+		if ('payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type) {
678
+			$charge = end($intent->charges->data);
679
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
680 680
 
681
-			do_action( 'wc_gateway_stripe_process_payment', $charge, $order );
681
+			do_action('wc_gateway_stripe_process_payment', $charge, $order);
682 682
 
683 683
 			// Process valid response.
684
-			$this->process_response( $charge, $order );
684
+			$this->process_response($charge, $order);
685 685
 
686 686
 		} else {
687 687
 			$error_message = $intent->last_payment_error ? $intent->last_payment_error->message : "";
688 688
 
689 689
 			/* translators: 1) The error message that was received from Stripe. */
690
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
690
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
691 691
 
692
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
692
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
693 693
 
694
-			$this->send_failed_order_email( $order_id );
694
+			$this->send_failed_order_email($order_id);
695 695
 		}
696 696
 
697
-		$this->unlock_order_payment( $order );
697
+		$this->unlock_order_payment($order);
698 698
 	}
699 699
 
700
-	public function process_setup_intent( $notification ) {
700
+	public function process_setup_intent($notification) {
701 701
 		$intent = $notification->data->object;
702
-		$order = WC_Stripe_Helper::get_order_by_setup_intent_id( $intent->id );
702
+		$order = WC_Stripe_Helper::get_order_by_setup_intent_id($intent->id);
703 703
 
704
-		if ( ! $order ) {
705
-			WC_Stripe_Logger::log( 'Could not find order via setup intent ID: ' . $intent->id );
704
+		if ( ! $order) {
705
+			WC_Stripe_Logger::log('Could not find order via setup intent ID: ' . $intent->id);
706 706
 			return;
707 707
 		}
708 708
 
709
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
709
+		if ( ! $order->has_status(array('pending', 'failed'))) {
710 710
 			return;
711 711
 		}
712 712
 
713
-		if ( $this->lock_order_payment( $order, $intent ) ) {
713
+		if ($this->lock_order_payment($order, $intent)) {
714 714
 			return;
715 715
 		}
716 716
 
717 717
 		$order_id = $order->get_id();
718
-		if ( 'setup_intent.succeeded' === $notification->type ) {
719
-			WC_Stripe_Logger::log( "Stripe SetupIntent $intent->id succeeded for order $order_id" );
720
-			if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) {
721
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
718
+		if ('setup_intent.succeeded' === $notification->type) {
719
+			WC_Stripe_Logger::log("Stripe SetupIntent $intent->id succeeded for order $order_id");
720
+			if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) {
721
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
722 722
 			} else {
723 723
 				$order->payment_complete();
724 724
 			}
@@ -726,12 +726,12 @@  discard block
 block discarded – undo
726 726
 			$error_message = $intent->last_setup_error ? $intent->last_setup_error->message : "";
727 727
 
728 728
 			/* translators: 1) The error message that was received from Stripe. */
729
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
729
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
730 730
 
731
-			$this->send_failed_order_email( $order_id );
731
+			$this->send_failed_order_email($order_id);
732 732
 		}
733 733
 
734
-		$this->unlock_order_payment( $order );
734
+		$this->unlock_order_payment($order);
735 735
 	}
736 736
 
737 737
 	/**
@@ -741,55 +741,55 @@  discard block
 block discarded – undo
741 741
 	 * @version 4.0.0
742 742
 	 * @param string $request_body
743 743
 	 */
744
-	public function process_webhook( $request_body ) {
745
-		$notification = json_decode( $request_body );
744
+	public function process_webhook($request_body) {
745
+		$notification = json_decode($request_body);
746 746
 
747
-		switch ( $notification->type ) {
747
+		switch ($notification->type) {
748 748
 			case 'source.chargeable':
749
-				$this->process_webhook_payment( $notification );
749
+				$this->process_webhook_payment($notification);
750 750
 				break;
751 751
 
752 752
 			case 'source.canceled':
753
-				$this->process_webhook_source_canceled( $notification );
753
+				$this->process_webhook_source_canceled($notification);
754 754
 				break;
755 755
 
756 756
 			case 'charge.succeeded':
757
-				$this->process_webhook_charge_succeeded( $notification );
757
+				$this->process_webhook_charge_succeeded($notification);
758 758
 				break;
759 759
 
760 760
 			case 'charge.failed':
761
-				$this->process_webhook_charge_failed( $notification );
761
+				$this->process_webhook_charge_failed($notification);
762 762
 				break;
763 763
 
764 764
 			case 'charge.captured':
765
-				$this->process_webhook_capture( $notification );
765
+				$this->process_webhook_capture($notification);
766 766
 				break;
767 767
 
768 768
 			case 'charge.dispute.created':
769
-				$this->process_webhook_dispute( $notification );
769
+				$this->process_webhook_dispute($notification);
770 770
 				break;
771 771
 
772 772
 			case 'charge.refunded':
773
-				$this->process_webhook_refund( $notification );
773
+				$this->process_webhook_refund($notification);
774 774
 				break;
775 775
 
776 776
 			case 'review.opened':
777
-				$this->process_review_opened( $notification );
777
+				$this->process_review_opened($notification);
778 778
 				break;
779 779
 
780 780
 			case 'review.closed':
781
-				$this->process_review_closed( $notification );
781
+				$this->process_review_closed($notification);
782 782
 				break;
783 783
 
784 784
 			case 'payment_intent.succeeded':
785 785
 			case 'payment_intent.payment_failed':
786 786
 			case 'payment_intent.amount_capturable_updated':
787
-				$this->process_payment_intent_success( $notification );
787
+				$this->process_payment_intent_success($notification);
788 788
 				break;
789 789
 
790 790
 			case 'setup_intent.succeeded':
791 791
 			case 'setup_intent.setup_failed':
792
-				$this->process_setup_intent( $notification );
792
+				$this->process_setup_intent($notification);
793 793
 
794 794
 		}
795 795
 	}
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +327 added lines, -327 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
-		$description = 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> (if there isn\'t one already enabled). This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::get_webhook_url() );
24
+		$description = 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> (if there isn\'t one already enabled). This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::get_webhook_url());
25 25
 
26 26
 		$webhook_status = WC_Stripe_Webhook_State::get_webhook_status_message();
27 27
 
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 				<input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
40 40
 				<label for="wc-%1$s-new-payment-method" style="display:inline;">%2$s</label>
41 41
 			</p>',
42
-			esc_attr( $this->id ),
43
-			esc_html( apply_filters( 'wc_stripe_save_to_account_text', __( 'Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe' ) ) )
42
+			esc_attr($this->id),
43
+			esc_html(apply_filters('wc_stripe_save_to_account_text', __('Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe')))
44 44
 		);
45 45
 	}
46 46
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @since 4.0.5
52 52
 	 * @param array $error
53 53
 	 */
54
-	public function is_retryable_error( $error ) {
54
+	public function is_retryable_error($error) {
55 55
 		return (
56 56
 			'invalid_request_error' === $error->type ||
57 57
 			'idempotency_error' === $error->type ||
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
 	 * @since 4.1.0
69 69
 	 * @param array $error
70 70
 	 */
71
-	public function is_same_idempotency_error( $error ) {
71
+	public function is_same_idempotency_error($error) {
72 72
 		return (
73 73
 			$error &&
74 74
 			'idempotency_error' === $error->type &&
75
-			preg_match( '/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message )
75
+			preg_match('/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message)
76 76
 		);
77 77
 	}
78 78
 
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 	 * @since 4.1.0
84 84
 	 * @param array $error
85 85
 	 */
86
-	public function is_no_such_customer_error( $error ) {
86
+	public function is_no_such_customer_error($error) {
87 87
 		return (
88 88
 			$error &&
89 89
 			'invalid_request_error' === $error->type &&
90
-			preg_match( '/No such customer/i', $error->message )
90
+			preg_match('/No such customer/i', $error->message)
91 91
 		);
92 92
 	}
93 93
 
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
 	 * @since 4.1.0
99 99
 	 * @param array $error
100 100
 	 */
101
-	public function is_no_such_token_error( $error ) {
101
+	public function is_no_such_token_error($error) {
102 102
 		return (
103 103
 			$error &&
104 104
 			'invalid_request_error' === $error->type &&
105
-			preg_match( '/No such token/i', $error->message )
105
+			preg_match('/No such token/i', $error->message)
106 106
 		);
107 107
 	}
108 108
 
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
 	 * @since 4.1.0
114 114
 	 * @param array $error
115 115
 	 */
116
-	public function is_no_such_source_error( $error ) {
116
+	public function is_no_such_source_error($error) {
117 117
 		return (
118 118
 			$error &&
119 119
 			'invalid_request_error' === $error->type &&
120
-			preg_match( '/No such source/i', $error->message )
120
+			preg_match('/No such source/i', $error->message)
121 121
 		);
122 122
 	}
123 123
 
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
 	 * @since 4.1.0
129 129
 	 * @param array $error
130 130
 	 */
131
-	public function is_no_linked_source_error( $error ) {
131
+	public function is_no_linked_source_error($error) {
132 132
 		return (
133 133
 			$error &&
134 134
 			'invalid_request_error' === $error->type &&
135
-			preg_match( '/does not have a linked source with ID/i', $error->message )
135
+			preg_match('/does not have a linked source with ID/i', $error->message)
136 136
 		);
137 137
 	}
138 138
 
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 	 * @param object $error
146 146
 	 * @return bool
147 147
 	 */
148
-	public function need_update_idempotency_key( $source_object, $error ) {
148
+	public function need_update_idempotency_key($source_object, $error) {
149 149
 		return (
150 150
 			$error &&
151 151
 			1 < $this->retry_interval &&
152
-			! empty( $source_object ) &&
152
+			! empty($source_object) &&
153 153
 			'chargeable' === $source_object->status &&
154
-			self::is_same_idempotency_error( $error )
154
+			self::is_same_idempotency_error($error)
155 155
 		);
156 156
 	}
157 157
 
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
 		// NOTE: updates to this function should be added to are_keys_set()
166 166
 		// in includes/payment-methods/class-wc-stripe-payment-request.php
167 167
 
168
-		if ( $this->testmode ) {
169
-			return preg_match( '/^pk_test_/', $this->publishable_key )
170
-				&& preg_match( '/^[rs]k_test_/', $this->secret_key );
168
+		if ($this->testmode) {
169
+			return preg_match('/^pk_test_/', $this->publishable_key)
170
+				&& preg_match('/^[rs]k_test_/', $this->secret_key);
171 171
 		} else {
172
-			return preg_match( '/^pk_live_/', $this->publishable_key )
173
-			    && preg_match( '/^[rs]k_live_/', $this->secret_key );
172
+			return preg_match('/^pk_live_/', $this->publishable_key)
173
+			    && preg_match('/^[rs]k_live_/', $this->secret_key);
174 174
 		}
175 175
 	}
176 176
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 * @since 4.1.3
181 181
 	 */
182 182
 	public function is_available() {
183
-		if ( 'yes' === $this->enabled ) {
183
+		if ('yes' === $this->enabled) {
184 184
 			return $this->are_keys_set();
185 185
 		}
186 186
 
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
 	 * @param int $order_id
196 196
 	 * @return bool
197 197
 	 */
198
-	public function maybe_process_pre_orders( $order_id ) {
198
+	public function maybe_process_pre_orders($order_id) {
199 199
 		return (
200 200
 			WC_Stripe_Helper::is_pre_orders_exists() &&
201
-			$this->pre_orders->is_pre_order( $order_id ) &&
202
-			WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) &&
203
-			! is_wc_endpoint_url( 'order-pay' )
201
+			$this->pre_orders->is_pre_order($order_id) &&
202
+			WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id) &&
203
+			! is_wc_endpoint_url('order-pay')
204 204
 		);
205 205
 	}
206 206
 
@@ -244,10 +244,10 @@  discard block
 block discarded – undo
244 244
 	 * @version 4.0.0
245 245
 	 * @param object $order
246 246
 	 */
247
-	public function validate_minimum_order_amount( $order ) {
248
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
247
+	public function validate_minimum_order_amount($order) {
248
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
249 249
 			/* translators: 1) dollar amount */
250
-			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 ) ) );
250
+			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)));
251 251
 		}
252 252
 	}
253 253
 
@@ -257,14 +257,14 @@  discard block
 block discarded – undo
257 257
 	 * @since 4.0.0
258 258
 	 * @version 4.0.0
259 259
 	 */
260
-	public function get_transaction_url( $order ) {
261
-		if ( $this->testmode ) {
260
+	public function get_transaction_url($order) {
261
+		if ($this->testmode) {
262 262
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
263 263
 		} else {
264 264
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
265 265
 		}
266 266
 
267
-		return parent::get_transaction_url( $order );
267
+		return parent::get_transaction_url($order);
268 268
 	}
269 269
 
270 270
 	/**
@@ -273,12 +273,12 @@  discard block
 block discarded – undo
273 273
 	 * @since 4.0.0
274 274
 	 * @version 4.0.0
275 275
 	 */
276
-	public function get_stripe_customer_id( $order ) {
277
-		$customer = get_user_option( '_stripe_customer_id', $order->get_customer_id() );
276
+	public function get_stripe_customer_id($order) {
277
+		$customer = get_user_option('_stripe_customer_id', $order->get_customer_id());
278 278
 
279
-		if ( empty( $customer ) ) {
279
+		if (empty($customer)) {
280 280
 			// Try to get it via the order.
281
-			return $order->get_meta( '_stripe_customer_id', true );
281
+			return $order->get_meta('_stripe_customer_id', true);
282 282
 		} else {
283 283
 			return $customer;
284 284
 		}
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 	 * @param object $order
295 295
 	 * @param int $id Stripe session id.
296 296
 	 */
297
-	public function get_stripe_return_url( $order = null, $id = null ) {
298
-		if ( is_object( $order ) ) {
299
-			if ( empty( $id ) ) {
297
+	public function get_stripe_return_url($order = null, $id = null) {
298
+		if (is_object($order)) {
299
+			if (empty($id)) {
300 300
 				$id = uniqid();
301 301
 			}
302 302
 
@@ -307,10 +307,10 @@  discard block
 block discarded – undo
307 307
 				'order_id'       => $order_id,
308 308
 			);
309 309
 
310
-			return wp_sanitize_redirect( esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ) );
310
+			return wp_sanitize_redirect(esc_url_raw(add_query_arg($args, $this->get_return_url($order))));
311 311
 		}
312 312
 
313
-		return wp_sanitize_redirect( esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ) );
313
+		return wp_sanitize_redirect(esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())));
314 314
 	}
315 315
 
316 316
 	/**
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
 	 * @param  int  $order_id
319 319
 	 * @return boolean
320 320
 	 */
321
-	public function has_subscription( $order_id ) {
322
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
321
+	public function has_subscription($order_id) {
322
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
323 323
 	}
324 324
 
325 325
 	/**
@@ -331,34 +331,34 @@  discard block
 block discarded – undo
331 331
 	 * @param  object $prepared_source
332 332
 	 * @return array()
333 333
 	 */
334
-	public function generate_payment_request( $order, $prepared_source ) {
335
-		$settings              = get_option( 'woocommerce_stripe_settings', array() );
336
-		$statement_descriptor  = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
337
-		$capture               = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
334
+	public function generate_payment_request($order, $prepared_source) {
335
+		$settings              = get_option('woocommerce_stripe_settings', array());
336
+		$statement_descriptor  = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
337
+		$capture               = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
338 338
 		$post_data             = array();
339
-		$post_data['currency'] = strtolower( $order->get_currency() );
340
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
339
+		$post_data['currency'] = strtolower($order->get_currency());
340
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
341 341
 		/* translators: 1) blog name 2) order number */
342
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
342
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
343 343
 		$billing_email            = $order->get_billing_email();
344 344
 		$billing_first_name       = $order->get_billing_first_name();
345 345
 		$billing_last_name        = $order->get_billing_last_name();
346 346
 
347
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
347
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
348 348
 			$post_data['receipt_email'] = $billing_email;
349 349
 		}
350 350
 
351
-		switch ( $order->get_payment_method() ) {
351
+		switch ($order->get_payment_method()) {
352 352
 			case 'stripe':
353
-				if ( ! empty( $statement_descriptor ) ) {
354
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
353
+				if ( ! empty($statement_descriptor)) {
354
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
355 355
 				}
356 356
 
357 357
 				$post_data['capture'] = $capture ? 'true' : 'false';
358 358
 				break;
359 359
 			case 'stripe_sepa':
360
-				if ( ! empty( $statement_descriptor ) ) {
361
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
360
+				if ( ! empty($statement_descriptor)) {
361
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
362 362
 				}
363 363
 				break;
364 364
 		}
@@ -366,25 +366,25 @@  discard block
 block discarded – undo
366 366
 		$post_data['expand[]'] = 'balance_transaction';
367 367
 
368 368
 		$metadata = array(
369
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
370
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
369
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
370
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
371 371
 			'order_id' => $order->get_order_number(),
372 372
 		);
373 373
 
374
-		if ( $this->has_subscription( $order->get_id() ) ) {
374
+		if ($this->has_subscription($order->get_id())) {
375 375
 			$metadata += array(
376 376
 				'payment_type' => 'recurring',
377
-				'site_url'     => esc_url( get_site_url() ),
377
+				'site_url'     => esc_url(get_site_url()),
378 378
 			);
379 379
 		}
380 380
 
381
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source );
381
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source);
382 382
 
383
-		if ( $prepared_source->customer ) {
383
+		if ($prepared_source->customer) {
384 384
 			$post_data['customer'] = $prepared_source->customer;
385 385
 		}
386 386
 
387
-		if ( $prepared_source->source ) {
387
+		if ($prepared_source->source) {
388 388
 			$post_data['source'] = $prepared_source->source;
389 389
 		}
390 390
 
@@ -396,72 +396,72 @@  discard block
 block discarded – undo
396 396
 		 * @param WC_Order $order
397 397
 		 * @param object $source
398 398
 		 */
399
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source );
399
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source);
400 400
 	}
401 401
 
402 402
 	/**
403 403
 	 * Store extra meta data for an order from a Stripe Response.
404 404
 	 */
405
-	public function process_response( $response, $order ) {
406
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
405
+	public function process_response($response, $order) {
406
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
407 407
 
408 408
 		$order_id = $order->get_id();
409
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
409
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
410 410
 
411 411
 		// Store charge data.
412
-		$order->update_meta_data( '_stripe_charge_captured', $captured );
412
+		$order->update_meta_data('_stripe_charge_captured', $captured);
413 413
 
414
-		if ( isset( $response->balance_transaction ) ) {
415
-			$this->update_fees( $order, is_string( $response->balance_transaction ) ? $response->balance_transaction : $response->balance_transaction->id );
414
+		if (isset($response->balance_transaction)) {
415
+			$this->update_fees($order, is_string($response->balance_transaction) ? $response->balance_transaction : $response->balance_transaction->id);
416 416
 		}
417 417
 
418
-		if ( 'yes' === $captured ) {
418
+		if ('yes' === $captured) {
419 419
 			/**
420 420
 			 * Charge can be captured but in a pending state. Payment methods
421 421
 			 * that are asynchronous may take couple days to clear. Webhook will
422 422
 			 * take care of the status changes.
423 423
 			 */
424
-			if ( 'pending' === $response->status ) {
425
-				$order_stock_reduced = $order->get_meta( '_order_stock_reduced', true );
424
+			if ('pending' === $response->status) {
425
+				$order_stock_reduced = $order->get_meta('_order_stock_reduced', true);
426 426
 
427
-				if ( ! $order_stock_reduced ) {
428
-					wc_reduce_stock_levels( $order_id );
427
+				if ( ! $order_stock_reduced) {
428
+					wc_reduce_stock_levels($order_id);
429 429
 				}
430 430
 
431
-				$order->set_transaction_id( $response->id );
431
+				$order->set_transaction_id($response->id);
432 432
 				/* translators: transaction id */
433
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
433
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
434 434
 			}
435 435
 
436
-			if ( 'succeeded' === $response->status ) {
437
-				$order->payment_complete( $response->id );
436
+			if ('succeeded' === $response->status) {
437
+				$order->payment_complete($response->id);
438 438
 
439 439
 				/* translators: transaction id */
440
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
441
-				$order->add_order_note( $message );
440
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
441
+				$order->add_order_note($message);
442 442
 			}
443 443
 
444
-			if ( 'failed' === $response->status ) {
445
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
446
-				$order->add_order_note( $localized_message );
447
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
444
+			if ('failed' === $response->status) {
445
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
446
+				$order->add_order_note($localized_message);
447
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
448 448
 			}
449 449
 		} else {
450
-			$order->set_transaction_id( $response->id );
450
+			$order->set_transaction_id($response->id);
451 451
 
452
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
453
-				wc_reduce_stock_levels( $order_id );
452
+			if ($order->has_status(array('pending', 'failed'))) {
453
+				wc_reduce_stock_levels($order_id);
454 454
 			}
455 455
 
456 456
 			/* translators: transaction id */
457
-			$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 ) );
457
+			$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));
458 458
 		}
459 459
 
460
-		if ( is_callable( array( $order, 'save' ) ) ) {
460
+		if (is_callable(array($order, 'save'))) {
461 461
 			$order->save();
462 462
 		}
463 463
 
464
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
464
+		do_action('wc_gateway_stripe_process_response', $response, $order);
465 465
 
466 466
 		return $response;
467 467
 	}
@@ -474,10 +474,10 @@  discard block
 block discarded – undo
474 474
 	 * @param int $order_id
475 475
 	 * @return null
476 476
 	 */
477
-	public function send_failed_order_email( $order_id ) {
477
+	public function send_failed_order_email($order_id) {
478 478
 		$emails = WC()->mailer()->get_emails();
479
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
480
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
479
+		if ( ! empty($emails) && ! empty($order_id)) {
480
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
481 481
 		}
482 482
 	}
483 483
 
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 	 * @param object $order
490 490
 	 * @return object $details
491 491
 	 */
492
-	public function get_owner_details( $order ) {
492
+	public function get_owner_details($order) {
493 493
 		$billing_first_name = $order->get_billing_first_name();
494 494
 		$billing_last_name  = $order->get_billing_last_name();
495 495
 
@@ -499,15 +499,15 @@  discard block
 block discarded – undo
499 499
 		$email = $order->get_billing_email();
500 500
 		$phone = $order->get_billing_phone();
501 501
 
502
-		if ( ! empty( $phone ) ) {
502
+		if ( ! empty($phone)) {
503 503
 			$details['phone'] = $phone;
504 504
 		}
505 505
 
506
-		if ( ! empty( $name ) ) {
506
+		if ( ! empty($name)) {
507 507
 			$details['name'] = $name;
508 508
 		}
509 509
 
510
-		if ( ! empty( $email ) ) {
510
+		if ( ! empty($email)) {
511 511
 			$details['email'] = $email;
512 512
 		}
513 513
 
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
 		$details['address']['postal_code'] = $order->get_billing_postcode();
519 519
 		$details['address']['country']     = $order->get_billing_country();
520 520
 
521
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
521
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
522 522
 	}
523 523
 
524 524
 	/**
@@ -527,15 +527,15 @@  discard block
 block discarded – undo
527 527
 	 * @since 4.0.3
528 528
 	 * @param string $source_id The source ID to get source object for.
529 529
 	 */
530
-	public function get_source_object( $source_id = '' ) {
531
-		if ( empty( $source_id ) ) {
530
+	public function get_source_object($source_id = '') {
531
+		if (empty($source_id)) {
532 532
 			return '';
533 533
 		}
534 534
 
535
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
535
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
536 536
 
537
-		if ( ! empty( $source_object->error ) ) {
538
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
537
+		if ( ! empty($source_object->error)) {
538
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
539 539
 		}
540 540
 
541 541
 		return $source_object;
@@ -548,10 +548,10 @@  discard block
 block discarded – undo
548 548
 	 * @param object $source_object
549 549
 	 * @return bool
550 550
 	 */
551
-	public function is_prepaid_card( $source_object ) {
551
+	public function is_prepaid_card($source_object) {
552 552
 		return (
553 553
 			$source_object
554
-			&& ( 'token' === $source_object->object || 'source' === $source_object->object )
554
+			&& ('token' === $source_object->object || 'source' === $source_object->object)
555 555
 			&& 'prepaid' === $source_object->card->funding
556 556
 		);
557 557
 	}
@@ -563,8 +563,8 @@  discard block
 block discarded – undo
563 563
 	 * @param string $source_id
564 564
 	 * @return bool
565 565
 	 */
566
-	public function is_type_legacy_card( $source_id ) {
567
-		return ( preg_match( '/^card_/', $source_id ) );
566
+	public function is_type_legacy_card($source_id) {
567
+		return (preg_match('/^card_/', $source_id));
568 568
 	}
569 569
 
570 570
 	/**
@@ -574,9 +574,9 @@  discard block
 block discarded – undo
574 574
 	 * @return bool
575 575
 	 */
576 576
 	public function is_using_saved_payment_method() {
577
-		$payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
577
+		$payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
578 578
 
579
-		return ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
579
+		return (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']);
580 580
 	}
581 581
 
582 582
 	/**
@@ -592,64 +592,64 @@  discard block
 block discarded – undo
592 592
 	 * @throws Exception When card was not added or for and invalid card.
593 593
 	 * @return object
594 594
 	 */
595
-	public function prepare_source( $user_id, $force_save_source = false, $existing_customer_id = null ) {
596
-		$customer = new WC_Stripe_Customer( $user_id );
597
-		if ( ! empty( $existing_customer_id ) ) {
598
-			$customer->set_id( $existing_customer_id );
595
+	public function prepare_source($user_id, $force_save_source = false, $existing_customer_id = null) {
596
+		$customer = new WC_Stripe_Customer($user_id);
597
+		if ( ! empty($existing_customer_id)) {
598
+			$customer->set_id($existing_customer_id);
599 599
 		}
600 600
 
601
-		$force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
601
+		$force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
602 602
 		$source_object     = '';
603 603
 		$source_id         = '';
604 604
 		$wc_token_id       = false;
605
-		$payment_method    = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
605
+		$payment_method    = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
606 606
 		$is_token          = false;
607 607
 
608 608
 		// New CC info was entered and we have a new source to process.
609
-		if ( ! empty( $_POST['stripe_source'] ) ) {
610
-			$source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) );
609
+		if ( ! empty($_POST['stripe_source'])) {
610
+			$source_object = self::get_source_object(wc_clean($_POST['stripe_source']));
611 611
 			$source_id     = $source_object->id;
612 612
 
613 613
 			// This checks to see if customer opted to save the payment method to file.
614
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
614
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
615 615
 
616 616
 			/**
617 617
 			 * This is true if the user wants to store the card to their account.
618 618
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
619 619
 			 * actually reusable. Either that or force_save_source is true.
620 620
 			 */
621
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
622
-				$response = $customer->add_source( $source_object->id );
621
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
622
+				$response = $customer->add_source($source_object->id);
623 623
 
624
-				if ( ! empty( $response->error ) ) {
625
-					throw new WC_Stripe_Exception( print_r( $response, true ), $this->get_localized_error_message_from_response( $response ) );
624
+				if ( ! empty($response->error)) {
625
+					throw new WC_Stripe_Exception(print_r($response, true), $this->get_localized_error_message_from_response($response));
626 626
 				}
627 627
 			}
628
-		} elseif ( $this->is_using_saved_payment_method() ) {
628
+		} elseif ($this->is_using_saved_payment_method()) {
629 629
 			// Use an existing token, and then process the payment.
630
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
631
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
630
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
631
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
632 632
 
633
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
634
-				WC()->session->set( 'refresh_totals', true );
635
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
633
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
634
+				WC()->session->set('refresh_totals', true);
635
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
636 636
 			}
637 637
 
638 638
 			$source_id = $wc_token->get_token();
639 639
 
640
-			if ( $this->is_type_legacy_card( $source_id ) ) {
640
+			if ($this->is_type_legacy_card($source_id)) {
641 641
 				$is_token = true;
642 642
 			}
643
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
644
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
645
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
643
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
644
+			$stripe_token     = wc_clean($_POST['stripe_token']);
645
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
646 646
 
647 647
 			// This is true if the user wants to store the card to their account.
648
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
649
-				$response = $customer->add_source( $stripe_token );
648
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
649
+				$response = $customer->add_source($stripe_token);
650 650
 
651
-				if ( ! empty( $response->error ) ) {
652
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
651
+				if ( ! empty($response->error)) {
652
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
653 653
 				}
654 654
 				$source_id    = $response;
655 655
 			} else {
@@ -659,15 +659,15 @@  discard block
 block discarded – undo
659 659
 		}
660 660
 
661 661
 		$customer_id = $customer->get_id();
662
-		if ( ! $customer_id ) {
663
-			$customer->set_id( $customer->create_customer() );
662
+		if ( ! $customer_id) {
663
+			$customer->set_id($customer->create_customer());
664 664
 			$customer_id = $customer->get_id();
665 665
 		} else {
666 666
 			$customer_id = $customer->update_customer();
667 667
 		}
668 668
 
669
-		if ( empty( $source_object ) && ! $is_token ) {
670
-			$source_object = self::get_source_object( $source_id );
669
+		if (empty($source_object) && ! $is_token) {
670
+			$source_object = self::get_source_object($source_id);
671 671
 		}
672 672
 
673 673
 		return (object) array(
@@ -691,39 +691,39 @@  discard block
 block discarded – undo
691 691
 	 * @param object $order
692 692
 	 * @return object
693 693
 	 */
694
-	public function prepare_order_source( $order = null ) {
694
+	public function prepare_order_source($order = null) {
695 695
 		$stripe_customer = new WC_Stripe_Customer();
696 696
 		$stripe_source   = false;
697 697
 		$token_id        = false;
698 698
 		$source_object   = false;
699 699
 
700
-		if ( $order ) {
700
+		if ($order) {
701 701
 			$order_id = $order->get_id();
702 702
 
703
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
703
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
704 704
 
705
-			if ( $stripe_customer_id ) {
706
-				$stripe_customer->set_id( $stripe_customer_id );
705
+			if ($stripe_customer_id) {
706
+				$stripe_customer->set_id($stripe_customer_id);
707 707
 			}
708 708
 
709
-			$source_id = $order->get_meta( '_stripe_source_id', true );
709
+			$source_id = $order->get_meta('_stripe_source_id', true);
710 710
 
711 711
 			// Since 4.0.0, we changed card to source so we need to account for that.
712
-			if ( empty( $source_id ) ) {
713
-				$source_id = $order->get_meta( '_stripe_card_id', true );
712
+			if (empty($source_id)) {
713
+				$source_id = $order->get_meta('_stripe_card_id', true);
714 714
 
715 715
 				// Take this opportunity to update the key name.
716
-				$order->update_meta_data( '_stripe_source_id', $source_id );
716
+				$order->update_meta_data('_stripe_source_id', $source_id);
717 717
 
718
-				if ( is_callable( array( $order, 'save' ) ) ) {
718
+				if (is_callable(array($order, 'save'))) {
719 719
 					$order->save();
720 720
 				}
721 721
 			}
722 722
 
723
-			if ( $source_id ) {
723
+			if ($source_id) {
724 724
 				$stripe_source = $source_id;
725
-				$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
726
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
725
+				$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
726
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
727 727
 				/*
728 728
 				 * We can attempt to charge the customer's default source
729 729
 				 * by sending empty source id.
@@ -748,17 +748,17 @@  discard block
 block discarded – undo
748 748
 	 * @param WC_Order $order For to which the source applies.
749 749
 	 * @param stdClass $source Source information.
750 750
 	 */
751
-	public function save_source_to_order( $order, $source ) {
751
+	public function save_source_to_order($order, $source) {
752 752
 		// Store source in the order.
753
-		if ( $source->customer ) {
754
-			$order->update_meta_data( '_stripe_customer_id', $source->customer );
753
+		if ($source->customer) {
754
+			$order->update_meta_data('_stripe_customer_id', $source->customer);
755 755
 		}
756 756
 
757
-		if ( $source->source ) {
758
-			$order->update_meta_data( '_stripe_source_id', $source->source );
757
+		if ($source->source) {
758
+			$order->update_meta_data('_stripe_source_id', $source->source);
759 759
 		}
760 760
 
761
-		if ( is_callable( array( $order, 'save' ) ) ) {
761
+		if (is_callable(array($order, 'save'))) {
762 762
 			$order->save();
763 763
 		}
764 764
 	}
@@ -772,36 +772,36 @@  discard block
 block discarded – undo
772 772
 	 * @param object $order The order object
773 773
 	 * @param int $balance_transaction_id
774 774
 	 */
775
-	public function update_fees( $order, $balance_transaction_id ) {
776
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
775
+	public function update_fees($order, $balance_transaction_id) {
776
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
777 777
 
778
-		if ( empty( $balance_transaction->error ) ) {
779
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
778
+		if (empty($balance_transaction->error)) {
779
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
780 780
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
781 781
 				// values are in the local currency of the Stripe account, not from WC.
782
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
783
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
782
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
783
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
784 784
 
785 785
 				// Current data fee & net.
786
-				$fee_current = WC_Stripe_Helper::get_stripe_fee( $order );
787
-				$net_current = WC_Stripe_Helper::get_stripe_net( $order );
786
+				$fee_current = WC_Stripe_Helper::get_stripe_fee($order);
787
+				$net_current = WC_Stripe_Helper::get_stripe_net($order);
788 788
 
789 789
 				// Calculation.
790 790
 				$fee = (float) $fee_current + (float) $fee_refund;
791 791
 				$net = (float) $net_current + (float) $net_refund;
792 792
 
793
-				WC_Stripe_Helper::update_stripe_fee( $order, $fee );
794
-				WC_Stripe_Helper::update_stripe_net( $order, $net );
793
+				WC_Stripe_Helper::update_stripe_fee($order, $fee);
794
+				WC_Stripe_Helper::update_stripe_net($order, $net);
795 795
 
796
-				$currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null;
797
-				WC_Stripe_Helper::update_stripe_currency( $order, $currency );
796
+				$currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null;
797
+				WC_Stripe_Helper::update_stripe_currency($order, $currency);
798 798
 
799
-				if ( is_callable( array( $order, 'save' ) ) ) {
799
+				if (is_callable(array($order, 'save'))) {
800 800
 					$order->save();
801 801
 				}
802 802
 			}
803 803
 		} else {
804
-			WC_Stripe_Logger::log( 'Unable to update fees/net meta for order: ' . $order->get_id() );
804
+			WC_Stripe_Logger::log('Unable to update fees/net meta for order: ' . $order->get_id());
805 805
 		}
806 806
 	}
807 807
 
@@ -814,93 +814,93 @@  discard block
 block discarded – undo
814 814
 	 * @param  float $amount
815 815
 	 * @return bool
816 816
 	 */
817
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
818
-		$order = wc_get_order( $order_id );
817
+	public function process_refund($order_id, $amount = null, $reason = '') {
818
+		$order = wc_get_order($order_id);
819 819
 
820
-		if ( ! $order ) {
820
+		if ( ! $order) {
821 821
 			return false;
822 822
 		}
823 823
 
824 824
 		$request = array();
825 825
 
826 826
 		$order_currency = $order->get_currency();
827
-		$captured       = $order->get_meta( '_stripe_charge_captured', true );
827
+		$captured       = $order->get_meta('_stripe_charge_captured', true);
828 828
 		$charge_id      = $order->get_transaction_id();
829 829
 
830
-		if ( ! $charge_id ) {
830
+		if ( ! $charge_id) {
831 831
 			return false;
832 832
 		}
833 833
 
834
-		if ( ! is_null( $amount ) ) {
835
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
834
+		if ( ! is_null($amount)) {
835
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
836 836
 		}
837 837
 
838 838
 		// If order is only authorized, don't pass amount.
839
-		if ( 'yes' !== $captured ) {
840
-			unset( $request['amount'] );
839
+		if ('yes' !== $captured) {
840
+			unset($request['amount']);
841 841
 		}
842 842
 
843
-		if ( $reason ) {
843
+		if ($reason) {
844 844
 			$request['metadata'] = array(
845 845
 				'reason' => $reason,
846 846
 			);
847 847
 		}
848 848
 
849 849
 		$request['charge'] = $charge_id;
850
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$charge_id} for the amount of {$amount}" );
850
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$charge_id} for the amount of {$amount}");
851 851
 
852
-		$request = apply_filters( 'wc_stripe_refund_request', $request, $order );
852
+		$request = apply_filters('wc_stripe_refund_request', $request, $order);
853 853
 
854
-		$intent = $this->get_intent_from_order( $order );
854
+		$intent = $this->get_intent_from_order($order);
855 855
 		$intent_cancelled = false;
856
-		if ( $intent ) {
856
+		if ($intent) {
857 857
 			// If the order has a Payment Intent pending capture, then the Intent itself must be refunded (cancelled), not the Charge
858
-			if ( ! empty( $intent->error ) ) {
858
+			if ( ! empty($intent->error)) {
859 859
 				$response = $intent;
860 860
 				$intent_cancelled = true;
861
-			} elseif ( 'requires_capture' === $intent->status ) {
861
+			} elseif ('requires_capture' === $intent->status) {
862 862
 				$result = WC_Stripe_API::request(
863 863
 					array(),
864 864
 					'payment_intents/' . $intent->id . '/cancel'
865 865
 				);
866 866
 				$intent_cancelled = true;
867 867
 
868
-				if ( ! empty( $result->error ) ) {
868
+				if ( ! empty($result->error)) {
869 869
 					$response = $result;
870 870
 				} else {
871
-					$charge = end( $result->charges->data );
872
-					$response = end( $charge->refunds->data );
871
+					$charge = end($result->charges->data);
872
+					$response = end($charge->refunds->data);
873 873
 				}
874 874
 			}
875 875
 		}
876 876
 
877
-		if ( ! $intent_cancelled ) {
878
-			$response = WC_Stripe_API::request( $request, 'refunds' );
877
+		if ( ! $intent_cancelled) {
878
+			$response = WC_Stripe_API::request($request, 'refunds');
879 879
 		}
880 880
 
881
-		if ( ! empty( $response->error ) ) {
882
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
881
+		if ( ! empty($response->error)) {
882
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
883 883
 
884 884
 			return $response;
885 885
 
886
-		} elseif ( ! empty( $response->id ) ) {
887
-			$order->update_meta_data( '_stripe_refund_id', $response->id );
886
+		} elseif ( ! empty($response->id)) {
887
+			$order->update_meta_data('_stripe_refund_id', $response->id);
888 888
 
889
-			$amount = wc_price( $response->amount / 100 );
889
+			$amount = wc_price($response->amount / 100);
890 890
 
891
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
892
-				$amount = wc_price( $response->amount );
891
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
892
+				$amount = wc_price($response->amount);
893 893
 			}
894 894
 
895
-			if ( isset( $response->balance_transaction ) ) {
896
-				$this->update_fees( $order, $response->balance_transaction );
895
+			if (isset($response->balance_transaction)) {
896
+				$this->update_fees($order, $response->balance_transaction);
897 897
 			}
898 898
 
899 899
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
900
-			$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' );
900
+			$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');
901 901
 
902
-			$order->add_order_note( $refund_message );
903
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) );
902
+			$order->add_order_note($refund_message);
903
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message)));
904 904
 
905 905
 			return true;
906 906
 		}
@@ -915,46 +915,46 @@  discard block
 block discarded – undo
915 915
 	 */
916 916
 	public function add_payment_method() {
917 917
 		$error     = false;
918
-		$error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' );
918
+		$error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe');
919 919
 		$source_id = '';
920 920
 
921
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
921
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
922 922
 			$error = true;
923 923
 		}
924 924
 
925
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
925
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
926 926
 
927
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
927
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
928 928
 
929
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
929
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
930 930
 
931
-		if ( isset( $source_object ) ) {
932
-			if ( ! empty( $source_object->error ) ) {
931
+		if (isset($source_object)) {
932
+			if ( ! empty($source_object->error)) {
933 933
 				$error = true;
934 934
 			}
935 935
 
936 936
 			$source_id = $source_object->id;
937
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
938
-			$source_id = wc_clean( $_POST['stripe_token'] );
937
+		} elseif (isset($_POST['stripe_token'])) {
938
+			$source_id = wc_clean($_POST['stripe_token']);
939 939
 		}
940 940
 
941
-		$response = $stripe_customer->add_source( $source_id );
941
+		$response = $stripe_customer->add_source($source_id);
942 942
 
943
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
943
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
944 944
 			$error = true;
945 945
 		}
946 946
 
947
-		if ( $error ) {
948
-			wc_add_notice( $error_msg, 'error' );
949
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
947
+		if ($error) {
948
+			wc_add_notice($error_msg, 'error');
949
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
950 950
 			return;
951 951
 		}
952 952
 
953
-		do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object );
953
+		do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object);
954 954
 
955 955
 		return array(
956 956
 			'result'   => 'success',
957
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
957
+			'redirect' => wc_get_endpoint_url('payment-methods'),
958 958
 		);
959 959
 	}
960 960
 
@@ -971,10 +971,10 @@  discard block
 block discarded – undo
971 971
 		 * Stripe expects Norwegian to only be passed NO.
972 972
 		 * But WP has different dialects.
973 973
 		 */
974
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
974
+		if ('NO' === substr($locale, 3, 2)) {
975 975
 			$locale = 'no';
976 976
 		} else {
977
-			$locale = substr( get_locale(), 0, 2 );
977
+			$locale = substr(get_locale(), 0, 2);
978 978
 		}
979 979
 
980 980
 		return $locale;
@@ -988,9 +988,9 @@  discard block
 block discarded – undo
988 988
 	 * @param string $idempotency_key
989 989
 	 * @param array $request
990 990
 	 */
991
-	public function change_idempotency_key( $idempotency_key, $request ) {
992
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
993
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
991
+	public function change_idempotency_key($idempotency_key, $request) {
992
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
993
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
994 994
 		$count    = $this->retry_interval;
995 995
 
996 996
 		return $request['metadata']['order_id'] . '-' . $count . '-' . $source;
@@ -1004,8 +1004,8 @@  discard block
 block discarded – undo
1004 1004
 	 * @since 4.0.6
1005 1005
 	 * @param array $headers
1006 1006
 	 */
1007
-	public function is_original_request( $headers ) {
1008
-		if ( $headers['original-request'] === $headers['request-id'] ) {
1007
+	public function is_original_request($headers) {
1008
+		if ($headers['original-request'] === $headers['request-id']) {
1009 1009
 			return true;
1010 1010
 		}
1011 1011
 
@@ -1019,27 +1019,27 @@  discard block
 block discarded – undo
1019 1019
 	 * @param object   $prepared_source The source that is used for the payment.
1020 1020
 	 * @return array                    The arguments for the request.
1021 1021
 	 */
1022
-	public function generate_create_intent_request( $order, $prepared_source ) {
1022
+	public function generate_create_intent_request($order, $prepared_source) {
1023 1023
 		// The request for a charge contains metadata for the intent.
1024
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1024
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1025 1025
 
1026 1026
 		$request = array(
1027 1027
 			'source'               => $prepared_source->source,
1028
-			'amount'               => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
1029
-			'currency'             => strtolower( $order->get_currency() ),
1028
+			'amount'               => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
1029
+			'currency'             => strtolower($order->get_currency()),
1030 1030
 			'description'          => $full_request['description'],
1031 1031
 			'metadata'             => $full_request['metadata'],
1032
-			'capture_method'       => ( 'true' === $full_request['capture'] ) ? 'automatic' : 'manual',
1032
+			'capture_method'       => ('true' === $full_request['capture']) ? 'automatic' : 'manual',
1033 1033
 			'payment_method_types' => array(
1034 1034
 				'card',
1035 1035
 			),
1036 1036
 		);
1037 1037
 
1038
-		if ( $prepared_source->customer ) {
1038
+		if ($prepared_source->customer) {
1039 1039
 			$request['customer'] = $prepared_source->customer;
1040 1040
 		}
1041 1041
 
1042
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1042
+		if (isset($full_request['statement_descriptor'])) {
1043 1043
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1044 1044
 		}
1045 1045
 
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 		 * @param WC_Order $order
1052 1052
 		 * @param object $source
1053 1053
 		 */
1054
-		return apply_filters( 'wc_stripe_generate_create_intent_request', $request, $order, $prepared_source );
1054
+		return apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source);
1055 1055
 	}
1056 1056
 
1057 1057
 	/**
@@ -1060,21 +1060,21 @@  discard block
 block discarded – undo
1060 1060
 	 * @param WC_Order $order The order that is being paid for.
1061 1061
 	 * @return array          The level 3 data to send to Stripe.
1062 1062
 	 */
1063
-	public function get_level3_data_from_order( $order ) {
1063
+	public function get_level3_data_from_order($order) {
1064 1064
 		// Get the order items. Don't need their keys, only their values.
1065 1065
 		// Order item IDs are used as keys in the original order items array.
1066
-		$order_items = array_values( $order->get_items() );
1066
+		$order_items = array_values($order->get_items());
1067 1067
 		$currency    = $order->get_currency();
1068 1068
 
1069
-		$stripe_line_items = array_map(function( $item ) use ( $currency ) {
1069
+		$stripe_line_items = array_map(function($item) use ($currency) {
1070 1070
 			$product_id          = $item->get_variation_id()
1071 1071
 				? $item->get_variation_id()
1072 1072
 				: $item->get_product_id();
1073
-			$product_description = substr( $item->get_name(), 0, 26 );
1073
+			$product_description = substr($item->get_name(), 0, 26);
1074 1074
 			$quantity            = $item->get_quantity();
1075
-			$unit_cost           = WC_Stripe_Helper::get_stripe_amount( ( $item->get_subtotal() / $quantity ), $currency );
1076
-			$tax_amount          = WC_Stripe_Helper::get_stripe_amount( $item->get_total_tax(), $currency );
1077
-			$discount_amount     = WC_Stripe_Helper::get_stripe_amount( $item->get_subtotal() - $item->get_total(), $currency );
1075
+			$unit_cost           = WC_Stripe_Helper::get_stripe_amount(($item->get_subtotal() / $quantity), $currency);
1076
+			$tax_amount          = WC_Stripe_Helper::get_stripe_amount($item->get_total_tax(), $currency);
1077
+			$discount_amount     = WC_Stripe_Helper::get_stripe_amount($item->get_subtotal() - $item->get_total(), $currency);
1078 1078
 
1079 1079
 			return (object) array(
1080 1080
 				'product_code'        => (string) $product_id, // Up to 12 characters that uniquely identify the product.
@@ -1088,19 +1088,19 @@  discard block
 block discarded – undo
1088 1088
 
1089 1089
 		$level3_data = array(
1090 1090
 			'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”.
1091
-			'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.
1091
+			'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.
1092 1092
 			'line_items'           => $stripe_line_items,
1093 1093
 		);
1094 1094
 
1095 1095
 		// The customer’s U.S. shipping ZIP code.
1096 1096
 		$shipping_address_zip = $order->get_shipping_postcode();
1097
-		if ( $this->is_valid_us_zip_code( $shipping_address_zip ) ) {
1097
+		if ($this->is_valid_us_zip_code($shipping_address_zip)) {
1098 1098
 			$level3_data['shipping_address_zip'] = $shipping_address_zip;
1099 1099
 		}
1100 1100
 
1101 1101
 		// The merchant’s U.S. shipping ZIP code.
1102
-		$store_postcode = get_option( 'woocommerce_store_postcode' );
1103
-		if ( $this->is_valid_us_zip_code( $store_postcode ) ) {
1102
+		$store_postcode = get_option('woocommerce_store_postcode');
1103
+		if ($this->is_valid_us_zip_code($store_postcode)) {
1104 1104
 			$level3_data['shipping_from_zip'] = $store_postcode;
1105 1105
 		}
1106 1106
 
@@ -1114,20 +1114,20 @@  discard block
 block discarded – undo
1114 1114
 	 * @param object   $prepared_source The source that is used for the payment.
1115 1115
 	 * @return object                   An intent or an error.
1116 1116
 	 */
1117
-	public function create_intent( $order, $prepared_source ) {
1118
-		$request = $this->generate_create_intent_request( $order, $prepared_source );
1117
+	public function create_intent($order, $prepared_source) {
1118
+		$request = $this->generate_create_intent_request($order, $prepared_source);
1119 1119
 
1120 1120
 		// Create an intent that awaits an action.
1121
-		$intent = WC_Stripe_API::request( $request, 'payment_intents' );
1122
-		if ( ! empty( $intent->error ) ) {
1121
+		$intent = WC_Stripe_API::request($request, 'payment_intents');
1122
+		if ( ! empty($intent->error)) {
1123 1123
 			return $intent;
1124 1124
 		}
1125 1125
 
1126 1126
 		$order_id = $order->get_id();
1127
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id initiated for order $order_id" );
1127
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id initiated for order $order_id");
1128 1128
 
1129 1129
 		// Save the intent ID to the order.
1130
-		$this->save_intent_to_order( $order, $intent );
1130
+		$this->save_intent_to_order($order, $intent);
1131 1131
 
1132 1132
 		return $intent;
1133 1133
 	}
@@ -1140,27 +1140,27 @@  discard block
 block discarded – undo
1140 1140
 	 * @param object   $prepared_source Currently selected source.
1141 1141
 	 * @return object                   An updated intent.
1142 1142
 	 */
1143
-	public function update_existing_intent( $intent, $order, $prepared_source ) {
1143
+	public function update_existing_intent($intent, $order, $prepared_source) {
1144 1144
 		$request = array();
1145 1145
 
1146
-		if ( $prepared_source->source !== $intent->source ) {
1146
+		if ($prepared_source->source !== $intent->source) {
1147 1147
 			$request['source'] = $prepared_source->source;
1148 1148
 		}
1149 1149
 
1150
-		$new_amount = WC_Stripe_Helper::get_stripe_amount( $order->get_total() );
1151
-		if ( $intent->amount !== $new_amount ) {
1150
+		$new_amount = WC_Stripe_Helper::get_stripe_amount($order->get_total());
1151
+		if ($intent->amount !== $new_amount) {
1152 1152
 			$request['amount'] = $new_amount;
1153 1153
 		}
1154 1154
 
1155
-		if ( $prepared_source->customer && $intent->customer !== $prepared_source->customer ) {
1155
+		if ($prepared_source->customer && $intent->customer !== $prepared_source->customer) {
1156 1156
 			$request['customer'] = $prepared_source->customer;
1157 1157
 		}
1158 1158
 
1159
-		if ( empty( $request ) ) {
1159
+		if (empty($request)) {
1160 1160
 			return $intent;
1161 1161
 		}
1162 1162
 
1163
-		$level3_data = $this->get_level3_data_from_order( $order );
1163
+		$level3_data = $this->get_level3_data_from_order($order);
1164 1164
 		return WC_Stripe_API::request_with_level3_data(
1165 1165
 			$request,
1166 1166
 			"payment_intents/$intent->id",
@@ -1178,8 +1178,8 @@  discard block
 block discarded – undo
1178 1178
 	 * @param object   $prepared_source The source that is being charged.
1179 1179
 	 * @return object                   Either an error or the updated intent.
1180 1180
 	 */
1181
-	public function confirm_intent( $intent, $order, $prepared_source ) {
1182
-		if ( 'requires_confirmation' !== $intent->status ) {
1181
+	public function confirm_intent($intent, $order, $prepared_source) {
1182
+		if ('requires_confirmation' !== $intent->status) {
1183 1183
 			return $intent;
1184 1184
 		}
1185 1185
 
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
 			'source' => $prepared_source->source,
1189 1189
 		);
1190 1190
 
1191
-		$level3_data = $this->get_level3_data_from_order( $order );
1191
+		$level3_data = $this->get_level3_data_from_order($order);
1192 1192
 		$confirmed_intent = WC_Stripe_API::request_with_level3_data(
1193 1193
 			$confirm_request,
1194 1194
 			"payment_intents/$intent->id/confirm",
@@ -1196,16 +1196,16 @@  discard block
 block discarded – undo
1196 1196
 			$order
1197 1197
 		);
1198 1198
 
1199
-		if ( ! empty( $confirmed_intent->error ) ) {
1199
+		if ( ! empty($confirmed_intent->error)) {
1200 1200
 			return $confirmed_intent;
1201 1201
 		}
1202 1202
 
1203 1203
 		// Save a note about the status of the intent.
1204 1204
 		$order_id = $order->get_id();
1205
-		if ( 'succeeded' === $confirmed_intent->status ) {
1206
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
1207
-		} elseif ( 'requires_action' === $confirmed_intent->status ) {
1208
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id requires authentication for order $order_id" );
1205
+		if ('succeeded' === $confirmed_intent->status) {
1206
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
1207
+		} elseif ('requires_action' === $confirmed_intent->status) {
1208
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id requires authentication for order $order_id");
1209 1209
 		}
1210 1210
 
1211 1211
 		return $confirmed_intent;
@@ -1218,10 +1218,10 @@  discard block
 block discarded – undo
1218 1218
 	 * @param WC_Order $order For to which the source applies.
1219 1219
 	 * @param stdClass $intent Payment intent information.
1220 1220
 	 */
1221
-	public function save_intent_to_order( $order, $intent ) {
1222
-		$order->update_meta_data( '_stripe_intent_id', $intent->id );
1221
+	public function save_intent_to_order($order, $intent) {
1222
+		$order->update_meta_data('_stripe_intent_id', $intent->id);
1223 1223
 
1224
-		if ( is_callable( array( $order, 'save' ) ) ) {
1224
+		if (is_callable(array($order, 'save'))) {
1225 1225
 			$order->save();
1226 1226
 		}
1227 1227
 	}
@@ -1233,18 +1233,18 @@  discard block
 block discarded – undo
1233 1233
 	 * @param WC_Order $order The order to retrieve an intent for.
1234 1234
 	 * @return obect|bool     Either the intent object or `false`.
1235 1235
 	 */
1236
-	public function get_intent_from_order( $order ) {
1237
-		$intent_id = $order->get_meta( '_stripe_intent_id' );
1236
+	public function get_intent_from_order($order) {
1237
+		$intent_id = $order->get_meta('_stripe_intent_id');
1238 1238
 
1239
-		if ( $intent_id ) {
1240
-			return $this->get_intent( 'payment_intents', $intent_id );
1239
+		if ($intent_id) {
1240
+			return $this->get_intent('payment_intents', $intent_id);
1241 1241
 		}
1242 1242
 
1243 1243
 		// The order doesn't have a payment intent, but it may have a setup intent.
1244
-		$intent_id = $order->get_meta( '_stripe_setup_intent' );
1244
+		$intent_id = $order->get_meta('_stripe_setup_intent');
1245 1245
 
1246
-		if ( $intent_id ) {
1247
-			return $this->get_intent( 'setup_intents', $intent_id );
1246
+		if ($intent_id) {
1247
+			return $this->get_intent('setup_intents', $intent_id);
1248 1248
 		}
1249 1249
 
1250 1250
 		return false;
@@ -1258,15 +1258,15 @@  discard block
 block discarded – undo
1258 1258
 	 * @return object|bool 			Either the intent object or `false`.
1259 1259
 	 * @throws Exception 			Throws exception for unknown $intent_type.
1260 1260
 	 */
1261
-	private function get_intent( $intent_type, $intent_id ) {
1262
-		if ( ! in_array( $intent_type, [ 'payment_intents', 'setup_intents' ] ) ) {
1263
-			throw new Exception( "Failed to get intent of type $intent_type. Type is not allowed" );
1261
+	private function get_intent($intent_type, $intent_id) {
1262
+		if ( ! in_array($intent_type, ['payment_intents', 'setup_intents'])) {
1263
+			throw new Exception("Failed to get intent of type $intent_type. Type is not allowed");
1264 1264
 		}
1265 1265
 
1266
-		$response = WC_Stripe_API::request( array(), "$intent_type/$intent_id", 'GET' );
1266
+		$response = WC_Stripe_API::request(array(), "$intent_type/$intent_id", 'GET');
1267 1267
 
1268
-		if ( $response && isset( $response->{ 'error' } ) ) {
1269
-			$error_response_message = print_r( $response, true );
1268
+		if ($response && isset($response->{ 'error' } )) {
1269
+			$error_response_message = print_r($response, true);
1270 1270
 			WC_Stripe_Logger::log("Failed to get Stripe intent $intent_type/$intent_id.");
1271 1271
 			WC_Stripe_Logger::log("Response: $error_response_message");
1272 1272
 			return false;
@@ -1283,18 +1283,18 @@  discard block
 block discarded – undo
1283 1283
 	 * @param stdClass $intent The intent that is being processed.
1284 1284
 	 * @return bool            A flag that indicates whether the order is already locked.
1285 1285
 	 */
1286
-	public function lock_order_payment( $order, $intent = null ) {
1286
+	public function lock_order_payment($order, $intent = null) {
1287 1287
 		$order_id       = $order->get_id();
1288 1288
 		$transient_name = 'wc_stripe_processing_intent_' . $order_id;
1289
-		$processing     = get_transient( $transient_name );
1289
+		$processing     = get_transient($transient_name);
1290 1290
 
1291 1291
 		// Block the process if the same intent is already being handled.
1292
-		if ( "-1" === $processing || ( isset( $intent->id ) && $processing === $intent->id ) ) {
1292
+		if ("-1" === $processing || (isset($intent->id) && $processing === $intent->id)) {
1293 1293
 			return true;
1294 1294
 		}
1295 1295
 
1296 1296
 		// Save the new intent as a transient, eventually overwriting another one.
1297
-		set_transient( $transient_name, empty( $intent ) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS );
1297
+		set_transient($transient_name, empty($intent) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS);
1298 1298
 
1299 1299
 		return false;
1300 1300
 	}
@@ -1305,9 +1305,9 @@  discard block
 block discarded – undo
1305 1305
 	 * @since 4.2
1306 1306
 	 * @param WC_Order $order The order that is being unlocked.
1307 1307
 	 */
1308
-	public function unlock_order_payment( $order ) {
1308
+	public function unlock_order_payment($order) {
1309 1309
 		$order_id = $order->get_id();
1310
-		delete_transient( 'wc_stripe_processing_intent_' . $order_id );
1310
+		delete_transient('wc_stripe_processing_intent_' . $order_id);
1311 1311
 	}
1312 1312
 
1313 1313
 	/**
@@ -1317,9 +1317,9 @@  discard block
 block discarded – undo
1317 1317
 	 * @param object $response The response from Stripe.
1318 1318
 	 * @return boolean Whether or not it's a 'authentication_required' error
1319 1319
 	 */
1320
-	public function is_authentication_required_for_payment( $response ) {
1321
-		return ( ! empty( $response->error ) && 'authentication_required' === $response->error->code )
1322
-			|| ( ! empty( $response->last_payment_error ) && 'authentication_required' === $response->last_payment_error->code );
1320
+	public function is_authentication_required_for_payment($response) {
1321
+		return ( ! empty($response->error) && 'authentication_required' === $response->error->code)
1322
+			|| ( ! empty($response->last_payment_error) && 'authentication_required' === $response->last_payment_error->code);
1323 1323
 	}
1324 1324
 
1325 1325
 	/**
@@ -1329,18 +1329,18 @@  discard block
 block discarded – undo
1329 1329
 	 * @param object   $prepared_source The source, entered/chosen by the customer.
1330 1330
 	 * @return string                   The client secret of the intent, used for confirmation in JS.
1331 1331
 	 */
1332
-	public function setup_intent( $order, $prepared_source ) {
1332
+	public function setup_intent($order, $prepared_source) {
1333 1333
 		$order_id     = $order->get_id();
1334
-		$setup_intent = WC_Stripe_API::request( array(
1334
+		$setup_intent = WC_Stripe_API::request(array(
1335 1335
 			'payment_method' => $prepared_source->source,
1336 1336
 			'customer'       => $prepared_source->customer,
1337 1337
 			'confirm'        => 'true',
1338
-		), 'setup_intents' );
1338
+		), 'setup_intents');
1339 1339
 
1340
-		if ( is_wp_error( $setup_intent ) ) {
1341
-			WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) );
1342
-		} elseif ( 'requires_action' === $setup_intent->status ) {
1343
-			$order->update_meta_data( '_stripe_setup_intent', $setup_intent->id );
1340
+		if (is_wp_error($setup_intent)) {
1341
+			WC_Stripe_Logger::log("Unable to create SetupIntent for Order #$order_id: " . print_r($setup_intent, true));
1342
+		} elseif ('requires_action' === $setup_intent->status) {
1343
+			$order->update_meta_data('_stripe_setup_intent', $setup_intent->id);
1344 1344
 			$order->save();
1345 1345
 
1346 1346
 			return $setup_intent->client_secret;
@@ -1355,12 +1355,12 @@  discard block
 block discarded – undo
1355 1355
 	 * @param float    $amount          The amount to charge. If not specified, it will be read from the order.
1356 1356
 	 * @return object                   An intent or an error.
1357 1357
 	 */
1358
-	public function create_and_confirm_intent_for_off_session( $order, $prepared_source, $amount = NULL ) {
1358
+	public function create_and_confirm_intent_for_off_session($order, $prepared_source, $amount = NULL) {
1359 1359
 		// The request for a charge contains metadata for the intent.
1360
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1360
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1361 1361
 
1362 1362
 		$request = array(
1363
-			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount( $amount, $full_request['currency'] ) : $full_request['amount'],
1363
+			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount($amount, $full_request['currency']) : $full_request['amount'],
1364 1364
 			'currency'             => $full_request['currency'],
1365 1365
 			'description'          => $full_request['description'],
1366 1366
 			'metadata'             => $full_request['metadata'],
@@ -1372,44 +1372,44 @@  discard block
 block discarded – undo
1372 1372
 			'confirmation_method'  => 'automatic',
1373 1373
 		);
1374 1374
 
1375
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1375
+		if (isset($full_request['statement_descriptor'])) {
1376 1376
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1377 1377
 		}
1378 1378
 
1379
-		if ( isset( $full_request['customer'] ) ) {
1379
+		if (isset($full_request['customer'])) {
1380 1380
 			$request['customer'] = $full_request['customer'];
1381 1381
 		}
1382 1382
 
1383
-		if ( isset( $full_request['source'] ) ) {
1383
+		if (isset($full_request['source'])) {
1384 1384
 			$request['source'] = $full_request['source'];
1385 1385
 		}
1386 1386
 
1387
-		$level3_data = $this->get_level3_data_from_order( $order );
1387
+		$level3_data = $this->get_level3_data_from_order($order);
1388 1388
 		$intent = WC_Stripe_API::request_with_level3_data(
1389 1389
 			$request,
1390 1390
 			'payment_intents',
1391 1391
 			$level3_data,
1392 1392
 			$order
1393 1393
 		);
1394
-		$is_authentication_required = $this->is_authentication_required_for_payment( $intent );
1394
+		$is_authentication_required = $this->is_authentication_required_for_payment($intent);
1395 1395
 
1396
-		if ( ! empty( $intent->error ) && ! $is_authentication_required ) {
1396
+		if ( ! empty($intent->error) && ! $is_authentication_required) {
1397 1397
 			return $intent;
1398 1398
 		}
1399 1399
 
1400
-		$intent_id      = ( ! empty( $intent->error )
1400
+		$intent_id = ( ! empty($intent->error)
1401 1401
 			? $intent->error->payment_intent->id
1402 1402
 			: $intent->id
1403 1403
 		);
1404
-		$payment_intent = ( ! empty( $intent->error )
1404
+		$payment_intent = ( ! empty($intent->error)
1405 1405
 			? $intent->error->payment_intent
1406 1406
 			: $intent
1407 1407
 		);
1408
-		$order_id       = $order->get_id();
1409
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent_id initiated for order $order_id" );
1408
+		$order_id = $order->get_id();
1409
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent_id initiated for order $order_id");
1410 1410
 
1411 1411
 		// Save the intent ID to the order.
1412
-		$this->save_intent_to_order( $order, $payment_intent );
1412
+		$this->save_intent_to_order($order, $payment_intent);
1413 1413
 
1414 1414
 		return $intent;
1415 1415
 	}
@@ -1420,13 +1420,13 @@  discard block
 block discarded – undo
1420 1420
 	 * Fix renewal for existing subscriptions affected by https://github.com/woocommerce/woocommerce-gateway-stripe/issues/1072.
1421 1421
 	 * @param int $order_id subscription renewal order id.
1422 1422
 	 */
1423
-	public function ensure_subscription_has_customer_id( $order_id ) {
1424
-		$subscriptions_ids = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => 'any' ) );
1425
-		foreach( $subscriptions_ids as $subscription_id => $subscription ) {
1426
-			if ( ! metadata_exists( 'post', $subscription_id, '_stripe_customer_id' ) ) {
1427
-				$stripe_customer = new WC_Stripe_Customer( $subscription->get_user_id() );
1428
-				update_post_meta( $subscription_id, '_stripe_customer_id', $stripe_customer->get_id() );
1429
-				update_post_meta( $order_id, '_stripe_customer_id', $stripe_customer->get_id() );
1423
+	public function ensure_subscription_has_customer_id($order_id) {
1424
+		$subscriptions_ids = wcs_get_subscriptions_for_order($order_id, array('order_type' => 'any'));
1425
+		foreach ($subscriptions_ids as $subscription_id => $subscription) {
1426
+			if ( ! metadata_exists('post', $subscription_id, '_stripe_customer_id')) {
1427
+				$stripe_customer = new WC_Stripe_Customer($subscription->get_user_id());
1428
+				update_post_meta($subscription_id, '_stripe_customer_id', $stripe_customer->get_id());
1429
+				update_post_meta($order_id, '_stripe_customer_id', $stripe_customer->get_id());
1430 1430
 			}
1431 1431
 		}
1432 1432
 	}
@@ -1436,7 +1436,7 @@  discard block
 block discarded – undo
1436 1436
 	 * @param string $zip The ZIP code to verify.
1437 1437
 	 * @return boolean
1438 1438
 	 */
1439
-	public function is_valid_us_zip_code( $zip ) {
1440
-		return ! empty( $zip ) && preg_match( '/^\d{5,5}(-\d{4,4})?$/', $zip );
1439
+	public function is_valid_us_zip_code($zip) {
1440
+		return ! empty($zip) && preg_match('/^\d{5,5}(-\d{4,4})?$/', $zip);
1441 1441
 	}
1442 1442
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-state.php 1 patch
Spacing   +51 added lines, -55 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
 
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 	 * @return bool
36 36
 	 */
37 37
 	public static function get_testmode() {
38
-		$stripe_settings = get_option( 'woocommerce_stripe_settings', array() );
39
-		return ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false;
38
+		$stripe_settings = get_option('woocommerce_stripe_settings', array());
39
+		return ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false;
40 40
 	}
41 41
 
42 42
 	/**
@@ -48,17 +48,17 @@  discard block
 block discarded – undo
48 48
 	 */
49 49
 	public static function get_monitoring_began_at() {
50 50
 		$option = self::get_testmode() ? self::OPTION_TEST_MONITORING_BEGAN_AT : self::OPTION_LIVE_MONITORING_BEGAN_AT;
51
-		$monitoring_began_at = get_option( $option, 0 );
52
-		if ( 0 == $monitoring_began_at ) {
53
-			$monitoring_began_at = current_time( 'timestamp', true );
54
-			update_option( $option, $monitoring_began_at );
51
+		$monitoring_began_at = get_option($option, 0);
52
+		if (0 == $monitoring_began_at) {
53
+			$monitoring_began_at = current_time('timestamp', true);
54
+			update_option($option, $monitoring_began_at);
55 55
 
56 56
 			// Enforce database consistency. This should only be needed if the user
57 57
 			// has modified the database directly. We should not allow timestamps
58 58
 			// before monitoring began.
59
-			self::set_last_webhook_success_at( 0 );
60
-			self::set_last_webhook_failure_at( 0 );
61
-			self::set_last_error_reason( self::VALIDATION_SUCCEEDED );
59
+			self::set_last_webhook_success_at(0);
60
+			self::set_last_webhook_failure_at(0);
61
+			self::set_last_error_reason(self::VALIDATION_SUCCEEDED);
62 62
 		}
63 63
 		return $monitoring_began_at;
64 64
 	}
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 	 * @since 4.4.2
70 70
 	 * @param integer UTC seconds since 1970.
71 71
 	 */
72
-	public static function set_last_webhook_success_at( $timestamp ) {
72
+	public static function set_last_webhook_success_at($timestamp) {
73 73
 		$option = self::get_testmode() ? self::OPTION_TEST_LAST_SUCCESS_AT : self::OPTION_LIVE_LAST_SUCCESS_AT;
74
-		update_option( $option, $timestamp );
74
+		update_option($option, $timestamp);
75 75
 	}
76 76
 
77 77
 	/**
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	public static function get_last_webhook_success_at() {
85 85
 		$option = self::get_testmode() ? self::OPTION_TEST_LAST_SUCCESS_AT : self::OPTION_LIVE_LAST_FAILURE_AT;
86
-		return get_option( $option, 0 );
86
+		return get_option($option, 0);
87 87
 	}
88 88
 
89 89
 	/**
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
 	 * @since 4.4.2
93 93
 	 * @param integer UTC seconds since 1970.
94 94
 	 */
95
-	public static function set_last_webhook_failure_at( $timestamp ) {
95
+	public static function set_last_webhook_failure_at($timestamp) {
96 96
 		$option = self::get_testmode() ? self::OPTION_TEST_LAST_FAILURE_AT : self::OPTION_LIVE_LAST_FAILURE_AT;
97
-		update_option( $option, $timestamp );
97
+		update_option($option, $timestamp);
98 98
 	}
99 99
 
100 100
 	/**
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 */
107 107
 	public static function get_last_webhook_failure_at() {
108 108
 		$option = self::get_testmode() ? self::OPTION_TEST_LAST_FAILURE_AT : self::OPTION_LIVE_LAST_FAILURE_AT;
109
-		return get_option( $option, 0 );
109
+		return get_option($option, 0);
110 110
 	}
111 111
 
112 112
 	/**
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 	 * @param string Reason code.
117 117
 	 * 
118 118
 	 */
119
-	public static function set_last_error_reason( $reason ) {
119
+	public static function set_last_error_reason($reason) {
120 120
 		$option = self::get_testmode() ? self::OPTION_TEST_LAST_ERROR : self::OPTION_LIVE_LAST_ERROR;
121
-		update_option( $option, $reason );
121
+		update_option($option, $reason);
122 122
 	}
123 123
 
124 124
 	/**
@@ -129,37 +129,37 @@  discard block
 block discarded – undo
129 129
 	 */
130 130
 	public static function get_last_error_reason() {
131 131
 		$option = self::get_testmode() ? self::OPTION_TEST_LAST_ERROR : self::OPTION_LIVE_LAST_ERROR;
132
-		$last_error = get_option( $option, false );
132
+		$last_error = get_option($option, false);
133 133
 
134
-		if ( ! $last_error ) {
135
-			return( __( 'No error', 'woocommerce-gateway-stripe' ) );
134
+		if ( ! $last_error) {
135
+			return(__('No error', 'woocommerce-gateway-stripe'));
136 136
 		}
137 137
 
138
-		if ( self::VALIDATION_FAILED_BODY_NULL == $last_error ) {
139
-			return( __( 'The webhook was missing expected body', 'woocommerce-gateway-stripe' ) );
138
+		if (self::VALIDATION_FAILED_BODY_NULL == $last_error) {
139
+			return(__('The webhook was missing expected body', 'woocommerce-gateway-stripe'));
140 140
 		}
141 141
 
142
-		if ( self::VALIDATION_FAILED_HEADERS_NULL == $last_error ) {
143
-			return( __( 'The webhook was missing expected headers', 'woocommerce-gateway-stripe' ) );
142
+		if (self::VALIDATION_FAILED_HEADERS_NULL == $last_error) {
143
+			return(__('The webhook was missing expected headers', 'woocommerce-gateway-stripe'));
144 144
 		}
145 145
 
146
-		if ( self::VALIDATION_FAILED_SIGNATURE_INVALID == $last_error ) {
147
-			return( __( 'The webhook signature was missing or was incorrectly formatted', 'woocommerce-gateway-stripe' ) );
146
+		if (self::VALIDATION_FAILED_SIGNATURE_INVALID == $last_error) {
147
+			return(__('The webhook signature was missing or was incorrectly formatted', 'woocommerce-gateway-stripe'));
148 148
 		}
149 149
 
150
-		if ( self::VALIDATION_FAILED_SIGNATURE_MISMATCH == $last_error ) {
151
-			return( __( 'The webhook was not signed with the expected signing secret', 'woocommerce-gateway-stripe' ) );
150
+		if (self::VALIDATION_FAILED_SIGNATURE_MISMATCH == $last_error) {
151
+			return(__('The webhook was not signed with the expected signing secret', 'woocommerce-gateway-stripe'));
152 152
 		}
153 153
 
154
-		if ( self::VALIDATION_FAILED_TIMESTAMP_MISMATCH == $last_error ) {
155
-			return( __( 'The timestamp in the webhook differed more than five minutes from the site time', 'woocommerce-gateway-stripe' ) );
154
+		if (self::VALIDATION_FAILED_TIMESTAMP_MISMATCH == $last_error) {
155
+			return(__('The timestamp in the webhook differed more than five minutes from the site time', 'woocommerce-gateway-stripe'));
156 156
 		}
157 157
 
158
-		if ( self::VALIDATION_FAILED_USER_AGENT_INVALID == $last_error ) {
159
-			return( __( 'The webhook received did not come from Stripe', 'woocommerce-gateway-stripe' ) );
158
+		if (self::VALIDATION_FAILED_USER_AGENT_INVALID == $last_error) {
159
+			return(__('The webhook received did not come from Stripe', 'woocommerce-gateway-stripe'));
160 160
 		}
161 161
 
162
-		return( __( 'Unknown error.', 'woocommerce-gateway-stripe' ) );
162
+		return(__('Unknown error.', 'woocommerce-gateway-stripe'));
163 163
 	}
164 164
 
165 165
 	/**
@@ -178,46 +178,43 @@  discard block
 block discarded – undo
178 178
 		$date_format = 'Y-m-d H:i:s e';
179 179
 
180 180
 		// Case 1 (Nominal case): Most recent = success
181
-		if ( $last_success_at > $last_failure_at ) {
181
+		if ($last_success_at > $last_failure_at) {
182 182
 			$message = sprintf(
183 183
 				$test_mode ?
184 184
 					/* translators: 1) date and time of last webhook received, e.g. 2020-06-28 10:30:50 UTC */
185
-					__( 'The most recent test webhook, timestamped %s, was processed successfully.', 'woocommerce-gateway-stripe' ) :
186
-					/* translators: 1) date and time of last webhook received, e.g. 2020-06-28 10:30:50 UTC */
187
-					__( 'The most recent live webhook, timestamped %s, was processed successfully.', 'woocommerce-gateway-stripe' ),
188
-				date( $date_format, $last_success_at )
185
+					__('The most recent test webhook, timestamped %s, was processed successfully.', 'woocommerce-gateway-stripe') : /* translators: 1) date and time of last webhook received, e.g. 2020-06-28 10:30:50 UTC */
186
+					__('The most recent live webhook, timestamped %s, was processed successfully.', 'woocommerce-gateway-stripe'),
187
+				date($date_format, $last_success_at)
189 188
 			);
190 189
 			return $message;
191 190
 		}
192 191
 
193 192
 		// Case 2: No webhooks received yet
194
-		if ( ( 0 == $last_success_at ) && ( 0 == $last_failure_at ) ) {
193
+		if ((0 == $last_success_at) && (0 == $last_failure_at)) {
195 194
 			$message = sprintf(
196 195
 				$test_mode ?
197 196
 					/* translators: 1) date and time webhook monitoring began, e.g. 2020-06-28 10:30:50 UTC */
198
-					__( 'No test webhooks have been received since monitoring began at %s.', 'woocommerce-gateway-stripe' ) :
199
-					/* translators: 1) date and time webhook monitoring began, e.g. 2020-06-28 10:30:50 UTC */
200
-					__( 'No live webhooks have been received since monitoring began at %s.', 'woocommerce-gateway-stripe' ),
201
-				date( $date_format, $monitoring_began_at )
197
+					__('No test webhooks have been received since monitoring began at %s.', 'woocommerce-gateway-stripe') : /* translators: 1) date and time webhook monitoring began, e.g. 2020-06-28 10:30:50 UTC */
198
+					__('No live webhooks have been received since monitoring began at %s.', 'woocommerce-gateway-stripe'),
199
+				date($date_format, $monitoring_began_at)
202 200
 			);
203 201
 			return $message;
204 202
 		}
205 203
 
206 204
 		// Case 3: Failure after success
207
-		if ( $last_success_at > 0 ) {
205
+		if ($last_success_at > 0) {
208 206
 			$message = sprintf(
209 207
 				$test_mode ?
210 208
 					/* translators: 1) date and time of last failed webhook e.g. 2020-06-28 10:30:50 UTC */
211 209
 					/* translators: 2) reason webhook failed */
212 210
 					/* translators: 3) date and time of last successful webhook e.g. 2020-05-28 10:30:50 UTC */
213
-					__( 'Warning: The most recent test webhook, received at %s, could not be processed. Reason: %s. (The last test webhook to process successfully was timestamped %s.)', 'woocommerce-gateway-stripe' ) :
214
-					/* translators: 1) date and time of last failed webhook e.g. 2020-06-28 10:30:50 UTC */
211
+					__('Warning: The most recent test webhook, received at %s, could not be processed. Reason: %s. (The last test webhook to process successfully was timestamped %s.)', 'woocommerce-gateway-stripe') : /* translators: 1) date and time of last failed webhook e.g. 2020-06-28 10:30:50 UTC */
215 212
 					/* translators: 2) reason webhook failed */
216 213
 					/* translators: 3) date and time of last successful webhook e.g. 2020-05-28 10:30:50 UTC */
217
-					__( 'Warning: The most recent live webhook, received at %s, could not be processed. Reason: %s. (The last live webhook to process successfully was timestamped %s.)', 'woocommerce-gateway-stripe' ),
218
-				date( $date_format, $last_failure_at ),
214
+					__('Warning: The most recent live webhook, received at %s, could not be processed. Reason: %s. (The last live webhook to process successfully was timestamped %s.)', 'woocommerce-gateway-stripe'),
215
+				date($date_format, $last_failure_at),
219 216
 				$last_error,
220
-				date( $date_format, $last_success_at )
217
+				date($date_format, $last_success_at)
221 218
 			);
222 219
 			return $message;
223 220
 		}
@@ -228,14 +225,13 @@  discard block
 block discarded – undo
228 225
 				/* translators: 1) date and time of last failed webhook e.g. 2020-06-28 10:30:50 UTC */
229 226
 				/* translators: 2) reason webhook failed */
230 227
 				/* translators: 3) date and time webhook monitoring began e.g. 2020-05-28 10:30:50 UTC */
231
-				__( 'Warning: The most recent test webhook, received at %s, could not be processed. Reason: %s. (No test webhooks have been processed successfully since monitoring began at %s.)', 'woocommerce-gateway-stripe' ) :
232
-				/* translators: 1) date and time of last failed webhook e.g. 2020-06-28 10:30:50 UTC */
228
+				__('Warning: The most recent test webhook, received at %s, could not be processed. Reason: %s. (No test webhooks have been processed successfully since monitoring began at %s.)', 'woocommerce-gateway-stripe') : /* translators: 1) date and time of last failed webhook e.g. 2020-06-28 10:30:50 UTC */
233 229
 				/* translators: 2) reason webhook failed */
234 230
 				/* translators: 3) date and time webhook monitoring began e.g. 2020-05-28 10:30:50 UTC */
235
-				__( 'Warning: The most recent live webhook, received at %s, could not be processed. Reason: %s. (No live webhooks have been processed successfully since monitoring began at %s.)', 'woocommerce-gateway-stripe' ),
236
-			date( $date_format, $last_failure_at ),
231
+				__('Warning: The most recent live webhook, received at %s, could not be processed. Reason: %s. (No live webhooks have been processed successfully since monitoring began at %s.)', 'woocommerce-gateway-stripe'),
232
+			date($date_format, $last_failure_at),
237 233
 			$last_error,
238
-			date( $date_format, $monitoring_began_at )
234
+			date($date_format, $monitoring_began_at)
239 235
 		);
240 236
 		return $message;
241 237
 	}
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +99 added lines, -99 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.4.0' );
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.0' );
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.4.0');
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.0');
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,25 +51,25 @@  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
-add_action( 'plugins_loaded', 'woocommerce_gateway_stripe_init' );
57
+add_action('plugins_loaded', 'woocommerce_gateway_stripe_init');
58 58
 
59 59
 function woocommerce_gateway_stripe_init() {
60
-	load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
60
+	load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
61 61
 
62
-	if ( ! class_exists( 'WooCommerce' ) ) {
63
-		add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' );
62
+	if ( ! class_exists('WooCommerce')) {
63
+		add_action('admin_notices', 'woocommerce_stripe_missing_wc_notice');
64 64
 		return;
65 65
 	}
66 66
 
67
-	if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
68
-		add_action( 'admin_notices', 'woocommerce_stripe_wc_not_supported' );
67
+	if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
68
+		add_action('admin_notices', 'woocommerce_stripe_wc_not_supported');
69 69
 		return;
70 70
 	}
71 71
 
72
-	if ( ! class_exists( 'WC_Stripe' ) ) :
72
+	if ( ! class_exists('WC_Stripe')) :
73 73
 
74 74
 		class WC_Stripe {
75 75
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 			 * @return Singleton The *Singleton* instance.
85 85
 			 */
86 86
 			public static function get_instance() {
87
-				if ( null === self::$instance ) {
87
+				if (null === self::$instance) {
88 88
 					self::$instance = new self();
89 89
 				}
90 90
 				return self::$instance;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 			 * *Singleton* via the `new` operator from outside of this class.
112 112
 			 */
113 113
 			private function __construct() {
114
-				add_action( 'admin_init', array( $this, 'install' ) );
114
+				add_action('admin_init', array($this, 'install'));
115 115
 				$this->init();
116 116
 			}
117 117
 
@@ -122,54 +122,54 @@  discard block
 block discarded – undo
122 122
 			 * @version 4.0.0
123 123
 			 */
124 124
 			public function init() {
125
-				if ( is_admin() ) {
126
-					require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-privacy.php';
125
+				if (is_admin()) {
126
+					require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-privacy.php';
127 127
 				}
128 128
 
129
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php';
130
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php';
131
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php';
132
-				include_once dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php';
133
-				require_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php';
134
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-state.php';
135
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php';
136
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php';
137
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php';
138
-				require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php';
139
-				require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php';
140
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php';
141
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php';
142
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php';
143
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php';
144
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php';
145
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php';
146
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php';
147
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php';
148
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php';
149
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php';
150
-				require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php';
151
-				require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php';
152
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php';
153
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php';
154
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php';
155
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-intent-controller.php';
156
-
157
-				if ( is_admin() ) {
158
-					require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php';
129
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-exception.php';
130
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-logger.php';
131
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-helper.php';
132
+				include_once dirname(__FILE__) . '/includes/class-wc-stripe-api.php';
133
+				require_once dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php';
134
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-webhook-state.php';
135
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php';
136
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php';
137
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php';
138
+				require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-pre-orders-compat.php';
139
+				require_once dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php';
140
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php';
141
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php';
142
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php';
143
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php';
144
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php';
145
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php';
146
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php';
147
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php';
148
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php';
149
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php';
150
+				require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-subs-compat.php';
151
+				require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php';
152
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php';
153
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php';
154
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-customer.php';
155
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-intent-controller.php';
156
+
157
+				if (is_admin()) {
158
+					require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-admin-notices.php';
159 159
 				}
160 160
 
161 161
 				// REMOVE IN THE FUTURE.
162
-				require_once dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php';
162
+				require_once dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php';
163 163
 
164
-				add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
165
-				add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
166
-				add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
164
+				add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
165
+				add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
166
+				add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
167 167
 
168 168
 				// Modify emails emails.
169
-				add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ), 20 );
169
+				add_filter('woocommerce_email_classes', array($this, 'add_emails'), 20);
170 170
 
171
-				if ( version_compare( WC_VERSION, '3.4', '<' ) ) {
172
-					add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) );
171
+				if (version_compare(WC_VERSION, '3.4', '<')) {
172
+					add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin'));
173 173
 				}
174 174
 			}
175 175
 
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
 			 * @version 4.0.0
181 181
 			 */
182 182
 			public function update_plugin_version() {
183
-				delete_option( 'wc_stripe_version' );
184
-				update_option( 'wc_stripe_version', WC_STRIPE_VERSION );
183
+				delete_option('wc_stripe_version');
184
+				update_option('wc_stripe_version', WC_STRIPE_VERSION);
185 185
 			}
186 186
 
187 187
 			/**
@@ -191,15 +191,15 @@  discard block
 block discarded – undo
191 191
 			 * @version 3.1.0
192 192
 			 */
193 193
 			public function install() {
194
-				if ( ! is_plugin_active( plugin_basename( __FILE__ ) ) ) {
194
+				if ( ! is_plugin_active(plugin_basename(__FILE__))) {
195 195
 					return;
196 196
 				}
197 197
 
198
-				if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) {
199
-					do_action( 'woocommerce_stripe_updated' );
198
+				if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) {
199
+					do_action('woocommerce_stripe_updated');
200 200
 
201
-					if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) {
202
-						define( 'WC_STRIPE_INSTALLING', true );
201
+					if ( ! defined('WC_STRIPE_INSTALLING')) {
202
+						define('WC_STRIPE_INSTALLING', true);
203 203
 					}
204 204
 
205 205
 					$this->update_plugin_version();
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
 			 * @since 1.0.0
213 213
 			 * @version 4.0.0
214 214
 			 */
215
-			public function plugin_action_links( $links ) {
215
+			public function plugin_action_links($links) {
216 216
 				$plugin_links = array(
217
-					'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
217
+					'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>',
218 218
 				);
219
-				return array_merge( $plugin_links, $links );
219
+				return array_merge($plugin_links, $links);
220 220
 			}
221 221
 
222 222
 			/**
@@ -227,13 +227,13 @@  discard block
 block discarded – undo
227 227
 			 * @param  string $file  Name of current file.
228 228
 			 * @return array  $links Update list of plugin links.
229 229
 			 */
230
-			public function plugin_row_meta( $links, $file ) {
231
-				if ( plugin_basename( __FILE__ ) === $file ) {
230
+			public function plugin_row_meta($links, $file) {
231
+				if (plugin_basename(__FILE__) === $file) {
232 232
 					$row_meta = array(
233
-						'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>',
234
-						'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>',
233
+						'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>',
234
+						'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>',
235 235
 					);
236
-					return array_merge( $links, $row_meta );
236
+					return array_merge($links, $row_meta);
237 237
 				}
238 238
 				return (array) $links;
239 239
 			}
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 			 * @since 1.0.0
245 245
 			 * @version 4.0.0
246 246
 			 */
247
-			public function add_gateways( $methods ) {
248
-				if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
247
+			public function add_gateways($methods) {
248
+				if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
249 249
 					$methods[] = 'WC_Stripe_Subs_Compat';
250 250
 					$methods[] = 'WC_Stripe_Sepa_Subs_Compat';
251 251
 				} else {
@@ -271,28 +271,28 @@  discard block
 block discarded – undo
271 271
 			 * @since 4.0.0
272 272
 			 * @version 4.0.0
273 273
 			 */
274
-			public function filter_gateway_order_admin( $sections ) {
275
-				unset( $sections['stripe'] );
276
-				unset( $sections['stripe_bancontact'] );
277
-				unset( $sections['stripe_sofort'] );
278
-				unset( $sections['stripe_giropay'] );
279
-				unset( $sections['stripe_eps'] );
280
-				unset( $sections['stripe_ideal'] );
281
-				unset( $sections['stripe_p24'] );
282
-				unset( $sections['stripe_alipay'] );
283
-				unset( $sections['stripe_sepa'] );
284
-				unset( $sections['stripe_multibanco'] );
274
+			public function filter_gateway_order_admin($sections) {
275
+				unset($sections['stripe']);
276
+				unset($sections['stripe_bancontact']);
277
+				unset($sections['stripe_sofort']);
278
+				unset($sections['stripe_giropay']);
279
+				unset($sections['stripe_eps']);
280
+				unset($sections['stripe_ideal']);
281
+				unset($sections['stripe_p24']);
282
+				unset($sections['stripe_alipay']);
283
+				unset($sections['stripe_sepa']);
284
+				unset($sections['stripe_multibanco']);
285 285
 
286 286
 				$sections['stripe']            = 'Stripe';
287
-				$sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
288
-				$sections['stripe_sofort']     = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
289
-				$sections['stripe_giropay']    = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
290
-				$sections['stripe_eps']        = __( 'Stripe EPS', 'woocommerce-gateway-stripe' );
291
-				$sections['stripe_ideal']      = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
292
-				$sections['stripe_p24']        = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
293
-				$sections['stripe_alipay']     = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
294
-				$sections['stripe_sepa']       = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
295
-				$sections['stripe_multibanco'] = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' );
287
+				$sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
288
+				$sections['stripe_sofort']     = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
289
+				$sections['stripe_giropay']    = __('Stripe Giropay', 'woocommerce-gateway-stripe');
290
+				$sections['stripe_eps']        = __('Stripe EPS', 'woocommerce-gateway-stripe');
291
+				$sections['stripe_ideal']      = __('Stripe iDeal', 'woocommerce-gateway-stripe');
292
+				$sections['stripe_p24']        = __('Stripe P24', 'woocommerce-gateway-stripe');
293
+				$sections['stripe_alipay']     = __('Stripe Alipay', 'woocommerce-gateway-stripe');
294
+				$sections['stripe_sepa']       = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
295
+				$sections['stripe_multibanco'] = __('Stripe Multibanco', 'woocommerce-gateway-stripe');
296 296
 
297 297
 				return $sections;
298 298
 			}
@@ -303,16 +303,16 @@  discard block
 block discarded – undo
303 303
 			 * @param WC_Email[] $email_classes All existing emails.
304 304
 			 * @return WC_Email[]
305 305
 			 */
306
-			public function add_emails( $email_classes ) {
306
+			public function add_emails($email_classes) {
307 307
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication.php';
308 308
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-renewal-authentication.php';
309 309
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-preorder-authentication.php';
310 310
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication-retry.php';
311 311
 
312 312
 				// Add all emails, generated by the gateway.
313
-				$email_classes['WC_Stripe_Email_Failed_Renewal_Authentication']  = new WC_Stripe_Email_Failed_Renewal_Authentication( $email_classes );
314
-				$email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication( $email_classes );
315
-				$email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry( $email_classes );
313
+				$email_classes['WC_Stripe_Email_Failed_Renewal_Authentication']  = new WC_Stripe_Email_Failed_Renewal_Authentication($email_classes);
314
+				$email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication($email_classes);
315
+				$email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry($email_classes);
316 316
 
317 317
 				return $email_classes;
318 318
 			}
Please login to merge, or discard this patch.