Completed
Pull Request — master (#1224)
by
unknown
01:50
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   +259 added lines, -259 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
 
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	public function __construct() {
54 54
 		$this->retry_interval = 2;
55
-		$stripe_settings      = get_option( 'woocommerce_stripe_settings', array() );
56
-		$this->testmode       = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false;
57
-		$secret_key           = ( $this->testmode ? 'test_' : '' ) . 'webhook_secret';
58
-		$this->secret         = ! empty( $stripe_settings[ $secret_key ] ) ? $stripe_settings[ $secret_key ] : false;
55
+		$stripe_settings      = get_option('woocommerce_stripe_settings', array());
56
+		$this->testmode       = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false;
57
+		$secret_key           = ($this->testmode ? 'test_' : '') . 'webhook_secret';
58
+		$this->secret         = ! empty($stripe_settings[$secret_key]) ? $stripe_settings[$secret_key] : false;
59 59
 
60
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
60
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
61 61
 
62 62
 		// Get/set the time we began monitoring the health of webhooks by fetching it.
63 63
 		// This should be roughly the same as the activation time of the version of the
@@ -72,32 +72,32 @@  discard block
 block discarded – undo
72 72
 	 * @version 4.0.0
73 73
 	 */
74 74
 	public function check_for_webhook() {
75
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
76
-			|| ! isset( $_GET['wc-api'] )
77
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
75
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
76
+			|| ! isset($_GET['wc-api'])
77
+			|| ('wc_stripe' !== $_GET['wc-api'])
78 78
 		) {
79 79
 			return;
80 80
 		}
81 81
 
82
-		$request_body    = file_get_contents( 'php://input' );
83
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
82
+		$request_body    = file_get_contents('php://input');
83
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
84 84
 
85 85
 		// Validate it to make sure it is legit.
86
-		$validation_result = $this->validate_request( $request_headers, $request_body );
87
-		if ( self::VALIDATION_SUCCEEDED === $validation_result ) {
88
-			$this->process_webhook( $request_body );
86
+		$validation_result = $this->validate_request($request_headers, $request_body);
87
+		if (self::VALIDATION_SUCCEEDED === $validation_result) {
88
+			$this->process_webhook($request_body);
89 89
 
90
-			$notification = json_decode( $request_body );
91
-			update_option( self::OPTION_LAST_SUCCESS_AT, $notification->created );
90
+			$notification = json_decode($request_body);
91
+			update_option(self::OPTION_LAST_SUCCESS_AT, $notification->created);
92 92
 
93
-			status_header( 200 );
93
+			status_header(200);
94 94
 			exit;
95 95
 		} else {
96
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
97
-			update_option( self::OPTION_LAST_FAILURE_AT, current_time( 'timestamp', true ) );
98
-			update_option( self::OPTION_LAST_ERROR, $validation_result );
96
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
97
+			update_option(self::OPTION_LAST_FAILURE_AT, current_time('timestamp', true));
98
+			update_option(self::OPTION_LAST_ERROR, $validation_result);
99 99
 
100
-			status_header( 400 );
100
+			status_header(400);
101 101
 			exit;
102 102
 		}
103 103
 	}
@@ -111,37 +111,37 @@  discard block
 block discarded – undo
111 111
 	 * @param string $request_body The request body from Stripe.
112 112
 	 * @return string The validation result (e.g. self::VALIDATION_SUCCEEDED )
113 113
 	 */
114
-	public function validate_request( $request_headers = null, $request_body = null ) {
115
-		if ( null === $request_headers ) {
114
+	public function validate_request($request_headers = null, $request_body = null) {
115
+		if (null === $request_headers) {
116 116
 			return self::VALIDATION_FAILED_HEADERS_NULL;
117 117
 		}
118
-		if ( null === $request_body ) {
118
+		if (null === $request_body) {
119 119
 			return self::VALIDATION_FAILED_BODY_NULL;
120 120
 		}
121 121
 
122
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
122
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
123 123
 			return self::VALIDATION_FAILED_USER_AGENT_INVALID;
124 124
 		}
125 125
 
126
-		if ( ! empty( $this->secret ) ) {
126
+		if ( ! empty($this->secret)) {
127 127
 			// Check for a valid signature.
128 128
 			$signature_format = '/^t=(?P<timestamp>\d+)(?P<signatures>(,v\d+=[a-z0-9]+){1,2})$/';
129
-			if ( empty( $request_headers['STRIPE-SIGNATURE'] ) || ! preg_match( $signature_format, $request_headers['STRIPE-SIGNATURE'], $matches ) ) {
129
+			if (empty($request_headers['STRIPE-SIGNATURE']) || ! preg_match($signature_format, $request_headers['STRIPE-SIGNATURE'], $matches)) {
130 130
 				return self::VALIDATION_FAILED_SIGNATURE_INVALID;
131 131
 			}
132 132
 
133 133
 			// Verify the timestamp.
134
-			$timestamp = intval( $matches['timestamp'] );
135
-			if ( abs( $timestamp - time() ) > 5 * MINUTE_IN_SECONDS ) {
134
+			$timestamp = intval($matches['timestamp']);
135
+			if (abs($timestamp - time()) > 5 * MINUTE_IN_SECONDS) {
136 136
 				return self::VALIDATION_FAILED_TIMESTAMP_MISMATCH;
137 137
 			}
138 138
 
139 139
 			// Generate the expected signature.
140 140
 			$signed_payload     = $timestamp . '.' . $request_body;
141
-			$expected_signature = hash_hmac( 'sha256', $signed_payload, $this->secret );
141
+			$expected_signature = hash_hmac('sha256', $signed_payload, $this->secret);
142 142
 
143 143
 			// Check if the expected signature is present.
144
-			if ( ! preg_match( '/,v\d+=' . preg_quote( $expected_signature, '/' ) . '/', $matches['signatures'] ) ) {
144
+			if ( ! preg_match('/,v\d+=' . preg_quote($expected_signature, '/') . '/', $matches['signatures'])) {
145 145
 				return self::VALIDATION_FAILED_SIGNATURE_MISMATCH;
146 146
 			}
147 147
 		}
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
 	 * @version 4.0.0
159 159
 	 */
160 160
 	public function get_request_headers() {
161
-		if ( ! function_exists( 'getallheaders' ) ) {
161
+		if ( ! function_exists('getallheaders')) {
162 162
 			$headers = array();
163 163
 
164
-			foreach ( $_SERVER as $name => $value ) {
165
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
166
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
164
+			foreach ($_SERVER as $name => $value) {
165
+				if ('HTTP_' === substr($name, 0, 5)) {
166
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
167 167
 				}
168 168
 			}
169 169
 
@@ -182,30 +182,30 @@  discard block
 block discarded – undo
182 182
 	 * @param object $notification
183 183
 	 * @param bool $retry
184 184
 	 */
185
-	public function process_webhook_payment( $notification, $retry = true ) {
185
+	public function process_webhook_payment($notification, $retry = true) {
186 186
 		// The following 3 payment methods are synchronous so does not need to be handle via webhook.
187
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) {
187
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) {
188 188
 			return;
189 189
 		}
190 190
 
191
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
191
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
192 192
 
193
-		if ( ! $order ) {
194
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
193
+		if ( ! $order) {
194
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
195 195
 			return;
196 196
 		}
197 197
 
198 198
 		$order_id  = $order->get_id();
199 199
 		$source_id = $notification->data->object->id;
200 200
 
201
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
201
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
202 202
 
203 203
 		try {
204
-			if ( $order->has_status( array( 'processing', 'completed' ) ) ) {
204
+			if ($order->has_status(array('processing', 'completed'))) {
205 205
 				return;
206 206
 			}
207 207
 
208
-			if ( $order->has_status( 'on-hold' ) && ! $is_pending_receiver ) {
208
+			if ($order->has_status('on-hold') && ! $is_pending_receiver) {
209 209
 				return;
210 210
 			}
211 211
 
@@ -213,89 +213,89 @@  discard block
 block discarded – undo
213 213
 			$response = null;
214 214
 
215 215
 			// This will throw exception if not valid.
216
-			$this->validate_minimum_order_amount( $order );
216
+			$this->validate_minimum_order_amount($order);
217 217
 
218
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
218
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
219 219
 
220 220
 			// Prep source object.
221 221
 			$source_object           = new stdClass();
222 222
 			$source_object->token_id = '';
223
-			$source_object->customer = $this->get_stripe_customer_id( $order );
223
+			$source_object->customer = $this->get_stripe_customer_id($order);
224 224
 			$source_object->source   = $source_id;
225 225
 
226 226
 			// Make the request.
227
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true );
227
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true);
228 228
 			$headers  = $response['headers'];
229 229
 			$response = $response['body'];
230 230
 
231
-			if ( ! empty( $response->error ) ) {
231
+			if ( ! empty($response->error)) {
232 232
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
233
-				if ( $this->is_no_such_customer_error( $response->error ) ) {
234
-					delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
235
-					$order->delete_meta_data( '_stripe_customer_id' );
233
+				if ($this->is_no_such_customer_error($response->error)) {
234
+					delete_user_option($order->get_customer_id(), '_stripe_customer_id');
235
+					$order->delete_meta_data('_stripe_customer_id');
236 236
 					$order->save();
237 237
 				}
238 238
 
239
-				if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) {
239
+				if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) {
240 240
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
241
-					$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
241
+					$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
242 242
 					$wc_token->delete();
243
-					$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
244
-					$order->add_order_note( $localized_message );
245
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
243
+					$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
244
+					$order->add_order_note($localized_message);
245
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
246 246
 				}
247 247
 
248 248
 				// We want to retry.
249
-				if ( $this->is_retryable_error( $response->error ) ) {
250
-					if ( $retry ) {
249
+				if ($this->is_retryable_error($response->error)) {
250
+					if ($retry) {
251 251
 						// Don't do anymore retries after this.
252
-						if ( 5 <= $this->retry_interval ) {
252
+						if (5 <= $this->retry_interval) {
253 253
 
254
-							return $this->process_webhook_payment( $notification, false );
254
+							return $this->process_webhook_payment($notification, false);
255 255
 						}
256 256
 
257
-						sleep( $this->retry_interval );
257
+						sleep($this->retry_interval);
258 258
 
259 259
 						$this->retry_interval++;
260
-						return $this->process_webhook_payment( $notification, true );
260
+						return $this->process_webhook_payment($notification, true);
261 261
 					} else {
262
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
263
-						$order->add_order_note( $localized_message );
264
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
262
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
263
+						$order->add_order_note($localized_message);
264
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
265 265
 					}
266 266
 				}
267 267
 
268 268
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
269 269
 
270
-				if ( 'card_error' === $response->error->type ) {
271
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
270
+				if ('card_error' === $response->error->type) {
271
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
272 272
 				} else {
273
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
273
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
274 274
 				}
275 275
 
276
-				$order->add_order_note( $localized_message );
276
+				$order->add_order_note($localized_message);
277 277
 
278
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
278
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
279 279
 			}
280 280
 
281 281
 			// To prevent double processing the order on WC side.
282
-			if ( ! $this->is_original_request( $headers ) ) {
282
+			if ( ! $this->is_original_request($headers)) {
283 283
 				return;
284 284
 			}
285 285
 
286
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
286
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
287 287
 
288
-			$this->process_response( $response, $order );
288
+			$this->process_response($response, $order);
289 289
 
290
-		} catch ( WC_Stripe_Exception $e ) {
291
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
290
+		} catch (WC_Stripe_Exception $e) {
291
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
292 292
 
293
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e );
293
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e);
294 294
 
295
-			$statuses = array( 'pending', 'failed' );
295
+			$statuses = array('pending', 'failed');
296 296
 
297
-			if ( $order->has_status( $statuses ) ) {
298
-				$this->send_failed_order_email( $order_id );
297
+			if ($order->has_status($statuses)) {
298
+				$this->send_failed_order_email($order_id);
299 299
 			}
300 300
 		}
301 301
 	}
@@ -308,21 +308,21 @@  discard block
 block discarded – undo
308 308
 	 * @since 4.0.0
309 309
 	 * @param object $notification
310 310
 	 */
311
-	public function process_webhook_dispute( $notification ) {
312
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
311
+	public function process_webhook_dispute($notification) {
312
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
313 313
 
314
-		if ( ! $order ) {
315
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
314
+		if ( ! $order) {
315
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
316 316
 			return;
317 317
 		}
318 318
 
319 319
 		/* translators: 1) The URL to the order. */
320
-		$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 ) ) );
320
+		$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)));
321 321
 
322
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
322
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
323 323
 
324 324
 		$order_id = $order->get_id();
325
-		$this->send_failed_order_email( $order_id );
325
+		$this->send_failed_order_email($order_id);
326 326
 	}
327 327
 
328 328
 	/**
@@ -333,43 +333,43 @@  discard block
 block discarded – undo
333 333
 	 * @version 4.0.0
334 334
 	 * @param object $notification
335 335
 	 */
336
-	public function process_webhook_capture( $notification ) {
337
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
336
+	public function process_webhook_capture($notification) {
337
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
338 338
 
339
-		if ( ! $order ) {
340
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
339
+		if ( ! $order) {
340
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
341 341
 			return;
342 342
 		}
343 343
 
344
-		if ( 'stripe' === $order->get_payment_method() ) {
344
+		if ('stripe' === $order->get_payment_method()) {
345 345
 			$charge   = $order->get_transaction_id();
346
-			$captured = $order->get_meta( '_stripe_charge_captured', true );
346
+			$captured = $order->get_meta('_stripe_charge_captured', true);
347 347
 
348
-			if ( $charge && 'no' === $captured ) {
349
-				$order->update_meta_data( '_stripe_charge_captured', 'yes' );
348
+			if ($charge && 'no' === $captured) {
349
+				$order->update_meta_data('_stripe_charge_captured', 'yes');
350 350
 
351 351
 				// Store other data such as fees
352
-				$order->set_transaction_id( $notification->data->object->id );
352
+				$order->set_transaction_id($notification->data->object->id);
353 353
 
354
-				if ( isset( $notification->data->object->balance_transaction ) ) {
355
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
354
+				if (isset($notification->data->object->balance_transaction)) {
355
+					$this->update_fees($order, $notification->data->object->balance_transaction);
356 356
 				}
357 357
 
358 358
 				// Check and see if capture is partial.
359
-				if ( $this->is_partial_capture( $notification ) ) {
360
-					$partial_amount = $this->get_partial_amount_to_charge( $notification );
361
-					$order->set_total( $partial_amount );
362
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
359
+				if ($this->is_partial_capture($notification)) {
360
+					$partial_amount = $this->get_partial_amount_to_charge($notification);
361
+					$order->set_total($partial_amount);
362
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
363 363
 					/* translators: partial captured amount */
364
-					$order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) );
364
+					$order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount));
365 365
 				} else {
366
-					$order->payment_complete( $notification->data->object->id );
366
+					$order->payment_complete($notification->data->object->id);
367 367
 
368 368
 					/* translators: transaction id */
369
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
369
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
370 370
 				}
371 371
 
372
-				if ( is_callable( array( $order, 'save' ) ) ) {
372
+				if (is_callable(array($order, 'save'))) {
373 373
 					$order->save();
374 374
 				}
375 375
 			}
@@ -384,41 +384,41 @@  discard block
 block discarded – undo
384 384
 	 * @version 4.0.0
385 385
 	 * @param object $notification
386 386
 	 */
387
-	public function process_webhook_charge_succeeded( $notification ) {
387
+	public function process_webhook_charge_succeeded($notification) {
388 388
 		// Ignore the notification for charges, created through PaymentIntents.
389
-		if ( isset( $notification->data->object->payment_intent ) && $notification->data->object->payment_intent ) {
389
+		if (isset($notification->data->object->payment_intent) && $notification->data->object->payment_intent) {
390 390
 			return;
391 391
 		}
392 392
 
393 393
 		// The following payment methods are synchronous so does not need to be handle via webhook.
394
-		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 ) ) {
394
+		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)) {
395 395
 			return;
396 396
 		}
397 397
 
398
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
398
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
399 399
 
400
-		if ( ! $order ) {
401
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
400
+		if ( ! $order) {
401
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
402 402
 			return;
403 403
 		}
404 404
 
405
-		if ( ! $order->has_status( 'on-hold' ) ) {
405
+		if ( ! $order->has_status('on-hold')) {
406 406
 			return;
407 407
 		}
408 408
 
409 409
 		// Store other data such as fees
410
-		$order->set_transaction_id( $notification->data->object->id );
410
+		$order->set_transaction_id($notification->data->object->id);
411 411
 
412
-		if ( isset( $notification->data->object->balance_transaction ) ) {
413
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
412
+		if (isset($notification->data->object->balance_transaction)) {
413
+			$this->update_fees($order, $notification->data->object->balance_transaction);
414 414
 		}
415 415
 
416
-		$order->payment_complete( $notification->data->object->id );
416
+		$order->payment_complete($notification->data->object->id);
417 417
 
418 418
 		/* translators: transaction id */
419
-		$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
419
+		$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
420 420
 
421
-		if ( is_callable( array( $order, 'save' ) ) ) {
421
+		if (is_callable(array($order, 'save'))) {
422 422
 			$order->save();
423 423
 		}
424 424
 	}
@@ -430,22 +430,22 @@  discard block
 block discarded – undo
430 430
 	 * @since 4.1.5 Can handle any fail payments from any methods.
431 431
 	 * @param object $notification
432 432
 	 */
433
-	public function process_webhook_charge_failed( $notification ) {
434
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
433
+	public function process_webhook_charge_failed($notification) {
434
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
435 435
 
436
-		if ( ! $order ) {
437
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
436
+		if ( ! $order) {
437
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
438 438
 			return;
439 439
 		}
440 440
 
441 441
 		// If order status is already in failed status don't continue.
442
-		if ( $order->has_status( 'failed' ) ) {
442
+		if ($order->has_status('failed')) {
443 443
 			return;
444 444
 		}
445 445
 
446
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
446
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
447 447
 
448
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
448
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
449 449
 	}
450 450
 
451 451
 	/**
@@ -456,30 +456,30 @@  discard block
 block discarded – undo
456 456
 	 * @since 4.1.15 Add check to make sure order is processed by Stripe.
457 457
 	 * @param object $notification
458 458
 	 */
459
-	public function process_webhook_source_canceled( $notification ) {
460
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
459
+	public function process_webhook_source_canceled($notification) {
460
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
461 461
 
462 462
 		// If can't find order by charge ID, try source ID.
463
-		if ( ! $order ) {
464
-			$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
463
+		if ( ! $order) {
464
+			$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
465 465
 
466
-			if ( ! $order ) {
467
-				WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id );
466
+			if ( ! $order) {
467
+				WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id);
468 468
 				return;
469 469
 			}
470 470
 		}
471 471
 
472 472
 		// Don't proceed if payment method isn't Stripe.
473
-		if ( 'stripe' !== $order->get_payment_method() ) {
474
-			WC_Stripe_Logger::log( 'Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id() );
473
+		if ('stripe' !== $order->get_payment_method()) {
474
+			WC_Stripe_Logger::log('Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id());
475 475
 			return;
476 476
 		}
477 477
 
478
-		if ( ! $order->has_status( 'cancelled' ) ) {
479
-			$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
478
+		if ( ! $order->has_status('cancelled')) {
479
+			$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
480 480
 		}
481 481
 
482
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
482
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
483 483
 	}
484 484
 
485 485
 	/**
@@ -489,59 +489,59 @@  discard block
 block discarded – undo
489 489
 	 * @version 4.0.0
490 490
 	 * @param object $notification
491 491
 	 */
492
-	public function process_webhook_refund( $notification ) {
493
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
492
+	public function process_webhook_refund($notification) {
493
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
494 494
 
495
-		if ( ! $order ) {
496
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
495
+		if ( ! $order) {
496
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
497 497
 			return;
498 498
 		}
499 499
 
500 500
 		$order_id = $order->get_id();
501 501
 
502
-		if ( 'stripe' === $order->get_payment_method() ) {
502
+		if ('stripe' === $order->get_payment_method()) {
503 503
 			$charge    = $order->get_transaction_id();
504
-			$captured  = $order->get_meta( '_stripe_charge_captured', true );
505
-			$refund_id = $order->get_meta( '_stripe_refund_id', true );
504
+			$captured  = $order->get_meta('_stripe_charge_captured', true);
505
+			$refund_id = $order->get_meta('_stripe_refund_id', true);
506 506
 
507 507
 			// If the refund ID matches, don't continue to prevent double refunding.
508
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
508
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
509 509
 				return;
510 510
 			}
511 511
 
512 512
 			// Only refund captured charge.
513
-			if ( $charge ) {
514
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
513
+			if ($charge) {
514
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
515 515
 
516 516
 				// Create the refund.
517 517
 				$refund = wc_create_refund(
518 518
 					array(
519 519
 						'order_id' => $order_id,
520
-						'amount'   => $this->get_refund_amount( $notification ),
520
+						'amount'   => $this->get_refund_amount($notification),
521 521
 						'reason'   => $reason,
522 522
 					)
523 523
 				);
524 524
 
525
-				if ( is_wp_error( $refund ) ) {
526
-					WC_Stripe_Logger::log( $refund->get_error_message() );
525
+				if (is_wp_error($refund)) {
526
+					WC_Stripe_Logger::log($refund->get_error_message());
527 527
 				}
528 528
 
529
-				$order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id );
529
+				$order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id);
530 530
 
531
-				$amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 );
531
+				$amount = wc_price($notification->data->object->refunds->data[0]->amount / 100);
532 532
 
533
-				if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
534
-					$amount = wc_price( $notification->data->object->refunds->data[0]->amount );
533
+				if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
534
+					$amount = wc_price($notification->data->object->refunds->data[0]->amount);
535 535
 				}
536 536
 
537
-				if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) {
538
-					$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
537
+				if (isset($notification->data->object->refunds->data[0]->balance_transaction)) {
538
+					$this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction);
539 539
 				}
540 540
 
541 541
 				/* translators: 1) dollar amount 2) transaction id 3) refund message */
542
-				$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' );
542
+				$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');
543 543
 
544
-				$order->add_order_note( $refund_message );
544
+				$order->add_order_note($refund_message);
545 545
 			}
546 546
 		}
547 547
 	}
@@ -552,30 +552,30 @@  discard block
 block discarded – undo
552 552
 	 * @since 4.0.6
553 553
 	 * @param object $notification
554 554
 	 */
555
-	public function process_review_opened( $notification ) {
556
-		if ( isset( $notification->data->object->payment_intent ) ) {
557
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
555
+	public function process_review_opened($notification) {
556
+		if (isset($notification->data->object->payment_intent)) {
557
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
558 558
 
559
-			if ( ! $order ) {
560
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
559
+			if ( ! $order) {
560
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
561 561
 				return;
562 562
 			}
563 563
 		} else {
564
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
564
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
565 565
 
566
-			if ( ! $order ) {
567
-				WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge );
566
+			if ( ! $order) {
567
+				WC_Stripe_Logger::log('[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge);
568 568
 				return;
569 569
 			}
570 570
 		}
571 571
 
572 572
 		/* translators: 1) The URL to the order. 2) The reason type. */
573
-		$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 );
573
+		$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);
574 574
 
575
-		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
576
-			$order->update_status( 'on-hold', $message );
575
+		if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
576
+			$order->update_status('on-hold', $message);
577 577
 		} else {
578
-			$order->add_order_note( $message );
578
+			$order->add_order_note($message);
579 579
 		}
580 580
 	}
581 581
 
@@ -585,34 +585,34 @@  discard block
 block discarded – undo
585 585
 	 * @since 4.0.6
586 586
 	 * @param object $notification
587 587
 	 */
588
-	public function process_review_closed( $notification ) {
589
-		if ( isset( $notification->data->object->payment_intent ) ) {
590
-			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
588
+	public function process_review_closed($notification) {
589
+		if (isset($notification->data->object->payment_intent)) {
590
+			$order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent);
591 591
 
592
-			if ( ! $order ) {
593
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
592
+			if ( ! $order) {
593
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent);
594 594
 				return;
595 595
 			}
596 596
 		} else {
597
-			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
597
+			$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
598 598
 
599
-			if ( ! $order ) {
600
-				WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge );
599
+			if ( ! $order) {
600
+				WC_Stripe_Logger::log('[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge);
601 601
 				return;
602 602
 			}
603 603
 		}
604 604
 
605 605
 		/* translators: 1) The reason type. */
606
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
606
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
607 607
 
608
-		if ( $order->has_status( 'on-hold' ) ) {
609
-			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
610
-				$order->update_status( 'processing', $message );
608
+		if ($order->has_status('on-hold')) {
609
+			if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) {
610
+				$order->update_status('processing', $message);
611 611
 			} else {
612
-				$order->add_order_note( $message );
612
+				$order->add_order_note($message);
613 613
 			}
614 614
 		} else {
615
-			$order->add_order_note( $message );
615
+			$order->add_order_note($message);
616 616
 		}
617 617
 	}
618 618
 
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 	 * @version 4.0.0
624 624
 	 * @param object $notification
625 625
 	 */
626
-	public function is_partial_capture( $notification ) {
626
+	public function is_partial_capture($notification) {
627 627
 		return 0 < $notification->data->object->amount_refunded;
628 628
 	}
629 629
 
@@ -634,11 +634,11 @@  discard block
 block discarded – undo
634 634
 	 * @version 4.0.0
635 635
 	 * @param object $notification
636 636
 	 */
637
-	public function get_refund_amount( $notification ) {
638
-		if ( $this->is_partial_capture( $notification ) ) {
637
+	public function get_refund_amount($notification) {
638
+		if ($this->is_partial_capture($notification)) {
639 639
 			$amount = $notification->data->object->refunds->data[0]->amount / 100;
640 640
 
641
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
641
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
642 642
 				$amount = $notification->data->object->refunds->data[0]->amount;
643 643
 			}
644 644
 
@@ -655,12 +655,12 @@  discard block
 block discarded – undo
655 655
 	 * @version 4.0.0
656 656
 	 * @param object $notification
657 657
 	 */
658
-	public function get_partial_amount_to_charge( $notification ) {
659
-		if ( $this->is_partial_capture( $notification ) ) {
660
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
658
+	public function get_partial_amount_to_charge($notification) {
659
+		if ($this->is_partial_capture($notification)) {
660
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
661 661
 
662
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
663
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
662
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
663
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
664 664
 			}
665 665
 
666 666
 			return $amount;
@@ -669,69 +669,69 @@  discard block
 block discarded – undo
669 669
 		return false;
670 670
 	}
671 671
 
672
-	public function process_payment_intent_success( $notification ) {
672
+	public function process_payment_intent_success($notification) {
673 673
 		$intent = $notification->data->object;
674
-		$order = WC_Stripe_Helper::get_order_by_intent_id( $intent->id );
674
+		$order = WC_Stripe_Helper::get_order_by_intent_id($intent->id);
675 675
 
676
-		if ( ! $order ) {
677
-			WC_Stripe_Logger::log( 'Could not find order via intent ID: ' . $intent->id );
676
+		if ( ! $order) {
677
+			WC_Stripe_Logger::log('Could not find order via intent ID: ' . $intent->id);
678 678
 			return;
679 679
 		}
680 680
 
681
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
681
+		if ( ! $order->has_status(array('pending', 'failed'))) {
682 682
 			return;
683 683
 		}
684 684
 
685
-		if ( $this->lock_order_payment( $order, $intent ) ) {
685
+		if ($this->lock_order_payment($order, $intent)) {
686 686
 			return;
687 687
 		}
688 688
 
689 689
 		$order_id = $order->get_id();
690
-		if ( 'payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type ) {
691
-			$charge = end( $intent->charges->data );
692
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
690
+		if ('payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type) {
691
+			$charge = end($intent->charges->data);
692
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
693 693
 
694
-			do_action( 'wc_gateway_stripe_process_payment', $charge, $order );
694
+			do_action('wc_gateway_stripe_process_payment', $charge, $order);
695 695
 
696 696
 			// Process valid response.
697
-			$this->process_response( $charge, $order );
697
+			$this->process_response($charge, $order);
698 698
 
699 699
 		} else {
700 700
 			$error_message = $intent->last_payment_error ? $intent->last_payment_error->message : "";
701 701
 
702 702
 			/* translators: 1) The error message that was received from Stripe. */
703
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
703
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
704 704
 
705
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
705
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
706 706
 
707
-			$this->send_failed_order_email( $order_id );
707
+			$this->send_failed_order_email($order_id);
708 708
 		}
709 709
 
710
-		$this->unlock_order_payment( $order );
710
+		$this->unlock_order_payment($order);
711 711
 	}
712 712
 
713
-	public function process_setup_intent( $notification ) {
713
+	public function process_setup_intent($notification) {
714 714
 		$intent = $notification->data->object;
715
-		$order = WC_Stripe_Helper::get_order_by_setup_intent_id( $intent->id );
715
+		$order = WC_Stripe_Helper::get_order_by_setup_intent_id($intent->id);
716 716
 
717
-		if ( ! $order ) {
718
-			WC_Stripe_Logger::log( 'Could not find order via setup intent ID: ' . $intent->id );
717
+		if ( ! $order) {
718
+			WC_Stripe_Logger::log('Could not find order via setup intent ID: ' . $intent->id);
719 719
 			return;
720 720
 		}
721 721
 
722
-		if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) {
722
+		if ( ! $order->has_status(array('pending', 'failed'))) {
723 723
 			return;
724 724
 		}
725 725
 
726
-		if ( $this->lock_order_payment( $order, $intent ) ) {
726
+		if ($this->lock_order_payment($order, $intent)) {
727 727
 			return;
728 728
 		}
729 729
 
730 730
 		$order_id = $order->get_id();
731
-		if ( 'setup_intent.succeeded' === $notification->type ) {
732
-			WC_Stripe_Logger::log( "Stripe SetupIntent $intent->id succeeded for order $order_id" );
733
-			if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) {
734
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
731
+		if ('setup_intent.succeeded' === $notification->type) {
732
+			WC_Stripe_Logger::log("Stripe SetupIntent $intent->id succeeded for order $order_id");
733
+			if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) {
734
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
735 735
 			} else {
736 736
 				$order->payment_complete();
737 737
 			}
@@ -739,12 +739,12 @@  discard block
 block discarded – undo
739 739
 			$error_message = $intent->last_setup_error ? $intent->last_setup_error->message : "";
740 740
 
741 741
 			/* translators: 1) The error message that was received from Stripe. */
742
-			$order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) );
742
+			$order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message));
743 743
 
744
-			$this->send_failed_order_email( $order_id );
744
+			$this->send_failed_order_email($order_id);
745 745
 		}
746 746
 
747
-		$this->unlock_order_payment( $order );
747
+		$this->unlock_order_payment($order);
748 748
 	}
749 749
 
750 750
 	/**
@@ -754,55 +754,55 @@  discard block
 block discarded – undo
754 754
 	 * @version 4.0.0
755 755
 	 * @param string $request_body
756 756
 	 */
757
-	public function process_webhook( $request_body ) {
758
-		$notification = json_decode( $request_body );
757
+	public function process_webhook($request_body) {
758
+		$notification = json_decode($request_body);
759 759
 
760
-		switch ( $notification->type ) {
760
+		switch ($notification->type) {
761 761
 			case 'source.chargeable':
762
-				$this->process_webhook_payment( $notification );
762
+				$this->process_webhook_payment($notification);
763 763
 				break;
764 764
 
765 765
 			case 'source.canceled':
766
-				$this->process_webhook_source_canceled( $notification );
766
+				$this->process_webhook_source_canceled($notification);
767 767
 				break;
768 768
 
769 769
 			case 'charge.succeeded':
770
-				$this->process_webhook_charge_succeeded( $notification );
770
+				$this->process_webhook_charge_succeeded($notification);
771 771
 				break;
772 772
 
773 773
 			case 'charge.failed':
774
-				$this->process_webhook_charge_failed( $notification );
774
+				$this->process_webhook_charge_failed($notification);
775 775
 				break;
776 776
 
777 777
 			case 'charge.captured':
778
-				$this->process_webhook_capture( $notification );
778
+				$this->process_webhook_capture($notification);
779 779
 				break;
780 780
 
781 781
 			case 'charge.dispute.created':
782
-				$this->process_webhook_dispute( $notification );
782
+				$this->process_webhook_dispute($notification);
783 783
 				break;
784 784
 
785 785
 			case 'charge.refunded':
786
-				$this->process_webhook_refund( $notification );
786
+				$this->process_webhook_refund($notification);
787 787
 				break;
788 788
 
789 789
 			case 'review.opened':
790
-				$this->process_review_opened( $notification );
790
+				$this->process_review_opened($notification);
791 791
 				break;
792 792
 
793 793
 			case 'review.closed':
794
-				$this->process_review_closed( $notification );
794
+				$this->process_review_closed($notification);
795 795
 				break;
796 796
 
797 797
 			case 'payment_intent.succeeded':
798 798
 			case 'payment_intent.payment_failed':
799 799
 			case 'payment_intent.amount_capturable_updated':
800
-				$this->process_payment_intent_success( $notification );
800
+				$this->process_payment_intent_success($notification);
801 801
 				break;
802 802
 
803 803
 			case 'setup_intent.succeeded':
804 804
 			case 'setup_intent.setup_failed':
805
-				$this->process_setup_intent( $notification );
805
+				$this->process_setup_intent($notification);
806 806
 
807 807
 		}
808 808
 	}
@@ -815,17 +815,17 @@  discard block
 block discarded – undo
815 815
 	 * @return integer UTC seconds since 1970.
816 816
 	 */
817 817
 	public static function get_monitoring_began_at() {
818
-		$monitoring_began_at = get_option( self::OPTION_MONITORING_BEGAN_AT, 0 );
819
-		if ( 0 == $monitoring_began_at ) {
820
-			$monitoring_began_at = current_time( 'timestamp', true );
821
-			update_option( self::OPTION_MONITORING_BEGAN_AT, $monitoring_began_at );
818
+		$monitoring_began_at = get_option(self::OPTION_MONITORING_BEGAN_AT, 0);
819
+		if (0 == $monitoring_began_at) {
820
+			$monitoring_began_at = current_time('timestamp', true);
821
+			update_option(self::OPTION_MONITORING_BEGAN_AT, $monitoring_began_at);
822 822
 
823 823
 			// Enforce database consistency. This should only be needed if the user
824 824
 			// has modified the database directly. We should not allow timestamps
825 825
 			// before monitoring began.
826
-			delete_option( self::OPTION_LAST_SUCCESS_AT );
827
-			delete_option( self::OPTION_LAST_FAILURE_AT );
828
-			delete_option( self::OPTION_LAST_ERROR );
826
+			delete_option(self::OPTION_LAST_SUCCESS_AT);
827
+			delete_option(self::OPTION_LAST_FAILURE_AT);
828
+			delete_option(self::OPTION_LAST_ERROR);
829 829
 		}
830 830
 		return $monitoring_began_at;
831 831
 	}
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 	 * @return integer UTC seconds since 1970 | 0.
839 839
 	 */
840 840
 	public static function get_last_webhook_success_at() {
841
-		return get_option( self::OPTION_LAST_SUCCESS_AT, 0 );
841
+		return get_option(self::OPTION_LAST_SUCCESS_AT, 0);
842 842
 	}
843 843
 
844 844
 	/**
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
 	 * @return integer UTC seconds since 1970 | 0.
850 850
 	 */
851 851
 	public static function get_last_webhook_failure_at() {
852
-		return get_option( self::OPTION_LAST_FAILURE_AT, 0 );
852
+		return get_option(self::OPTION_LAST_FAILURE_AT, 0);
853 853
 	}
854 854
 
855 855
 	/**
@@ -859,37 +859,37 @@  discard block
 block discarded – undo
859 859
 	 * @return string Reason the last webhook failed.
860 860
 	 */
861 861
 	public static function get_last_error_reason() {
862
-		$last_error = get_option( self::OPTION_LAST_ERROR, false );
862
+		$last_error = get_option(self::OPTION_LAST_ERROR, false);
863 863
 
864
-		if ( ! $last_error ) {
865
-			return( __( 'No error', 'woocommerce-gateway-stripe' ) );
864
+		if ( ! $last_error) {
865
+			return(__('No error', 'woocommerce-gateway-stripe'));
866 866
 		}
867 867
 
868
-		if ( self::VALIDATION_FAILED_BODY_NULL == $last_error ) {
869
-			return( __( 'The webhook was missing expected body', 'woocommerce-gateway-stripe' ) );
868
+		if (self::VALIDATION_FAILED_BODY_NULL == $last_error) {
869
+			return(__('The webhook was missing expected body', 'woocommerce-gateway-stripe'));
870 870
 		}
871 871
 
872
-		if ( self::VALIDATION_FAILED_HEADERS_NULL == $last_error ) {
873
-			return( __( 'The webhook was missing expected headers', 'woocommerce-gateway-stripe' ) );
872
+		if (self::VALIDATION_FAILED_HEADERS_NULL == $last_error) {
873
+			return(__('The webhook was missing expected headers', 'woocommerce-gateway-stripe'));
874 874
 		}
875 875
 
876
-		if ( self::VALIDATION_FAILED_SIGNATURE_INVALID == $last_error ) {
877
-			return( __( 'The webhook signature was missing or was incorrectly formatted', 'woocommerce-gateway-stripe' ) );
876
+		if (self::VALIDATION_FAILED_SIGNATURE_INVALID == $last_error) {
877
+			return(__('The webhook signature was missing or was incorrectly formatted', 'woocommerce-gateway-stripe'));
878 878
 		}
879 879
 
880
-		if ( self::VALIDATION_FAILED_SIGNATURE_MISMATCH == $last_error ) {
881
-			return( __( 'The webhook was not signed with the expected signing secret', 'woocommerce-gateway-stripe' ) );
880
+		if (self::VALIDATION_FAILED_SIGNATURE_MISMATCH == $last_error) {
881
+			return(__('The webhook was not signed with the expected signing secret', 'woocommerce-gateway-stripe'));
882 882
 		}
883 883
 
884
-		if ( self::VALIDATION_FAILED_TIMESTAMP_MISMATCH == $last_error ) {
885
-			return( __( 'The timestamp in the webhook differed more than five minutes from the site time', 'woocommerce-gateway-stripe' ) );
884
+		if (self::VALIDATION_FAILED_TIMESTAMP_MISMATCH == $last_error) {
885
+			return(__('The timestamp in the webhook differed more than five minutes from the site time', 'woocommerce-gateway-stripe'));
886 886
 		}
887 887
 
888
-		if ( self::VALIDATION_FAILED_USER_AGENT_INVALID == $last_error ) {
889
-			return( __( 'The webhook received did not come from Stripe', 'woocommerce-gateway-stripe' ) );
888
+		if (self::VALIDATION_FAILED_USER_AGENT_INVALID == $last_error) {
889
+			return(__('The webhook received did not come from Stripe', 'woocommerce-gateway-stripe'));
890 890
 		}
891 891
 
892
-		return( __( 'Unknown error.', 'woocommerce-gateway-stripe' ) );
892
+		return(__('Unknown error.', 'woocommerce-gateway-stripe'));
893 893
 	}
894 894
 }
895 895
 
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +340 added lines, -340 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 = $this->get_webhook_status_message();
27 27
 
@@ -43,35 +43,35 @@  discard block
 block discarded – undo
43 43
 		$date_format = 'Y-m-d H:i:s e';
44 44
 
45 45
 		// Case 1 (Nominal case): Most recent = success
46
-		if ( last_success_at > $last_failure_at ) {
46
+		if (last_success_at > $last_failure_at) {
47 47
 			$message = sprintf(
48 48
 				/* translators: 1) date and time of last webhook received, e.g. 2020-06-28 10:30:50 UTC */
49
-				__( 'The most recent webhook, timestamped %s, was processed succesfully.', 'woocommerce-gateway-stripe' ),
50
-				date( $date_format, $last_success_at )
49
+				__('The most recent webhook, timestamped %s, was processed succesfully.', 'woocommerce-gateway-stripe'),
50
+				date($date_format, $last_success_at)
51 51
 			);
52 52
 			return $message;
53 53
 		}
54 54
 
55 55
 		// Case 2: No webhooks received yet
56
-		if ( ( 0 == $last_success_at ) && ( 0 == $last_failure_at ) ) {
56
+		if ((0 == $last_success_at) && (0 == $last_failure_at)) {
57 57
 			$message = sprintf(
58 58
 				/* translators: 1) date and time webhook monitoring began, e.g. 2020-06-28 10:30:50 UTC */
59
-				__( 'No webhooks have been received since monitoring began at %s.', 'woocommerce-gateway-stripe' ),
60
-				date( $date_format, $monitoring_began_at )
59
+				__('No webhooks have been received since monitoring began at %s.', 'woocommerce-gateway-stripe'),
60
+				date($date_format, $monitoring_began_at)
61 61
 			);
62 62
 			return $message;
63 63
 		}
64 64
 
65 65
 		// Case 3: Failure after success
66
-		if ( $last_success_at > 0 ) {
66
+		if ($last_success_at > 0) {
67 67
 			$message = sprintf(
68 68
 				/* translators: 1) date and time of last failed webhook e.g. 2020-06-28 10:30:50 UTC */
69 69
 				/* translators: 2) reason webhook failed */
70 70
 				/* translators: 3) date and time of last successful webhook e.g. 2020-05-28 10:30:50 UTC */
71
-				__( 'Warning: The most recent webhook, received at %s, could not be processed. Reason: %s. (The last webhook to process successfully was timestamped %s.)', 'woocommerce-gateway-stripe' ),
72
-				date( $date_format, $last_failure_at ),
71
+				__('Warning: The most recent webhook, received at %s, could not be processed. Reason: %s. (The last webhook to process successfully was timestamped %s.)', 'woocommerce-gateway-stripe'),
72
+				date($date_format, $last_failure_at),
73 73
 				$last_error,
74
-				date( $date_format, $last_success_at )
74
+				date($date_format, $last_success_at)
75 75
 			);
76 76
 			return $message;
77 77
 		}
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 			/* translators: 1) date and time of last failed webhook e.g. 2020-06-28 10:30:50 UTC */
82 82
 			/* translators: 2) reason webhook failed */
83 83
 			/* translators: 3) date and time webhook monitoring began e.g. 2020-05-28 10:30:50 UTC */
84
-			__( 'Warning: The most recent webhook, received at %s, could not be processed. Reason: %s. (No webhooks have been processed successfully since monitoring began at %s.)', 'woocommerce-gateway-stripe' ),
85
-			date( $date_format, $last_failure_at ),
84
+			__('Warning: The most recent webhook, received at %s, could not be processed. Reason: %s. (No webhooks have been processed successfully since monitoring began at %s.)', 'woocommerce-gateway-stripe'),
85
+			date($date_format, $last_failure_at),
86 86
 			$last_error,
87
-			date( $date_format, $monitoring_began_at )
87
+			date($date_format, $monitoring_began_at)
88 88
 		);
89 89
 		return $message;
90 90
 	}
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 				<input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
101 101
 				<label for="wc-%1$s-new-payment-method" style="display:inline;">%2$s</label>
102 102
 			</p>',
103
-			esc_attr( $this->id ),
104
-			esc_html( apply_filters( 'wc_stripe_save_to_account_text', __( 'Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe' ) ) )
103
+			esc_attr($this->id),
104
+			esc_html(apply_filters('wc_stripe_save_to_account_text', __('Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe')))
105 105
 		);
106 106
 	}
107 107
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @since 4.0.5
113 113
 	 * @param array $error
114 114
 	 */
115
-	public function is_retryable_error( $error ) {
115
+	public function is_retryable_error($error) {
116 116
 		return (
117 117
 			'invalid_request_error' === $error->type ||
118 118
 			'idempotency_error' === $error->type ||
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
 	 * @since 4.1.0
130 130
 	 * @param array $error
131 131
 	 */
132
-	public function is_same_idempotency_error( $error ) {
132
+	public function is_same_idempotency_error($error) {
133 133
 		return (
134 134
 			$error &&
135 135
 			'idempotency_error' === $error->type &&
136
-			preg_match( '/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message )
136
+			preg_match('/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message)
137 137
 		);
138 138
 	}
139 139
 
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 	 * @since 4.1.0
145 145
 	 * @param array $error
146 146
 	 */
147
-	public function is_no_such_customer_error( $error ) {
147
+	public function is_no_such_customer_error($error) {
148 148
 		return (
149 149
 			$error &&
150 150
 			'invalid_request_error' === $error->type &&
151
-			preg_match( '/No such customer/i', $error->message )
151
+			preg_match('/No such customer/i', $error->message)
152 152
 		);
153 153
 	}
154 154
 
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
 	 * @since 4.1.0
160 160
 	 * @param array $error
161 161
 	 */
162
-	public function is_no_such_token_error( $error ) {
162
+	public function is_no_such_token_error($error) {
163 163
 		return (
164 164
 			$error &&
165 165
 			'invalid_request_error' === $error->type &&
166
-			preg_match( '/No such token/i', $error->message )
166
+			preg_match('/No such token/i', $error->message)
167 167
 		);
168 168
 	}
169 169
 
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 	 * @since 4.1.0
175 175
 	 * @param array $error
176 176
 	 */
177
-	public function is_no_such_source_error( $error ) {
177
+	public function is_no_such_source_error($error) {
178 178
 		return (
179 179
 			$error &&
180 180
 			'invalid_request_error' === $error->type &&
181
-			preg_match( '/No such source/i', $error->message )
181
+			preg_match('/No such source/i', $error->message)
182 182
 		);
183 183
 	}
184 184
 
@@ -189,11 +189,11 @@  discard block
 block discarded – undo
189 189
 	 * @since 4.1.0
190 190
 	 * @param array $error
191 191
 	 */
192
-	public function is_no_linked_source_error( $error ) {
192
+	public function is_no_linked_source_error($error) {
193 193
 		return (
194 194
 			$error &&
195 195
 			'invalid_request_error' === $error->type &&
196
-			preg_match( '/does not have a linked source with ID/i', $error->message )
196
+			preg_match('/does not have a linked source with ID/i', $error->message)
197 197
 		);
198 198
 	}
199 199
 
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
 	 * @param object $error
207 207
 	 * @return bool
208 208
 	 */
209
-	public function need_update_idempotency_key( $source_object, $error ) {
209
+	public function need_update_idempotency_key($source_object, $error) {
210 210
 		return (
211 211
 			$error &&
212 212
 			1 < $this->retry_interval &&
213
-			! empty( $source_object ) &&
213
+			! empty($source_object) &&
214 214
 			'chargeable' === $source_object->status &&
215
-			self::is_same_idempotency_error( $error )
215
+			self::is_same_idempotency_error($error)
216 216
 		);
217 217
 	}
218 218
 
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
 		// NOTE: updates to this function should be added to are_keys_set()
227 227
 		// in includes/payment-methods/class-wc-stripe-payment-request.php
228 228
 
229
-		if ( $this->testmode ) {
230
-			return preg_match( '/^pk_test_/', $this->publishable_key )
231
-				&& preg_match( '/^[rs]k_test_/', $this->secret_key );
229
+		if ($this->testmode) {
230
+			return preg_match('/^pk_test_/', $this->publishable_key)
231
+				&& preg_match('/^[rs]k_test_/', $this->secret_key);
232 232
 		} else {
233
-			return preg_match( '/^pk_live_/', $this->publishable_key )
234
-			    && preg_match( '/^[rs]k_live_/', $this->secret_key );
233
+			return preg_match('/^pk_live_/', $this->publishable_key)
234
+			    && preg_match('/^[rs]k_live_/', $this->secret_key);
235 235
 		}
236 236
 	}
237 237
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 * @since 4.1.3
242 242
 	 */
243 243
 	public function is_available() {
244
-		if ( 'yes' === $this->enabled ) {
244
+		if ('yes' === $this->enabled) {
245 245
 			return $this->are_keys_set();
246 246
 		}
247 247
 
@@ -256,12 +256,12 @@  discard block
 block discarded – undo
256 256
 	 * @param int $order_id
257 257
 	 * @return bool
258 258
 	 */
259
-	public function maybe_process_pre_orders( $order_id ) {
259
+	public function maybe_process_pre_orders($order_id) {
260 260
 		return (
261 261
 			WC_Stripe_Helper::is_pre_orders_exists() &&
262
-			$this->pre_orders->is_pre_order( $order_id ) &&
263
-			WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) &&
264
-			! is_wc_endpoint_url( 'order-pay' )
262
+			$this->pre_orders->is_pre_order($order_id) &&
263
+			WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id) &&
264
+			! is_wc_endpoint_url('order-pay')
265 265
 		);
266 266
 	}
267 267
 
@@ -305,10 +305,10 @@  discard block
 block discarded – undo
305 305
 	 * @version 4.0.0
306 306
 	 * @param object $order
307 307
 	 */
308
-	public function validate_minimum_order_amount( $order ) {
309
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
308
+	public function validate_minimum_order_amount($order) {
309
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
310 310
 			/* translators: 1) dollar amount */
311
-			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 ) ) );
311
+			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)));
312 312
 		}
313 313
 	}
314 314
 
@@ -318,14 +318,14 @@  discard block
 block discarded – undo
318 318
 	 * @since 4.0.0
319 319
 	 * @version 4.0.0
320 320
 	 */
321
-	public function get_transaction_url( $order ) {
322
-		if ( $this->testmode ) {
321
+	public function get_transaction_url($order) {
322
+		if ($this->testmode) {
323 323
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
324 324
 		} else {
325 325
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
326 326
 		}
327 327
 
328
-		return parent::get_transaction_url( $order );
328
+		return parent::get_transaction_url($order);
329 329
 	}
330 330
 
331 331
 	/**
@@ -334,12 +334,12 @@  discard block
 block discarded – undo
334 334
 	 * @since 4.0.0
335 335
 	 * @version 4.0.0
336 336
 	 */
337
-	public function get_stripe_customer_id( $order ) {
338
-		$customer = get_user_option( '_stripe_customer_id', $order->get_customer_id() );
337
+	public function get_stripe_customer_id($order) {
338
+		$customer = get_user_option('_stripe_customer_id', $order->get_customer_id());
339 339
 
340
-		if ( empty( $customer ) ) {
340
+		if (empty($customer)) {
341 341
 			// Try to get it via the order.
342
-			return $order->get_meta( '_stripe_customer_id', true );
342
+			return $order->get_meta('_stripe_customer_id', true);
343 343
 		} else {
344 344
 			return $customer;
345 345
 		}
@@ -355,9 +355,9 @@  discard block
 block discarded – undo
355 355
 	 * @param object $order
356 356
 	 * @param int $id Stripe session id.
357 357
 	 */
358
-	public function get_stripe_return_url( $order = null, $id = null ) {
359
-		if ( is_object( $order ) ) {
360
-			if ( empty( $id ) ) {
358
+	public function get_stripe_return_url($order = null, $id = null) {
359
+		if (is_object($order)) {
360
+			if (empty($id)) {
361 361
 				$id = uniqid();
362 362
 			}
363 363
 
@@ -368,10 +368,10 @@  discard block
 block discarded – undo
368 368
 				'order_id'       => $order_id,
369 369
 			);
370 370
 
371
-			return wp_sanitize_redirect( esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ) );
371
+			return wp_sanitize_redirect(esc_url_raw(add_query_arg($args, $this->get_return_url($order))));
372 372
 		}
373 373
 
374
-		return wp_sanitize_redirect( esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ) );
374
+		return wp_sanitize_redirect(esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())));
375 375
 	}
376 376
 
377 377
 	/**
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 	 * @param  int  $order_id
380 380
 	 * @return boolean
381 381
 	 */
382
-	public function has_subscription( $order_id ) {
383
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
382
+	public function has_subscription($order_id) {
383
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
384 384
 	}
385 385
 
386 386
 	/**
@@ -392,34 +392,34 @@  discard block
 block discarded – undo
392 392
 	 * @param  object $prepared_source
393 393
 	 * @return array()
394 394
 	 */
395
-	public function generate_payment_request( $order, $prepared_source ) {
396
-		$settings              = get_option( 'woocommerce_stripe_settings', array() );
397
-		$statement_descriptor  = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
398
-		$capture               = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
395
+	public function generate_payment_request($order, $prepared_source) {
396
+		$settings              = get_option('woocommerce_stripe_settings', array());
397
+		$statement_descriptor  = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
398
+		$capture               = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
399 399
 		$post_data             = array();
400
-		$post_data['currency'] = strtolower( $order->get_currency() );
401
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
400
+		$post_data['currency'] = strtolower($order->get_currency());
401
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
402 402
 		/* translators: 1) blog name 2) order number */
403
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
403
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
404 404
 		$billing_email            = $order->get_billing_email();
405 405
 		$billing_first_name       = $order->get_billing_first_name();
406 406
 		$billing_last_name        = $order->get_billing_last_name();
407 407
 
408
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
408
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
409 409
 			$post_data['receipt_email'] = $billing_email;
410 410
 		}
411 411
 
412
-		switch ( $order->get_payment_method() ) {
412
+		switch ($order->get_payment_method()) {
413 413
 			case 'stripe':
414
-				if ( ! empty( $statement_descriptor ) ) {
415
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
414
+				if ( ! empty($statement_descriptor)) {
415
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
416 416
 				}
417 417
 
418 418
 				$post_data['capture'] = $capture ? 'true' : 'false';
419 419
 				break;
420 420
 			case 'stripe_sepa':
421
-				if ( ! empty( $statement_descriptor ) ) {
422
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
421
+				if ( ! empty($statement_descriptor)) {
422
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
423 423
 				}
424 424
 				break;
425 425
 		}
@@ -427,25 +427,25 @@  discard block
 block discarded – undo
427 427
 		$post_data['expand[]'] = 'balance_transaction';
428 428
 
429 429
 		$metadata = array(
430
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
431
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
430
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
431
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
432 432
 			'order_id' => $order->get_order_number(),
433 433
 		);
434 434
 
435
-		if ( $this->has_subscription( $order->get_id() ) ) {
435
+		if ($this->has_subscription($order->get_id())) {
436 436
 			$metadata += array(
437 437
 				'payment_type' => 'recurring',
438
-				'site_url'     => esc_url( get_site_url() ),
438
+				'site_url'     => esc_url(get_site_url()),
439 439
 			);
440 440
 		}
441 441
 
442
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source );
442
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source);
443 443
 
444
-		if ( $prepared_source->customer ) {
444
+		if ($prepared_source->customer) {
445 445
 			$post_data['customer'] = $prepared_source->customer;
446 446
 		}
447 447
 
448
-		if ( $prepared_source->source ) {
448
+		if ($prepared_source->source) {
449 449
 			$post_data['source'] = $prepared_source->source;
450 450
 		}
451 451
 
@@ -457,72 +457,72 @@  discard block
 block discarded – undo
457 457
 		 * @param WC_Order $order
458 458
 		 * @param object $source
459 459
 		 */
460
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source );
460
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source);
461 461
 	}
462 462
 
463 463
 	/**
464 464
 	 * Store extra meta data for an order from a Stripe Response.
465 465
 	 */
466
-	public function process_response( $response, $order ) {
467
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
466
+	public function process_response($response, $order) {
467
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
468 468
 
469 469
 		$order_id = $order->get_id();
470
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
470
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
471 471
 
472 472
 		// Store charge data.
473
-		$order->update_meta_data( '_stripe_charge_captured', $captured );
473
+		$order->update_meta_data('_stripe_charge_captured', $captured);
474 474
 
475
-		if ( isset( $response->balance_transaction ) ) {
476
-			$this->update_fees( $order, is_string( $response->balance_transaction ) ? $response->balance_transaction : $response->balance_transaction->id );
475
+		if (isset($response->balance_transaction)) {
476
+			$this->update_fees($order, is_string($response->balance_transaction) ? $response->balance_transaction : $response->balance_transaction->id);
477 477
 		}
478 478
 
479
-		if ( 'yes' === $captured ) {
479
+		if ('yes' === $captured) {
480 480
 			/**
481 481
 			 * Charge can be captured but in a pending state. Payment methods
482 482
 			 * that are asynchronous may take couple days to clear. Webhook will
483 483
 			 * take care of the status changes.
484 484
 			 */
485
-			if ( 'pending' === $response->status ) {
486
-				$order_stock_reduced = $order->get_meta( '_order_stock_reduced', true );
485
+			if ('pending' === $response->status) {
486
+				$order_stock_reduced = $order->get_meta('_order_stock_reduced', true);
487 487
 
488
-				if ( ! $order_stock_reduced ) {
489
-					wc_reduce_stock_levels( $order_id );
488
+				if ( ! $order_stock_reduced) {
489
+					wc_reduce_stock_levels($order_id);
490 490
 				}
491 491
 
492
-				$order->set_transaction_id( $response->id );
492
+				$order->set_transaction_id($response->id);
493 493
 				/* translators: transaction id */
494
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
494
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
495 495
 			}
496 496
 
497
-			if ( 'succeeded' === $response->status ) {
498
-				$order->payment_complete( $response->id );
497
+			if ('succeeded' === $response->status) {
498
+				$order->payment_complete($response->id);
499 499
 
500 500
 				/* translators: transaction id */
501
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
502
-				$order->add_order_note( $message );
501
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
502
+				$order->add_order_note($message);
503 503
 			}
504 504
 
505
-			if ( 'failed' === $response->status ) {
506
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
507
-				$order->add_order_note( $localized_message );
508
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
505
+			if ('failed' === $response->status) {
506
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
507
+				$order->add_order_note($localized_message);
508
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
509 509
 			}
510 510
 		} else {
511
-			$order->set_transaction_id( $response->id );
511
+			$order->set_transaction_id($response->id);
512 512
 
513
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
514
-				wc_reduce_stock_levels( $order_id );
513
+			if ($order->has_status(array('pending', 'failed'))) {
514
+				wc_reduce_stock_levels($order_id);
515 515
 			}
516 516
 
517 517
 			/* translators: transaction id */
518
-			$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 ) );
518
+			$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));
519 519
 		}
520 520
 
521
-		if ( is_callable( array( $order, 'save' ) ) ) {
521
+		if (is_callable(array($order, 'save'))) {
522 522
 			$order->save();
523 523
 		}
524 524
 
525
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
525
+		do_action('wc_gateway_stripe_process_response', $response, $order);
526 526
 
527 527
 		return $response;
528 528
 	}
@@ -535,10 +535,10 @@  discard block
 block discarded – undo
535 535
 	 * @param int $order_id
536 536
 	 * @return null
537 537
 	 */
538
-	public function send_failed_order_email( $order_id ) {
538
+	public function send_failed_order_email($order_id) {
539 539
 		$emails = WC()->mailer()->get_emails();
540
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
541
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
540
+		if ( ! empty($emails) && ! empty($order_id)) {
541
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
542 542
 		}
543 543
 	}
544 544
 
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 	 * @param object $order
551 551
 	 * @return object $details
552 552
 	 */
553
-	public function get_owner_details( $order ) {
553
+	public function get_owner_details($order) {
554 554
 		$billing_first_name = $order->get_billing_first_name();
555 555
 		$billing_last_name  = $order->get_billing_last_name();
556 556
 
@@ -560,15 +560,15 @@  discard block
 block discarded – undo
560 560
 		$email = $order->get_billing_email();
561 561
 		$phone = $order->get_billing_phone();
562 562
 
563
-		if ( ! empty( $phone ) ) {
563
+		if ( ! empty($phone)) {
564 564
 			$details['phone'] = $phone;
565 565
 		}
566 566
 
567
-		if ( ! empty( $name ) ) {
567
+		if ( ! empty($name)) {
568 568
 			$details['name'] = $name;
569 569
 		}
570 570
 
571
-		if ( ! empty( $email ) ) {
571
+		if ( ! empty($email)) {
572 572
 			$details['email'] = $email;
573 573
 		}
574 574
 
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 		$details['address']['postal_code'] = $order->get_billing_postcode();
580 580
 		$details['address']['country']     = $order->get_billing_country();
581 581
 
582
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
582
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
583 583
 	}
584 584
 
585 585
 	/**
@@ -588,15 +588,15 @@  discard block
 block discarded – undo
588 588
 	 * @since 4.0.3
589 589
 	 * @param string $source_id The source ID to get source object for.
590 590
 	 */
591
-	public function get_source_object( $source_id = '' ) {
592
-		if ( empty( $source_id ) ) {
591
+	public function get_source_object($source_id = '') {
592
+		if (empty($source_id)) {
593 593
 			return '';
594 594
 		}
595 595
 
596
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
596
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
597 597
 
598
-		if ( ! empty( $source_object->error ) ) {
599
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
598
+		if ( ! empty($source_object->error)) {
599
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
600 600
 		}
601 601
 
602 602
 		return $source_object;
@@ -609,10 +609,10 @@  discard block
 block discarded – undo
609 609
 	 * @param object $source_object
610 610
 	 * @return bool
611 611
 	 */
612
-	public function is_prepaid_card( $source_object ) {
612
+	public function is_prepaid_card($source_object) {
613 613
 		return (
614 614
 			$source_object
615
-			&& ( 'token' === $source_object->object || 'source' === $source_object->object )
615
+			&& ('token' === $source_object->object || 'source' === $source_object->object)
616 616
 			&& 'prepaid' === $source_object->card->funding
617 617
 		);
618 618
 	}
@@ -624,8 +624,8 @@  discard block
 block discarded – undo
624 624
 	 * @param string $source_id
625 625
 	 * @return bool
626 626
 	 */
627
-	public function is_type_legacy_card( $source_id ) {
628
-		return ( preg_match( '/^card_/', $source_id ) );
627
+	public function is_type_legacy_card($source_id) {
628
+		return (preg_match('/^card_/', $source_id));
629 629
 	}
630 630
 
631 631
 	/**
@@ -635,9 +635,9 @@  discard block
 block discarded – undo
635 635
 	 * @return bool
636 636
 	 */
637 637
 	public function is_using_saved_payment_method() {
638
-		$payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
638
+		$payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
639 639
 
640
-		return ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
640
+		return (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']);
641 641
 	}
642 642
 
643 643
 	/**
@@ -653,64 +653,64 @@  discard block
 block discarded – undo
653 653
 	 * @throws Exception When card was not added or for and invalid card.
654 654
 	 * @return object
655 655
 	 */
656
-	public function prepare_source( $user_id, $force_save_source = false, $existing_customer_id = null ) {
657
-		$customer = new WC_Stripe_Customer( $user_id );
658
-		if ( ! empty( $existing_customer_id ) ) {
659
-			$customer->set_id( $existing_customer_id );
656
+	public function prepare_source($user_id, $force_save_source = false, $existing_customer_id = null) {
657
+		$customer = new WC_Stripe_Customer($user_id);
658
+		if ( ! empty($existing_customer_id)) {
659
+			$customer->set_id($existing_customer_id);
660 660
 		}
661 661
 
662
-		$force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
662
+		$force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
663 663
 		$source_object     = '';
664 664
 		$source_id         = '';
665 665
 		$wc_token_id       = false;
666
-		$payment_method    = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
666
+		$payment_method    = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
667 667
 		$is_token          = false;
668 668
 
669 669
 		// New CC info was entered and we have a new source to process.
670
-		if ( ! empty( $_POST['stripe_source'] ) ) {
671
-			$source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) );
670
+		if ( ! empty($_POST['stripe_source'])) {
671
+			$source_object = self::get_source_object(wc_clean($_POST['stripe_source']));
672 672
 			$source_id     = $source_object->id;
673 673
 
674 674
 			// This checks to see if customer opted to save the payment method to file.
675
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
675
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
676 676
 
677 677
 			/**
678 678
 			 * This is true if the user wants to store the card to their account.
679 679
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
680 680
 			 * actually reusable. Either that or force_save_source is true.
681 681
 			 */
682
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
683
-				$response = $customer->add_source( $source_object->id );
682
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
683
+				$response = $customer->add_source($source_object->id);
684 684
 
685
-				if ( ! empty( $response->error ) ) {
686
-					throw new WC_Stripe_Exception( print_r( $response, true ), $this->get_localized_error_message_from_response( $response ) );
685
+				if ( ! empty($response->error)) {
686
+					throw new WC_Stripe_Exception(print_r($response, true), $this->get_localized_error_message_from_response($response));
687 687
 				}
688 688
 			}
689
-		} elseif ( $this->is_using_saved_payment_method() ) {
689
+		} elseif ($this->is_using_saved_payment_method()) {
690 690
 			// Use an existing token, and then process the payment.
691
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
692
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
691
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
692
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
693 693
 
694
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
695
-				WC()->session->set( 'refresh_totals', true );
696
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
694
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
695
+				WC()->session->set('refresh_totals', true);
696
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
697 697
 			}
698 698
 
699 699
 			$source_id = $wc_token->get_token();
700 700
 
701
-			if ( $this->is_type_legacy_card( $source_id ) ) {
701
+			if ($this->is_type_legacy_card($source_id)) {
702 702
 				$is_token = true;
703 703
 			}
704
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
705
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
706
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
704
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
705
+			$stripe_token     = wc_clean($_POST['stripe_token']);
706
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
707 707
 
708 708
 			// This is true if the user wants to store the card to their account.
709
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
710
-				$response = $customer->add_source( $stripe_token );
709
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
710
+				$response = $customer->add_source($stripe_token);
711 711
 
712
-				if ( ! empty( $response->error ) ) {
713
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
712
+				if ( ! empty($response->error)) {
713
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
714 714
 				}
715 715
 				$source_id    = $response;
716 716
 			} else {
@@ -720,15 +720,15 @@  discard block
 block discarded – undo
720 720
 		}
721 721
 
722 722
 		$customer_id = $customer->get_id();
723
-		if ( ! $customer_id ) {
724
-			$customer->set_id( $customer->create_customer() );
723
+		if ( ! $customer_id) {
724
+			$customer->set_id($customer->create_customer());
725 725
 			$customer_id = $customer->get_id();
726 726
 		} else {
727 727
 			$customer_id = $customer->update_customer();
728 728
 		}
729 729
 
730
-		if ( empty( $source_object ) && ! $is_token ) {
731
-			$source_object = self::get_source_object( $source_id );
730
+		if (empty($source_object) && ! $is_token) {
731
+			$source_object = self::get_source_object($source_id);
732 732
 		}
733 733
 
734 734
 		return (object) array(
@@ -752,39 +752,39 @@  discard block
 block discarded – undo
752 752
 	 * @param object $order
753 753
 	 * @return object
754 754
 	 */
755
-	public function prepare_order_source( $order = null ) {
755
+	public function prepare_order_source($order = null) {
756 756
 		$stripe_customer = new WC_Stripe_Customer();
757 757
 		$stripe_source   = false;
758 758
 		$token_id        = false;
759 759
 		$source_object   = false;
760 760
 
761
-		if ( $order ) {
761
+		if ($order) {
762 762
 			$order_id = $order->get_id();
763 763
 
764
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
764
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
765 765
 
766
-			if ( $stripe_customer_id ) {
767
-				$stripe_customer->set_id( $stripe_customer_id );
766
+			if ($stripe_customer_id) {
767
+				$stripe_customer->set_id($stripe_customer_id);
768 768
 			}
769 769
 
770
-			$source_id = $order->get_meta( '_stripe_source_id', true );
770
+			$source_id = $order->get_meta('_stripe_source_id', true);
771 771
 
772 772
 			// Since 4.0.0, we changed card to source so we need to account for that.
773
-			if ( empty( $source_id ) ) {
774
-				$source_id = $order->get_meta( '_stripe_card_id', true );
773
+			if (empty($source_id)) {
774
+				$source_id = $order->get_meta('_stripe_card_id', true);
775 775
 
776 776
 				// Take this opportunity to update the key name.
777
-				$order->update_meta_data( '_stripe_source_id', $source_id );
777
+				$order->update_meta_data('_stripe_source_id', $source_id);
778 778
 
779
-				if ( is_callable( array( $order, 'save' ) ) ) {
779
+				if (is_callable(array($order, 'save'))) {
780 780
 					$order->save();
781 781
 				}
782 782
 			}
783 783
 
784
-			if ( $source_id ) {
784
+			if ($source_id) {
785 785
 				$stripe_source = $source_id;
786
-				$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
787
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
786
+				$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
787
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
788 788
 				/*
789 789
 				 * We can attempt to charge the customer's default source
790 790
 				 * by sending empty source id.
@@ -809,17 +809,17 @@  discard block
 block discarded – undo
809 809
 	 * @param WC_Order $order For to which the source applies.
810 810
 	 * @param stdClass $source Source information.
811 811
 	 */
812
-	public function save_source_to_order( $order, $source ) {
812
+	public function save_source_to_order($order, $source) {
813 813
 		// Store source in the order.
814
-		if ( $source->customer ) {
815
-			$order->update_meta_data( '_stripe_customer_id', $source->customer );
814
+		if ($source->customer) {
815
+			$order->update_meta_data('_stripe_customer_id', $source->customer);
816 816
 		}
817 817
 
818
-		if ( $source->source ) {
819
-			$order->update_meta_data( '_stripe_source_id', $source->source );
818
+		if ($source->source) {
819
+			$order->update_meta_data('_stripe_source_id', $source->source);
820 820
 		}
821 821
 
822
-		if ( is_callable( array( $order, 'save' ) ) ) {
822
+		if (is_callable(array($order, 'save'))) {
823 823
 			$order->save();
824 824
 		}
825 825
 	}
@@ -833,36 +833,36 @@  discard block
 block discarded – undo
833 833
 	 * @param object $order The order object
834 834
 	 * @param int $balance_transaction_id
835 835
 	 */
836
-	public function update_fees( $order, $balance_transaction_id ) {
837
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
836
+	public function update_fees($order, $balance_transaction_id) {
837
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
838 838
 
839
-		if ( empty( $balance_transaction->error ) ) {
840
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
839
+		if (empty($balance_transaction->error)) {
840
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
841 841
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
842 842
 				// values are in the local currency of the Stripe account, not from WC.
843
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
844
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
843
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
844
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
845 845
 
846 846
 				// Current data fee & net.
847
-				$fee_current = WC_Stripe_Helper::get_stripe_fee( $order );
848
-				$net_current = WC_Stripe_Helper::get_stripe_net( $order );
847
+				$fee_current = WC_Stripe_Helper::get_stripe_fee($order);
848
+				$net_current = WC_Stripe_Helper::get_stripe_net($order);
849 849
 
850 850
 				// Calculation.
851 851
 				$fee = (float) $fee_current + (float) $fee_refund;
852 852
 				$net = (float) $net_current + (float) $net_refund;
853 853
 
854
-				WC_Stripe_Helper::update_stripe_fee( $order, $fee );
855
-				WC_Stripe_Helper::update_stripe_net( $order, $net );
854
+				WC_Stripe_Helper::update_stripe_fee($order, $fee);
855
+				WC_Stripe_Helper::update_stripe_net($order, $net);
856 856
 
857
-				$currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null;
858
-				WC_Stripe_Helper::update_stripe_currency( $order, $currency );
857
+				$currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null;
858
+				WC_Stripe_Helper::update_stripe_currency($order, $currency);
859 859
 
860
-				if ( is_callable( array( $order, 'save' ) ) ) {
860
+				if (is_callable(array($order, 'save'))) {
861 861
 					$order->save();
862 862
 				}
863 863
 			}
864 864
 		} else {
865
-			WC_Stripe_Logger::log( 'Unable to update fees/net meta for order: ' . $order->get_id() );
865
+			WC_Stripe_Logger::log('Unable to update fees/net meta for order: ' . $order->get_id());
866 866
 		}
867 867
 	}
868 868
 
@@ -875,93 +875,93 @@  discard block
 block discarded – undo
875 875
 	 * @param  float $amount
876 876
 	 * @return bool
877 877
 	 */
878
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
879
-		$order = wc_get_order( $order_id );
878
+	public function process_refund($order_id, $amount = null, $reason = '') {
879
+		$order = wc_get_order($order_id);
880 880
 
881
-		if ( ! $order ) {
881
+		if ( ! $order) {
882 882
 			return false;
883 883
 		}
884 884
 
885 885
 		$request = array();
886 886
 
887 887
 		$order_currency = $order->get_currency();
888
-		$captured       = $order->get_meta( '_stripe_charge_captured', true );
888
+		$captured       = $order->get_meta('_stripe_charge_captured', true);
889 889
 		$charge_id      = $order->get_transaction_id();
890 890
 
891
-		if ( ! $charge_id ) {
891
+		if ( ! $charge_id) {
892 892
 			return false;
893 893
 		}
894 894
 
895
-		if ( ! is_null( $amount ) ) {
896
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
895
+		if ( ! is_null($amount)) {
896
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
897 897
 		}
898 898
 
899 899
 		// If order is only authorized, don't pass amount.
900
-		if ( 'yes' !== $captured ) {
901
-			unset( $request['amount'] );
900
+		if ('yes' !== $captured) {
901
+			unset($request['amount']);
902 902
 		}
903 903
 
904
-		if ( $reason ) {
904
+		if ($reason) {
905 905
 			$request['metadata'] = array(
906 906
 				'reason' => $reason,
907 907
 			);
908 908
 		}
909 909
 
910 910
 		$request['charge'] = $charge_id;
911
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$charge_id} for the amount of {$amount}" );
911
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$charge_id} for the amount of {$amount}");
912 912
 
913
-		$request = apply_filters( 'wc_stripe_refund_request', $request, $order );
913
+		$request = apply_filters('wc_stripe_refund_request', $request, $order);
914 914
 
915
-		$intent = $this->get_intent_from_order( $order );
915
+		$intent = $this->get_intent_from_order($order);
916 916
 		$intent_cancelled = false;
917
-		if ( $intent ) {
917
+		if ($intent) {
918 918
 			// If the order has a Payment Intent pending capture, then the Intent itself must be refunded (cancelled), not the Charge
919
-			if ( ! empty( $intent->error ) ) {
919
+			if ( ! empty($intent->error)) {
920 920
 				$response = $intent;
921 921
 				$intent_cancelled = true;
922
-			} elseif ( 'requires_capture' === $intent->status ) {
922
+			} elseif ('requires_capture' === $intent->status) {
923 923
 				$result = WC_Stripe_API::request(
924 924
 					array(),
925 925
 					'payment_intents/' . $intent->id . '/cancel'
926 926
 				);
927 927
 				$intent_cancelled = true;
928 928
 
929
-				if ( ! empty( $result->error ) ) {
929
+				if ( ! empty($result->error)) {
930 930
 					$response = $result;
931 931
 				} else {
932
-					$charge = end( $result->charges->data );
933
-					$response = end( $charge->refunds->data );
932
+					$charge = end($result->charges->data);
933
+					$response = end($charge->refunds->data);
934 934
 				}
935 935
 			}
936 936
 		}
937 937
 
938
-		if ( ! $intent_cancelled ) {
939
-			$response = WC_Stripe_API::request( $request, 'refunds' );
938
+		if ( ! $intent_cancelled) {
939
+			$response = WC_Stripe_API::request($request, 'refunds');
940 940
 		}
941 941
 
942
-		if ( ! empty( $response->error ) ) {
943
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
942
+		if ( ! empty($response->error)) {
943
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
944 944
 
945 945
 			return $response;
946 946
 
947
-		} elseif ( ! empty( $response->id ) ) {
948
-			$order->update_meta_data( '_stripe_refund_id', $response->id );
947
+		} elseif ( ! empty($response->id)) {
948
+			$order->update_meta_data('_stripe_refund_id', $response->id);
949 949
 
950
-			$amount = wc_price( $response->amount / 100 );
950
+			$amount = wc_price($response->amount / 100);
951 951
 
952
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
953
-				$amount = wc_price( $response->amount );
952
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
953
+				$amount = wc_price($response->amount);
954 954
 			}
955 955
 
956
-			if ( isset( $response->balance_transaction ) ) {
957
-				$this->update_fees( $order, $response->balance_transaction );
956
+			if (isset($response->balance_transaction)) {
957
+				$this->update_fees($order, $response->balance_transaction);
958 958
 			}
959 959
 
960 960
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
961
-			$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' );
961
+			$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');
962 962
 
963
-			$order->add_order_note( $refund_message );
964
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) );
963
+			$order->add_order_note($refund_message);
964
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message)));
965 965
 
966 966
 			return true;
967 967
 		}
@@ -976,46 +976,46 @@  discard block
 block discarded – undo
976 976
 	 */
977 977
 	public function add_payment_method() {
978 978
 		$error     = false;
979
-		$error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' );
979
+		$error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe');
980 980
 		$source_id = '';
981 981
 
982
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
982
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
983 983
 			$error = true;
984 984
 		}
985 985
 
986
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
986
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
987 987
 
988
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
988
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
989 989
 
990
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
990
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
991 991
 
992
-		if ( isset( $source_object ) ) {
993
-			if ( ! empty( $source_object->error ) ) {
992
+		if (isset($source_object)) {
993
+			if ( ! empty($source_object->error)) {
994 994
 				$error = true;
995 995
 			}
996 996
 
997 997
 			$source_id = $source_object->id;
998
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
999
-			$source_id = wc_clean( $_POST['stripe_token'] );
998
+		} elseif (isset($_POST['stripe_token'])) {
999
+			$source_id = wc_clean($_POST['stripe_token']);
1000 1000
 		}
1001 1001
 
1002
-		$response = $stripe_customer->add_source( $source_id );
1002
+		$response = $stripe_customer->add_source($source_id);
1003 1003
 
1004
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
1004
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
1005 1005
 			$error = true;
1006 1006
 		}
1007 1007
 
1008
-		if ( $error ) {
1009
-			wc_add_notice( $error_msg, 'error' );
1010
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
1008
+		if ($error) {
1009
+			wc_add_notice($error_msg, 'error');
1010
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
1011 1011
 			return;
1012 1012
 		}
1013 1013
 
1014
-		do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object );
1014
+		do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object);
1015 1015
 
1016 1016
 		return array(
1017 1017
 			'result'   => 'success',
1018
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
1018
+			'redirect' => wc_get_endpoint_url('payment-methods'),
1019 1019
 		);
1020 1020
 	}
1021 1021
 
@@ -1032,10 +1032,10 @@  discard block
 block discarded – undo
1032 1032
 		 * Stripe expects Norwegian to only be passed NO.
1033 1033
 		 * But WP has different dialects.
1034 1034
 		 */
1035
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
1035
+		if ('NO' === substr($locale, 3, 2)) {
1036 1036
 			$locale = 'no';
1037 1037
 		} else {
1038
-			$locale = substr( get_locale(), 0, 2 );
1038
+			$locale = substr(get_locale(), 0, 2);
1039 1039
 		}
1040 1040
 
1041 1041
 		return $locale;
@@ -1049,9 +1049,9 @@  discard block
 block discarded – undo
1049 1049
 	 * @param string $idempotency_key
1050 1050
 	 * @param array $request
1051 1051
 	 */
1052
-	public function change_idempotency_key( $idempotency_key, $request ) {
1053
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
1054
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
1052
+	public function change_idempotency_key($idempotency_key, $request) {
1053
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
1054
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
1055 1055
 		$count    = $this->retry_interval;
1056 1056
 
1057 1057
 		return $request['metadata']['order_id'] . '-' . $count . '-' . $source;
@@ -1065,8 +1065,8 @@  discard block
 block discarded – undo
1065 1065
 	 * @since 4.0.6
1066 1066
 	 * @param array $headers
1067 1067
 	 */
1068
-	public function is_original_request( $headers ) {
1069
-		if ( $headers['original-request'] === $headers['request-id'] ) {
1068
+	public function is_original_request($headers) {
1069
+		if ($headers['original-request'] === $headers['request-id']) {
1070 1070
 			return true;
1071 1071
 		}
1072 1072
 
@@ -1080,27 +1080,27 @@  discard block
 block discarded – undo
1080 1080
 	 * @param object   $prepared_source The source that is used for the payment.
1081 1081
 	 * @return array                    The arguments for the request.
1082 1082
 	 */
1083
-	public function generate_create_intent_request( $order, $prepared_source ) {
1083
+	public function generate_create_intent_request($order, $prepared_source) {
1084 1084
 		// The request for a charge contains metadata for the intent.
1085
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1085
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1086 1086
 
1087 1087
 		$request = array(
1088 1088
 			'source'               => $prepared_source->source,
1089
-			'amount'               => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
1090
-			'currency'             => strtolower( $order->get_currency() ),
1089
+			'amount'               => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
1090
+			'currency'             => strtolower($order->get_currency()),
1091 1091
 			'description'          => $full_request['description'],
1092 1092
 			'metadata'             => $full_request['metadata'],
1093
-			'capture_method'       => ( 'true' === $full_request['capture'] ) ? 'automatic' : 'manual',
1093
+			'capture_method'       => ('true' === $full_request['capture']) ? 'automatic' : 'manual',
1094 1094
 			'payment_method_types' => array(
1095 1095
 				'card',
1096 1096
 			),
1097 1097
 		);
1098 1098
 
1099
-		if ( $prepared_source->customer ) {
1099
+		if ($prepared_source->customer) {
1100 1100
 			$request['customer'] = $prepared_source->customer;
1101 1101
 		}
1102 1102
 
1103
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1103
+		if (isset($full_request['statement_descriptor'])) {
1104 1104
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1105 1105
 		}
1106 1106
 
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
 		 * @param WC_Order $order
1113 1113
 		 * @param object $source
1114 1114
 		 */
1115
-		return apply_filters( 'wc_stripe_generate_create_intent_request', $request, $order, $prepared_source );
1115
+		return apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source);
1116 1116
 	}
1117 1117
 
1118 1118
 	/**
@@ -1121,21 +1121,21 @@  discard block
 block discarded – undo
1121 1121
 	 * @param WC_Order $order The order that is being paid for.
1122 1122
 	 * @return array          The level 3 data to send to Stripe.
1123 1123
 	 */
1124
-	public function get_level3_data_from_order( $order ) {
1124
+	public function get_level3_data_from_order($order) {
1125 1125
 		// Get the order items. Don't need their keys, only their values.
1126 1126
 		// Order item IDs are used as keys in the original order items array.
1127
-		$order_items = array_values( $order->get_items() );
1127
+		$order_items = array_values($order->get_items());
1128 1128
 		$currency    = $order->get_currency();
1129 1129
 
1130
-		$stripe_line_items = array_map(function( $item ) use ( $currency ) {
1130
+		$stripe_line_items = array_map(function($item) use ($currency) {
1131 1131
 			$product_id          = $item->get_variation_id()
1132 1132
 				? $item->get_variation_id()
1133 1133
 				: $item->get_product_id();
1134
-			$product_description = substr( $item->get_name(), 0, 26 );
1134
+			$product_description = substr($item->get_name(), 0, 26);
1135 1135
 			$quantity            = $item->get_quantity();
1136
-			$unit_cost           = WC_Stripe_Helper::get_stripe_amount( ( $item->get_subtotal() / $quantity ), $currency );
1137
-			$tax_amount          = WC_Stripe_Helper::get_stripe_amount( $item->get_total_tax(), $currency );
1138
-			$discount_amount     = WC_Stripe_Helper::get_stripe_amount( $item->get_subtotal() - $item->get_total(), $currency );
1136
+			$unit_cost           = WC_Stripe_Helper::get_stripe_amount(($item->get_subtotal() / $quantity), $currency);
1137
+			$tax_amount          = WC_Stripe_Helper::get_stripe_amount($item->get_total_tax(), $currency);
1138
+			$discount_amount     = WC_Stripe_Helper::get_stripe_amount($item->get_subtotal() - $item->get_total(), $currency);
1139 1139
 
1140 1140
 			return (object) array(
1141 1141
 				'product_code'        => (string) $product_id, // Up to 12 characters that uniquely identify the product.
@@ -1149,19 +1149,19 @@  discard block
 block discarded – undo
1149 1149
 
1150 1150
 		$level3_data = array(
1151 1151
 			'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”.
1152
-			'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.
1152
+			'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.
1153 1153
 			'line_items'           => $stripe_line_items,
1154 1154
 		);
1155 1155
 
1156 1156
 		// The customer’s U.S. shipping ZIP code.
1157 1157
 		$shipping_address_zip = $order->get_shipping_postcode();
1158
-		if ( $this->is_valid_us_zip_code( $shipping_address_zip ) ) {
1158
+		if ($this->is_valid_us_zip_code($shipping_address_zip)) {
1159 1159
 			$level3_data['shipping_address_zip'] = $shipping_address_zip;
1160 1160
 		}
1161 1161
 
1162 1162
 		// The merchant’s U.S. shipping ZIP code.
1163
-		$store_postcode = get_option( 'woocommerce_store_postcode' );
1164
-		if ( $this->is_valid_us_zip_code( $store_postcode ) ) {
1163
+		$store_postcode = get_option('woocommerce_store_postcode');
1164
+		if ($this->is_valid_us_zip_code($store_postcode)) {
1165 1165
 			$level3_data['shipping_from_zip'] = $store_postcode;
1166 1166
 		}
1167 1167
 
@@ -1175,20 +1175,20 @@  discard block
 block discarded – undo
1175 1175
 	 * @param object   $prepared_source The source that is used for the payment.
1176 1176
 	 * @return object                   An intent or an error.
1177 1177
 	 */
1178
-	public function create_intent( $order, $prepared_source ) {
1179
-		$request = $this->generate_create_intent_request( $order, $prepared_source );
1178
+	public function create_intent($order, $prepared_source) {
1179
+		$request = $this->generate_create_intent_request($order, $prepared_source);
1180 1180
 
1181 1181
 		// Create an intent that awaits an action.
1182
-		$intent = WC_Stripe_API::request( $request, 'payment_intents' );
1183
-		if ( ! empty( $intent->error ) ) {
1182
+		$intent = WC_Stripe_API::request($request, 'payment_intents');
1183
+		if ( ! empty($intent->error)) {
1184 1184
 			return $intent;
1185 1185
 		}
1186 1186
 
1187 1187
 		$order_id = $order->get_id();
1188
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id initiated for order $order_id" );
1188
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id initiated for order $order_id");
1189 1189
 
1190 1190
 		// Save the intent ID to the order.
1191
-		$this->save_intent_to_order( $order, $intent );
1191
+		$this->save_intent_to_order($order, $intent);
1192 1192
 
1193 1193
 		return $intent;
1194 1194
 	}
@@ -1201,27 +1201,27 @@  discard block
 block discarded – undo
1201 1201
 	 * @param object   $prepared_source Currently selected source.
1202 1202
 	 * @return object                   An updated intent.
1203 1203
 	 */
1204
-	public function update_existing_intent( $intent, $order, $prepared_source ) {
1204
+	public function update_existing_intent($intent, $order, $prepared_source) {
1205 1205
 		$request = array();
1206 1206
 
1207
-		if ( $prepared_source->source !== $intent->source ) {
1207
+		if ($prepared_source->source !== $intent->source) {
1208 1208
 			$request['source'] = $prepared_source->source;
1209 1209
 		}
1210 1210
 
1211
-		$new_amount = WC_Stripe_Helper::get_stripe_amount( $order->get_total() );
1212
-		if ( $intent->amount !== $new_amount ) {
1211
+		$new_amount = WC_Stripe_Helper::get_stripe_amount($order->get_total());
1212
+		if ($intent->amount !== $new_amount) {
1213 1213
 			$request['amount'] = $new_amount;
1214 1214
 		}
1215 1215
 
1216
-		if ( $prepared_source->customer && $intent->customer !== $prepared_source->customer ) {
1216
+		if ($prepared_source->customer && $intent->customer !== $prepared_source->customer) {
1217 1217
 			$request['customer'] = $prepared_source->customer;
1218 1218
 		}
1219 1219
 
1220
-		if ( empty( $request ) ) {
1220
+		if (empty($request)) {
1221 1221
 			return $intent;
1222 1222
 		}
1223 1223
 
1224
-		$level3_data = $this->get_level3_data_from_order( $order );
1224
+		$level3_data = $this->get_level3_data_from_order($order);
1225 1225
 		return WC_Stripe_API::request_with_level3_data(
1226 1226
 			$request,
1227 1227
 			"payment_intents/$intent->id",
@@ -1239,8 +1239,8 @@  discard block
 block discarded – undo
1239 1239
 	 * @param object   $prepared_source The source that is being charged.
1240 1240
 	 * @return object                   Either an error or the updated intent.
1241 1241
 	 */
1242
-	public function confirm_intent( $intent, $order, $prepared_source ) {
1243
-		if ( 'requires_confirmation' !== $intent->status ) {
1242
+	public function confirm_intent($intent, $order, $prepared_source) {
1243
+		if ('requires_confirmation' !== $intent->status) {
1244 1244
 			return $intent;
1245 1245
 		}
1246 1246
 
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
 			'source' => $prepared_source->source,
1250 1250
 		);
1251 1251
 
1252
-		$level3_data = $this->get_level3_data_from_order( $order );
1252
+		$level3_data = $this->get_level3_data_from_order($order);
1253 1253
 		$confirmed_intent = WC_Stripe_API::request_with_level3_data(
1254 1254
 			$confirm_request,
1255 1255
 			"payment_intents/$intent->id/confirm",
@@ -1257,16 +1257,16 @@  discard block
 block discarded – undo
1257 1257
 			$order
1258 1258
 		);
1259 1259
 
1260
-		if ( ! empty( $confirmed_intent->error ) ) {
1260
+		if ( ! empty($confirmed_intent->error)) {
1261 1261
 			return $confirmed_intent;
1262 1262
 		}
1263 1263
 
1264 1264
 		// Save a note about the status of the intent.
1265 1265
 		$order_id = $order->get_id();
1266
-		if ( 'succeeded' === $confirmed_intent->status ) {
1267
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
1268
-		} elseif ( 'requires_action' === $confirmed_intent->status ) {
1269
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id requires authentication for order $order_id" );
1266
+		if ('succeeded' === $confirmed_intent->status) {
1267
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
1268
+		} elseif ('requires_action' === $confirmed_intent->status) {
1269
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id requires authentication for order $order_id");
1270 1270
 		}
1271 1271
 
1272 1272
 		return $confirmed_intent;
@@ -1279,10 +1279,10 @@  discard block
 block discarded – undo
1279 1279
 	 * @param WC_Order $order For to which the source applies.
1280 1280
 	 * @param stdClass $intent Payment intent information.
1281 1281
 	 */
1282
-	public function save_intent_to_order( $order, $intent ) {
1283
-		$order->update_meta_data( '_stripe_intent_id', $intent->id );
1282
+	public function save_intent_to_order($order, $intent) {
1283
+		$order->update_meta_data('_stripe_intent_id', $intent->id);
1284 1284
 
1285
-		if ( is_callable( array( $order, 'save' ) ) ) {
1285
+		if (is_callable(array($order, 'save'))) {
1286 1286
 			$order->save();
1287 1287
 		}
1288 1288
 	}
@@ -1294,18 +1294,18 @@  discard block
 block discarded – undo
1294 1294
 	 * @param WC_Order $order The order to retrieve an intent for.
1295 1295
 	 * @return obect|bool     Either the intent object or `false`.
1296 1296
 	 */
1297
-	public function get_intent_from_order( $order ) {
1298
-		$intent_id = $order->get_meta( '_stripe_intent_id' );
1297
+	public function get_intent_from_order($order) {
1298
+		$intent_id = $order->get_meta('_stripe_intent_id');
1299 1299
 
1300
-		if ( $intent_id ) {
1301
-			return $this->get_intent( 'payment_intents', $intent_id );
1300
+		if ($intent_id) {
1301
+			return $this->get_intent('payment_intents', $intent_id);
1302 1302
 		}
1303 1303
 
1304 1304
 		// The order doesn't have a payment intent, but it may have a setup intent.
1305
-		$intent_id = $order->get_meta( '_stripe_setup_intent' );
1305
+		$intent_id = $order->get_meta('_stripe_setup_intent');
1306 1306
 
1307
-		if ( $intent_id ) {
1308
-			return $this->get_intent( 'setup_intents', $intent_id );
1307
+		if ($intent_id) {
1308
+			return $this->get_intent('setup_intents', $intent_id);
1309 1309
 		}
1310 1310
 
1311 1311
 		return false;
@@ -1319,15 +1319,15 @@  discard block
 block discarded – undo
1319 1319
 	 * @return object|bool 			Either the intent object or `false`.
1320 1320
 	 * @throws Exception 			Throws exception for unknown $intent_type.
1321 1321
 	 */
1322
-	private function get_intent( $intent_type, $intent_id ) {
1323
-		if ( ! in_array( $intent_type, [ 'payment_intents', 'setup_intents' ] ) ) {
1324
-			throw new Exception( "Failed to get intent of type $intent_type. Type is not allowed" );
1322
+	private function get_intent($intent_type, $intent_id) {
1323
+		if ( ! in_array($intent_type, ['payment_intents', 'setup_intents'])) {
1324
+			throw new Exception("Failed to get intent of type $intent_type. Type is not allowed");
1325 1325
 		}
1326 1326
 
1327
-		$response = WC_Stripe_API::request( array(), "$intent_type/$intent_id", 'GET' );
1327
+		$response = WC_Stripe_API::request(array(), "$intent_type/$intent_id", 'GET');
1328 1328
 
1329
-		if ( $response && isset( $response->{ 'error' } ) ) {
1330
-			$error_response_message = print_r( $response, true );
1329
+		if ($response && isset($response->{ 'error' } )) {
1330
+			$error_response_message = print_r($response, true);
1331 1331
 			WC_Stripe_Logger::log("Failed to get Stripe intent $intent_type/$intent_id.");
1332 1332
 			WC_Stripe_Logger::log("Response: $error_response_message");
1333 1333
 			return false;
@@ -1344,18 +1344,18 @@  discard block
 block discarded – undo
1344 1344
 	 * @param stdClass $intent The intent that is being processed.
1345 1345
 	 * @return bool            A flag that indicates whether the order is already locked.
1346 1346
 	 */
1347
-	public function lock_order_payment( $order, $intent = null ) {
1347
+	public function lock_order_payment($order, $intent = null) {
1348 1348
 		$order_id       = $order->get_id();
1349 1349
 		$transient_name = 'wc_stripe_processing_intent_' . $order_id;
1350
-		$processing     = get_transient( $transient_name );
1350
+		$processing     = get_transient($transient_name);
1351 1351
 
1352 1352
 		// Block the process if the same intent is already being handled.
1353
-		if ( "-1" === $processing || ( isset( $intent->id ) && $processing === $intent->id ) ) {
1353
+		if ("-1" === $processing || (isset($intent->id) && $processing === $intent->id)) {
1354 1354
 			return true;
1355 1355
 		}
1356 1356
 
1357 1357
 		// Save the new intent as a transient, eventually overwriting another one.
1358
-		set_transient( $transient_name, empty( $intent ) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS );
1358
+		set_transient($transient_name, empty($intent) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS);
1359 1359
 
1360 1360
 		return false;
1361 1361
 	}
@@ -1366,9 +1366,9 @@  discard block
 block discarded – undo
1366 1366
 	 * @since 4.2
1367 1367
 	 * @param WC_Order $order The order that is being unlocked.
1368 1368
 	 */
1369
-	public function unlock_order_payment( $order ) {
1369
+	public function unlock_order_payment($order) {
1370 1370
 		$order_id = $order->get_id();
1371
-		delete_transient( 'wc_stripe_processing_intent_' . $order_id );
1371
+		delete_transient('wc_stripe_processing_intent_' . $order_id);
1372 1372
 	}
1373 1373
 
1374 1374
 	/**
@@ -1378,9 +1378,9 @@  discard block
 block discarded – undo
1378 1378
 	 * @param object $response The response from Stripe.
1379 1379
 	 * @return boolean Whether or not it's a 'authentication_required' error
1380 1380
 	 */
1381
-	public function is_authentication_required_for_payment( $response ) {
1382
-		return ( ! empty( $response->error ) && 'authentication_required' === $response->error->code )
1383
-			|| ( ! empty( $response->last_payment_error ) && 'authentication_required' === $response->last_payment_error->code );
1381
+	public function is_authentication_required_for_payment($response) {
1382
+		return ( ! empty($response->error) && 'authentication_required' === $response->error->code)
1383
+			|| ( ! empty($response->last_payment_error) && 'authentication_required' === $response->last_payment_error->code);
1384 1384
 	}
1385 1385
 
1386 1386
 	/**
@@ -1390,18 +1390,18 @@  discard block
 block discarded – undo
1390 1390
 	 * @param object   $prepared_source The source, entered/chosen by the customer.
1391 1391
 	 * @return string                   The client secret of the intent, used for confirmation in JS.
1392 1392
 	 */
1393
-	public function setup_intent( $order, $prepared_source ) {
1393
+	public function setup_intent($order, $prepared_source) {
1394 1394
 		$order_id     = $order->get_id();
1395
-		$setup_intent = WC_Stripe_API::request( array(
1395
+		$setup_intent = WC_Stripe_API::request(array(
1396 1396
 			'payment_method' => $prepared_source->source,
1397 1397
 			'customer'       => $prepared_source->customer,
1398 1398
 			'confirm'        => 'true',
1399
-		), 'setup_intents' );
1399
+		), 'setup_intents');
1400 1400
 
1401
-		if ( is_wp_error( $setup_intent ) ) {
1402
-			WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) );
1403
-		} elseif ( 'requires_action' === $setup_intent->status ) {
1404
-			$order->update_meta_data( '_stripe_setup_intent', $setup_intent->id );
1401
+		if (is_wp_error($setup_intent)) {
1402
+			WC_Stripe_Logger::log("Unable to create SetupIntent for Order #$order_id: " . print_r($setup_intent, true));
1403
+		} elseif ('requires_action' === $setup_intent->status) {
1404
+			$order->update_meta_data('_stripe_setup_intent', $setup_intent->id);
1405 1405
 			$order->save();
1406 1406
 
1407 1407
 			return $setup_intent->client_secret;
@@ -1416,12 +1416,12 @@  discard block
 block discarded – undo
1416 1416
 	 * @param float    $amount          The amount to charge. If not specified, it will be read from the order.
1417 1417
 	 * @return object                   An intent or an error.
1418 1418
 	 */
1419
-	public function create_and_confirm_intent_for_off_session( $order, $prepared_source, $amount = NULL ) {
1419
+	public function create_and_confirm_intent_for_off_session($order, $prepared_source, $amount = NULL) {
1420 1420
 		// The request for a charge contains metadata for the intent.
1421
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1421
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1422 1422
 
1423 1423
 		$request = array(
1424
-			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount( $amount, $full_request['currency'] ) : $full_request['amount'],
1424
+			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount($amount, $full_request['currency']) : $full_request['amount'],
1425 1425
 			'currency'             => $full_request['currency'],
1426 1426
 			'description'          => $full_request['description'],
1427 1427
 			'metadata'             => $full_request['metadata'],
@@ -1433,44 +1433,44 @@  discard block
 block discarded – undo
1433 1433
 			'confirmation_method'  => 'automatic',
1434 1434
 		);
1435 1435
 
1436
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1436
+		if (isset($full_request['statement_descriptor'])) {
1437 1437
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1438 1438
 		}
1439 1439
 
1440
-		if ( isset( $full_request['customer'] ) ) {
1440
+		if (isset($full_request['customer'])) {
1441 1441
 			$request['customer'] = $full_request['customer'];
1442 1442
 		}
1443 1443
 
1444
-		if ( isset( $full_request['source'] ) ) {
1444
+		if (isset($full_request['source'])) {
1445 1445
 			$request['source'] = $full_request['source'];
1446 1446
 		}
1447 1447
 
1448
-		$level3_data = $this->get_level3_data_from_order( $order );
1448
+		$level3_data = $this->get_level3_data_from_order($order);
1449 1449
 		$intent = WC_Stripe_API::request_with_level3_data(
1450 1450
 			$request,
1451 1451
 			'payment_intents',
1452 1452
 			$level3_data,
1453 1453
 			$order
1454 1454
 		);
1455
-		$is_authentication_required = $this->is_authentication_required_for_payment( $intent );
1455
+		$is_authentication_required = $this->is_authentication_required_for_payment($intent);
1456 1456
 
1457
-		if ( ! empty( $intent->error ) && ! $is_authentication_required ) {
1457
+		if ( ! empty($intent->error) && ! $is_authentication_required) {
1458 1458
 			return $intent;
1459 1459
 		}
1460 1460
 
1461
-		$intent_id      = ( ! empty( $intent->error )
1461
+		$intent_id = ( ! empty($intent->error)
1462 1462
 			? $intent->error->payment_intent->id
1463 1463
 			: $intent->id
1464 1464
 		);
1465
-		$payment_intent = ( ! empty( $intent->error )
1465
+		$payment_intent = ( ! empty($intent->error)
1466 1466
 			? $intent->error->payment_intent
1467 1467
 			: $intent
1468 1468
 		);
1469
-		$order_id       = $order->get_id();
1470
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent_id initiated for order $order_id" );
1469
+		$order_id = $order->get_id();
1470
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent_id initiated for order $order_id");
1471 1471
 
1472 1472
 		// Save the intent ID to the order.
1473
-		$this->save_intent_to_order( $order, $payment_intent );
1473
+		$this->save_intent_to_order($order, $payment_intent);
1474 1474
 
1475 1475
 		return $intent;
1476 1476
 	}
@@ -1481,13 +1481,13 @@  discard block
 block discarded – undo
1481 1481
 	 * Fix renewal for existing subscriptions affected by https://github.com/woocommerce/woocommerce-gateway-stripe/issues/1072.
1482 1482
 	 * @param int $order_id subscription renewal order id.
1483 1483
 	 */
1484
-	public function ensure_subscription_has_customer_id( $order_id ) {
1485
-		$subscriptions_ids = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => 'any' ) );
1486
-		foreach( $subscriptions_ids as $subscription_id => $subscription ) {
1487
-			if ( ! metadata_exists( 'post', $subscription_id, '_stripe_customer_id' ) ) {
1488
-				$stripe_customer = new WC_Stripe_Customer( $subscription->get_user_id() );
1489
-				update_post_meta( $subscription_id, '_stripe_customer_id', $stripe_customer->get_id() );
1490
-				update_post_meta( $order_id, '_stripe_customer_id', $stripe_customer->get_id() );
1484
+	public function ensure_subscription_has_customer_id($order_id) {
1485
+		$subscriptions_ids = wcs_get_subscriptions_for_order($order_id, array('order_type' => 'any'));
1486
+		foreach ($subscriptions_ids as $subscription_id => $subscription) {
1487
+			if ( ! metadata_exists('post', $subscription_id, '_stripe_customer_id')) {
1488
+				$stripe_customer = new WC_Stripe_Customer($subscription->get_user_id());
1489
+				update_post_meta($subscription_id, '_stripe_customer_id', $stripe_customer->get_id());
1490
+				update_post_meta($order_id, '_stripe_customer_id', $stripe_customer->get_id());
1491 1491
 			}
1492 1492
 		}
1493 1493
 	}
@@ -1497,7 +1497,7 @@  discard block
 block discarded – undo
1497 1497
 	 * @param string $zip The ZIP code to verify.
1498 1498
 	 * @return boolean
1499 1499
 	 */
1500
-	public function is_valid_us_zip_code( $zip ) {
1501
-		return ! empty( $zip ) && preg_match( '/^\d{5,5}(-\d{4,4})?$/', $zip );
1500
+	public function is_valid_us_zip_code($zip) {
1501
+		return ! empty($zip) && preg_match('/^\d{5,5}(-\d{4,4})?$/', $zip);
1502 1502
 	}
1503 1503
 }
Please login to merge, or discard this patch.