Completed
Pull Request — master (#1202)
by
unknown
01:56
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
 		'webhook'                       => array(
31
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
31
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
32 32
 			'type'        => 'title',
33 33
 			/* translators: webhook URL */
34 34
 			'description' => $this->display_admin_settings_webhook_description(),
35 35
 		),
36 36
 		'testmode'                      => array(
37
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
38
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
37
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
38
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
39 39
 			'type'        => 'checkbox',
40
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
40
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
41 41
 			'default'     => 'yes',
42 42
 			'desc_tip'    => true,
43 43
 		),
44 44
 		'test_publishable_key'          => array(
45
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
45
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
46 46
 			'type'        => 'text',
47
-			'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' ),
47
+			'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'),
48 48
 			'default'     => '',
49 49
 			'desc_tip'    => true,
50 50
 		),
51 51
 		'test_secret_key'               => array(
52
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
52
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
53 53
 			'type'        => 'password',
54
-			'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' ),
54
+			'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'),
55 55
 			'default'     => '',
56 56
 			'desc_tip'    => true,
57 57
 		),
58 58
 		'test_webhook_secret'           => array(
59
-			'title'       => __( 'Test Webhook Secret', 'woocommerce-gateway-stripe' ),
59
+			'title'       => __('Test Webhook Secret', 'woocommerce-gateway-stripe'),
60 60
 			'type'        => 'password',
61
-			'description' => __( 'Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe' ),
61
+			'description' => __('Get your webhook signing secret from the webhooks section in your stripe account.', 'woocommerce-gateway-stripe'),
62 62
 			'default'     => '',
63 63
 			'desc_tip'    => true,
64 64
 		),
65 65
 		'publishable_key'               => array(
66
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
66
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
67 67
 			'type'        => 'text',
68
-			'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' ),
68
+			'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'),
69 69
 			'default'     => '',
70 70
 			'desc_tip'    => true,
71 71
 		),
72 72
 		'secret_key'                    => array(
73
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
73
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
74 74
 			'type'        => 'password',
75
-			'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' ),
75
+			'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'),
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
-				'custom'  => __( 'Custom', 'woocommerce-gateway-stripe' ),
129
-				'branded' => __( 'Branded', 'woocommerce-gateway-stripe' ),
125
+				'default' => __('Default', 'woocommerce-gateway-stripe'),
126
+				'buy'     => __('Buy', 'woocommerce-gateway-stripe'),
127
+				'donate'  => __('Donate', 'woocommerce-gateway-stripe'),
128
+				'custom'  => __('Custom', 'woocommerce-gateway-stripe'),
129
+				'branded' => __('Branded', '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 Type', 'woocommerce-gateway-stripe' ),
163
-			'label'       => __( 'Branded Button Type', 'woocommerce-gateway-stripe' ),
162
+			'title'       => __('Payment Request Branded Button Type', 'woocommerce-gateway-stripe'),
163
+			'label'       => __('Branded Button Type', 'woocommerce-gateway-stripe'),
164 164
 			'type'        => 'select',
165
-			'description' => __( 'Select the type of button you would like to show.', 'woocommerce-gateway-stripe' ),
165
+			'description' => __('Select the type of button you would like to show.', 'woocommerce-gateway-stripe'),
166 166
 			'default'     => 'long',
167 167
 			'desc_tip'    => true,
168 168
 			'options'     => array(
169
-				'short' => __( 'Short', 'woocommerce-gateway-stripe' ),
170
-				'long'  => __( 'Long', 'woocommerce-gateway-stripe' ),
169
+				'short' => __('Short', 'woocommerce-gateway-stripe'),
170
+				'long'  => __('Long', '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/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +288 added lines, -288 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   4.0.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -64,41 +64,41 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		self::$_this            = $this;
67
-		$this->stripe_settings  = get_option( 'woocommerce_stripe_settings', array() );
68
-		$this->testmode         = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
69
-		$this->publishable_key  = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
70
-		$this->secret_key       = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : '';
71
-		$this->total_label      = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
67
+		$this->stripe_settings  = get_option('woocommerce_stripe_settings', array());
68
+		$this->testmode         = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
69
+		$this->publishable_key  = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
70
+		$this->secret_key       = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : '';
71
+		$this->total_label      = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
72 72
 
73
-		if ( $this->testmode ) {
74
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
75
-			$this->secret_key      = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : '';
73
+		if ($this->testmode) {
74
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
75
+			$this->secret_key      = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : '';
76 76
 		}
77 77
 
78
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
78
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
79 79
 
80 80
 		// Checks if Stripe Gateway is enabled.
81
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
81
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
82 82
 			return;
83 83
 		}
84 84
 
85 85
 		// Checks if Payment Request is enabled.
86
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
86
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
87 87
 			return;
88 88
 		}
89 89
 
90 90
 		// Don't load for change payment method page.
91
-		if ( isset( $_GET['change_payment_method'] ) ) {
91
+		if (isset($_GET['change_payment_method'])) {
92 92
 			return;
93 93
 		}
94 94
 
95
-		$wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
95
+		$wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2);
96 96
 
97
-		if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) {
97
+		if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) {
98 98
 			return;
99 99
 		}
100 100
 
101
-		add_action( 'template_redirect', array( $this, 'set_session' ) );
101
+		add_action('template_redirect', array($this, 'set_session'));
102 102
 		$this->init();
103 103
 	}
104 104
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @return array The list of countries.
110 110
 	 */
111 111
 	public function get_stripe_supported_countries() {
112
-		return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) );
112
+		return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US'));
113 113
 	}
114 114
 
115 115
 	/**
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 	public function are_keys_set() {
122 122
 		// NOTE: updates to this function should be added to are_keys_set()
123 123
 		// in includes/abstracts/abstract-wc-stripe-payment-gateway.php
124
-		if ( $this->testmode ) {
125
-			return preg_match( '/^pk_test_/', $this->publishable_key )
126
-			       && preg_match( '/^[rs]k_test_/', $this->secret_key );
124
+		if ($this->testmode) {
125
+			return preg_match('/^pk_test_/', $this->publishable_key)
126
+			       && preg_match('/^[rs]k_test_/', $this->secret_key);
127 127
 		} else {
128
-			return preg_match( '/^pk_live_/', $this->publishable_key )
129
-			       && preg_match( '/^[rs]k_live_/', $this->secret_key );
128
+			return preg_match('/^pk_live_/', $this->publishable_key)
129
+			       && preg_match('/^[rs]k_live_/', $this->secret_key);
130 130
 		}
131 131
 	}
132 132
 
@@ -147,11 +147,11 @@  discard block
 block discarded – undo
147 147
 	 * @since 4.0.0
148 148
 	 */
149 149
 	public function set_session() {
150
-		if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) {
150
+		if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) {
151 151
 			return;
152 152
 		}
153 153
 
154
-		WC()->session->set_customer_session_cookie( true );
154
+		WC()->session->set_customer_session_cookie(true);
155 155
 	}
156 156
 
157 157
 	/**
@@ -161,30 +161,30 @@  discard block
 block discarded – undo
161 161
 	 * @version 4.0.0
162 162
 	 */
163 163
 	public function init() {
164
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
164
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
165 165
 
166
-		add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
167
-		add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
166
+		add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
167
+		add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
168 168
 
169
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
170
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
169
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
170
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
171 171
 
172
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
173
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
172
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
173
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
174 174
 
175
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
176
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
177
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
178
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
179
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
180
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
181
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
182
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
175
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
176
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
177
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
178
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
179
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
180
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
181
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
182
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
183 183
 
184
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
185
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
184
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
185
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
186 186
 
187
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
187
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
188 188
 	}
189 189
 
190 190
 	/**
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @return string
196 196
 	 */
197 197
 	public function get_button_type() {
198
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
198
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
199 199
 	}
200 200
 
201 201
 	/**
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	 * @return string
207 207
 	 */
208 208
 	public function get_button_theme() {
209
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
209
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
210 210
 	}
211 211
 
212 212
 	/**
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @return string
218 218
 	 */
219 219
 	public function get_button_height() {
220
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
220
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
221 221
 	}
222 222
 
223 223
 	/**
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	 * @return string
240 240
 	 */
241 241
 	public function get_button_branded_type() {
242
-		return isset( $this->stripe_settings['payment_request_button_branded_type'] ) ? $this->stripe_settings['payment_request_button_branded_type'] : 'default';
242
+		return isset($this->stripe_settings['payment_request_button_branded_type']) ? $this->stripe_settings['payment_request_button_branded_type'] : 'default';
243 243
 	}
244 244
 
245 245
 	/**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @return string
273 273
 	 */
274 274
 	public function get_button_label() {
275
-		return isset( $this->stripe_settings['payment_request_button_label'] ) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now';
275
+		return isset($this->stripe_settings['payment_request_button_label']) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now';
276 276
 	}
277 277
 
278 278
 	/**
@@ -282,22 +282,22 @@  discard block
 block discarded – undo
282 282
 	 * @version 4.0.0
283 283
 	 */
284 284
 	public function get_product_data() {
285
-		if ( ! is_product() ) {
285
+		if ( ! is_product()) {
286 286
 			return false;
287 287
 		}
288 288
 
289 289
 		global $post;
290 290
 
291
-		$product = wc_get_product( $post->ID );
291
+		$product = wc_get_product($post->ID);
292 292
 
293
-		if ( 'variable' === $product->get_type() ) {
294
-			$attributes = wc_clean( wp_unslash( $_GET ) );
293
+		if ('variable' === $product->get_type()) {
294
+			$attributes = wc_clean(wp_unslash($_GET));
295 295
 
296
-			$data_store   = WC_Data_Store::load( 'product' );
297
-			$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
296
+			$data_store   = WC_Data_Store::load('product');
297
+			$variation_id = $data_store->find_matching_product_variation($product, $attributes);
298 298
 
299
-			if ( ! empty( $variation_id ) ) {
300
-				$product = wc_get_product( $variation_id );
299
+			if ( ! empty($variation_id)) {
300
+				$product = wc_get_product($variation_id);
301 301
 			}
302 302
 		}
303 303
 
@@ -306,27 +306,27 @@  discard block
 block discarded – undo
306 306
 
307 307
 		$items[] = array(
308 308
 			'label'  => $product->get_name(),
309
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ),
309
+			'amount' => WC_Stripe_Helper::get_stripe_amount($product->get_price()),
310 310
 		);
311 311
 
312
-		if ( wc_tax_enabled() ) {
312
+		if (wc_tax_enabled()) {
313 313
 			$items[] = array(
314
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
314
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
315 315
 				'amount'  => 0,
316 316
 				'pending' => true,
317 317
 			);
318 318
 		}
319 319
 
320
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
320
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
321 321
 			$items[] = array(
322
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
322
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
323 323
 				'amount'  => 0,
324 324
 				'pending' => true,
325 325
 			);
326 326
 
327 327
 			$data['shippingOptions'] = array(
328 328
 				'id'     => 'pending',
329
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
329
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
330 330
 				'detail' => '',
331 331
 				'amount' => 0,
332 332
 			);
@@ -334,37 +334,37 @@  discard block
 block discarded – undo
334 334
 
335 335
 		$data['displayItems'] = $items;
336 336
 		$data['total']        = array(
337
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
338
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ),
337
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
338
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($product->get_price()),
339 339
 			'pending' => true,
340 340
 		);
341 341
 
342
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
343
-		$data['currency']        = strtolower( get_woocommerce_currency() );
344
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
342
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
343
+		$data['currency']        = strtolower(get_woocommerce_currency());
344
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
345 345
 
346
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
346
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
347 347
 	}
348 348
 
349 349
 	/**
350 350
 	 * Filters the gateway title to reflect Payment Request type
351 351
 	 *
352 352
 	 */
353
-	public function filter_gateway_title( $title, $id ) {
353
+	public function filter_gateway_title($title, $id) {
354 354
 		global $post;
355 355
 
356
-		if ( ! is_object( $post ) ) {
356
+		if ( ! is_object($post)) {
357 357
 			return $title;
358 358
 		}
359 359
 
360
-		$order        = wc_get_order( $post->ID );
361
-		$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
360
+		$order        = wc_get_order($post->ID);
361
+		$method_title = is_object($order) ? $order->get_payment_method_title() : '';
362 362
 
363
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
363
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
364 364
 			return $method_title;
365 365
 		}
366 366
 
367
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
367
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
368 368
 			return $method_title;
369 369
 		}
370 370
 
@@ -377,16 +377,16 @@  discard block
 block discarded – undo
377 377
 	 * @since 3.1.4
378 378
 	 * @version 4.0.0
379 379
 	 */
380
-	public function postal_code_validation( $valid, $postcode, $country ) {
380
+	public function postal_code_validation($valid, $postcode, $country) {
381 381
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
382 382
 
383
-		if ( ! isset( $gateways['stripe'] ) ) {
383
+		if ( ! isset($gateways['stripe'])) {
384 384
 			return $valid;
385 385
 		}
386 386
 
387
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
387
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
388 388
 
389
-		if ( 'apple_pay' !== $payment_request_type ) {
389
+		if ('apple_pay' !== $payment_request_type) {
390 390
 			return $valid;
391 391
 		}
392 392
 
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
397 397
 		 * Note that this only works with shipping providers that don't validate full postal codes.
398 398
 		 */
399
-		if ( 'GB' === $country || 'CA' === $country ) {
399
+		if ('GB' === $country || 'CA' === $country) {
400 400
 			return true;
401 401
 		}
402 402
 
@@ -411,22 +411,22 @@  discard block
 block discarded – undo
411 411
 	 * @param int $order_id
412 412
 	 * @param array $posted_data The posted data from checkout form.
413 413
 	 */
414
-	public function add_order_meta( $order_id, $posted_data ) {
415
-		if ( empty( $_POST['payment_request_type'] ) ) {
414
+	public function add_order_meta($order_id, $posted_data) {
415
+		if (empty($_POST['payment_request_type'])) {
416 416
 			return;
417 417
 		}
418 418
 
419
-		$order = wc_get_order( $order_id );
419
+		$order = wc_get_order($order_id);
420 420
 
421
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
421
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
422 422
 
423
-		if ( 'apple_pay' === $payment_request_type ) {
424
-			$order->set_payment_method_title( 'Apple Pay (Stripe)' );
423
+		if ('apple_pay' === $payment_request_type) {
424
+			$order->set_payment_method_title('Apple Pay (Stripe)');
425 425
 			$order->save();
426 426
 		}
427 427
 
428
-		if ( 'payment_request_api' === $payment_request_type ) {
429
-			$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
428
+		if ('payment_request_api' === $payment_request_type) {
429
+			$order->set_payment_method_title('Chrome Payment Request (Stripe)');
430 430
 			$order->save();
431 431
 		}
432 432
 	}
@@ -464,20 +464,20 @@  discard block
 block discarded – undo
464 464
 	 * @return bool
465 465
 	 */
466 466
 	public function allowed_items_in_cart() {
467
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
468
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
467
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
468
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
469 469
 
470
-			if ( ! in_array( $_product->get_type(), $this->supported_product_types() ) ) {
470
+			if ( ! in_array($_product->get_type(), $this->supported_product_types())) {
471 471
 				return false;
472 472
 			}
473 473
 
474 474
 			// Trial subscriptions with shipping are not supported
475
-			if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) {
475
+			if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) {
476 476
 				return false;
477 477
 			}
478 478
 
479 479
 			// Pre Orders compatbility where we don't support charge upon release.
480
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) {
480
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) {
481 481
 				return false;
482 482
 			}
483 483
 		}
@@ -493,59 +493,59 @@  discard block
 block discarded – undo
493 493
 	 */
494 494
 	public function scripts() {
495 495
 		// If keys are not set bail.
496
-		if ( ! $this->are_keys_set() ) {
497
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
496
+		if ( ! $this->are_keys_set()) {
497
+			WC_Stripe_Logger::log('Keys are not set correctly.');
498 498
 			return;
499 499
 		}
500 500
 
501 501
 		// If no SSL bail.
502
-		if ( ! $this->testmode && ! is_ssl() ) {
503
-			WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' );
502
+		if ( ! $this->testmode && ! is_ssl()) {
503
+			WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.');
504 504
 			return;
505 505
 		}
506 506
 
507
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
507
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
508 508
 			return;
509 509
 		}
510 510
 
511
-		if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) {
511
+		if (is_product() && ! $this->should_show_payment_button_on_product_page()) {
512 512
 			return;
513 513
 		}
514 514
 
515
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
515
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
516 516
 
517 517
 		$stripe_params = array(
518
-			'ajax_url'        => WC_AJAX::get_endpoint( '%%endpoint%%' ),
518
+			'ajax_url'        => WC_AJAX::get_endpoint('%%endpoint%%'),
519 519
 			'stripe'          => array(
520 520
 				'key'                => $this->publishable_key,
521
-				'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
521
+				'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
522 522
 			),
523 523
 			'nonce'           => array(
524
-				'payment'                   => wp_create_nonce( 'wc-stripe-payment-request' ),
525
-				'shipping'                  => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
526
-				'update_shipping'           => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
527
-				'checkout'                  => wp_create_nonce( 'woocommerce-process_checkout' ),
528
-				'add_to_cart'               => wp_create_nonce( 'wc-stripe-add-to-cart' ),
529
-				'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
530
-				'log_errors'                => wp_create_nonce( 'wc-stripe-log-errors' ),
531
-				'clear_cart'                => wp_create_nonce( 'wc-stripe-clear-cart' ),
524
+				'payment'                   => wp_create_nonce('wc-stripe-payment-request'),
525
+				'shipping'                  => wp_create_nonce('wc-stripe-payment-request-shipping'),
526
+				'update_shipping'           => wp_create_nonce('wc-stripe-update-shipping-method'),
527
+				'checkout'                  => wp_create_nonce('woocommerce-process_checkout'),
528
+				'add_to_cart'               => wp_create_nonce('wc-stripe-add-to-cart'),
529
+				'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'),
530
+				'log_errors'                => wp_create_nonce('wc-stripe-log-errors'),
531
+				'clear_cart'                => wp_create_nonce('wc-stripe-clear-cart'),
532 532
 			),
533 533
 			'i18n'            => array(
534
-				'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
534
+				'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
535 535
 				/* translators: Do not translate the [option] placeholder */
536
-				'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
536
+				'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
537 537
 			),
538 538
 			'checkout'        => array(
539 539
 				'url'            => wc_get_checkout_url(),
540
-				'currency_code'  => strtolower( get_woocommerce_currency() ),
541
-				'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
540
+				'currency_code'  => strtolower(get_woocommerce_currency()),
541
+				'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
542 542
 				'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
543 543
 			),
544 544
 			'button'          => array(
545 545
 				'type'         => $this->get_button_type(),
546 546
 				'theme'        => $this->get_button_theme(),
547 547
 				'height'       => $this->get_button_height(),
548
-				'locale'       => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US.
548
+				'locale'       => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US.
549 549
 				'is_custom'    => $this->is_custom_button(),
550 550
 				'is_branded'   => $this->is_branded_button(),
551 551
 				'css_selector' => $this->custom_button_selector(),
@@ -555,15 +555,15 @@  discard block
 block discarded – undo
555 555
 			'product'         => $this->get_product_data(),
556 556
 		);
557 557
 
558
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
559
-		wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true );
558
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
559
+		wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true);
560 560
 
561
-		wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) );
561
+		wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params));
562 562
 
563
-		wp_enqueue_script( 'wc_stripe_payment_request' );
563
+		wp_enqueue_script('wc_stripe_payment_request');
564 564
 
565 565
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
566
-		if ( isset( $gateways['stripe'] ) ) {
566
+		if (isset($gateways['stripe'])) {
567 567
 			$gateways['stripe']->payment_scripts();
568 568
 		}
569 569
 	}
@@ -579,23 +579,23 @@  discard block
 block discarded – undo
579 579
 
580 580
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
581 581
 
582
-		if ( ! isset( $gateways['stripe'] ) ) {
582
+		if ( ! isset($gateways['stripe'])) {
583 583
 			return;
584 584
 		}
585 585
 
586
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
586
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
587 587
 			return;
588 588
 		}
589 589
 
590
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
590
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
591 591
 			return;
592 592
 		}
593 593
 
594
-		if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) {
594
+		if (is_product() && ! $this->should_show_payment_button_on_product_page()) {
595 595
 			return;
596 596
 		} else {
597
-			if ( ! $this->allowed_items_in_cart() ) {
598
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
597
+			if ( ! $this->allowed_items_in_cart()) {
598
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
599 599
 				return;
600 600
 			}
601 601
 		}
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
 		<div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;display:none;">
604 604
 			<div id="wc-stripe-payment-request-button">
605 605
 				<?php
606
-					if ( $this->is_custom_button() ) {
607
-						$label = esc_html( $this->get_button_label() );
608
-						$class_name = esc_attr( 'button ' .  $this->get_button_theme() );
609
-						$style = esc_attr( 'height:' . $this->get_button_height() . 'px;' );
606
+					if ($this->is_custom_button()) {
607
+						$label = esc_html($this->get_button_label());
608
+						$class_name = esc_attr('button ' . $this->get_button_theme());
609
+						$style = esc_attr('height:' . $this->get_button_height() . 'px;');
610 610
 						echo "<button id=\"wc-stripe-custom-button\" class=\"$class_name\" style=\"$style\"> $label </button>";
611 611
 					}
612 612
 				?>
@@ -627,28 +627,28 @@  discard block
 block discarded – undo
627 627
 
628 628
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
629 629
 
630
-		if ( ! isset( $gateways['stripe'] ) ) {
630
+		if ( ! isset($gateways['stripe'])) {
631 631
 			return;
632 632
 		}
633 633
 
634
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
634
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
635 635
 			return;
636 636
 		}
637 637
 
638
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
638
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
639 639
 			return;
640 640
 		}
641 641
 
642
-		if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) {
642
+		if (is_product() && ! $this->should_show_payment_button_on_product_page()) {
643 643
 			return;
644 644
 		} else {
645
-			if ( ! $this->allowed_items_in_cart() ) {
646
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
645
+			if ( ! $this->allowed_items_in_cart()) {
646
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
647 647
 				return;
648 648
 			}
649 649
 		}
650 650
 		?>
651
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> &mdash;</p>
651
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> &mdash;</p>
652 652
 		<?php
653 653
 	}
654 654
 
@@ -664,32 +664,32 @@  discard block
 block discarded – undo
664 664
 	private function should_show_payment_button_on_product_page() {
665 665
 		global $post;
666 666
 
667
-		$product = wc_get_product( $post->ID );
667
+		$product = wc_get_product($post->ID);
668 668
 
669
-		if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
669
+		if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
670 670
 			return false;
671 671
 		}
672 672
 
673
-		if ( ! is_object( $product ) || ! in_array( $product->get_type(), $this->supported_product_types() ) ) {
673
+		if ( ! is_object($product) || ! in_array($product->get_type(), $this->supported_product_types())) {
674 674
 			return false;
675 675
 		}
676 676
 
677 677
 		// Trial subscriptions with shipping are not supported
678
-		if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) {
678
+		if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) {
679 679
 			return false;
680 680
 		}
681 681
 
682 682
 		// Pre Orders charge upon release not supported.
683
-		if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
684
-			WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
683
+		if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
684
+			WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
685 685
 			return false;
686 686
 		}
687 687
 
688 688
 		// File upload addon not supported
689
-		if ( class_exists( 'WC_Product_Addons_Helper' ) ) {
690
-			$product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() );
691
-			foreach ( $product_addons as $addon ) {
692
-				if ( 'file_upload' === $addon['type'] ) {
689
+		if (class_exists('WC_Product_Addons_Helper')) {
690
+			$product_addons = WC_Product_Addons_Helper::get_product_addons($product->get_id());
691
+			foreach ($product_addons as $addon) {
692
+				if ('file_upload' === $addon['type']) {
693 693
 					return false;
694 694
 				}
695 695
 			}
@@ -705,11 +705,11 @@  discard block
 block discarded – undo
705 705
 	 * @version 4.0.0
706 706
 	 */
707 707
 	public function ajax_log_errors() {
708
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
708
+		check_ajax_referer('wc-stripe-log-errors', 'security');
709 709
 
710
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
710
+		$errors = wc_clean(stripslashes($_POST['errors']));
711 711
 
712
-		WC_Stripe_Logger::log( $errors );
712
+		WC_Stripe_Logger::log($errors);
713 713
 
714 714
 		exit;
715 715
 	}
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 	 * @version 4.0.0
722 722
 	 */
723 723
 	public function ajax_clear_cart() {
724
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
724
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
725 725
 
726 726
 		WC()->cart->empty_cart();
727 727
 		exit;
@@ -731,10 +731,10 @@  discard block
 block discarded – undo
731 731
 	 * Get cart details.
732 732
 	 */
733 733
 	public function ajax_get_cart_details() {
734
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
734
+		check_ajax_referer('wc-stripe-payment-request', 'security');
735 735
 
736
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
737
-			define( 'WOOCOMMERCE_CART', true );
736
+		if ( ! defined('WOOCOMMERCE_CART')) {
737
+			define('WOOCOMMERCE_CART', true);
738 738
 		}
739 739
 
740 740
 		WC()->cart->calculate_totals();
@@ -745,14 +745,14 @@  discard block
 block discarded – undo
745 745
 		$data = array(
746 746
 			'shipping_required' => WC()->cart->needs_shipping(),
747 747
 			'order_data'        => array(
748
-				'currency'     => strtolower( $currency ),
749
-				'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
748
+				'currency'     => strtolower($currency),
749
+				'country_code' => substr(get_option('woocommerce_default_country'), 0, 2),
750 750
 			),
751 751
 		);
752 752
 
753 753
 		$data['order_data'] += $this->build_display_items();
754 754
 
755
-		wp_send_json( $data );
755
+		wp_send_json($data);
756 756
 	}
757 757
 
758 758
 	/**
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 	 * @see WC_Shipping::get_packages().
764 764
 	 */
765 765
 	public function ajax_get_shipping_options() {
766
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
766
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
767 767
 
768 768
 		try {
769 769
 			// Set the shipping package.
@@ -779,34 +779,34 @@  discard block
 block discarded – undo
779 779
 				)
780 780
 			);
781 781
 
782
-			$this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) );
782
+			$this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted));
783 783
 
784 784
 			// Set the shipping options.
785 785
 			$data     = array();
786 786
 			$packages = WC()->shipping->get_packages();
787 787
 
788
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
789
-				foreach ( $packages as $package_key => $package ) {
790
-					if ( empty( $package['rates'] ) ) {
791
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
788
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
789
+				foreach ($packages as $package_key => $package) {
790
+					if (empty($package['rates'])) {
791
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
792 792
 					}
793 793
 
794
-					foreach ( $package['rates'] as $key => $rate ) {
794
+					foreach ($package['rates'] as $key => $rate) {
795 795
 						$data['shipping_options'][] = array(
796 796
 							'id'     => $rate->id,
797 797
 							'label'  => $rate->label,
798 798
 							'detail' => '',
799
-							'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
799
+							'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost),
800 800
 						);
801 801
 					}
802 802
 				}
803 803
 			} else {
804
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
804
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
805 805
 			}
806 806
 
807
-			if ( isset( $data[0] ) ) {
807
+			if (isset($data[0])) {
808 808
 				// Auto select the first shipping method.
809
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
809
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
810 810
 			}
811 811
 
812 812
 			WC()->cart->calculate_totals();
@@ -814,12 +814,12 @@  discard block
 block discarded – undo
814 814
 			$data          += $this->build_display_items();
815 815
 			$data['result'] = 'success';
816 816
 
817
-			wp_send_json( $data );
818
-		} catch ( Exception $e ) {
817
+			wp_send_json($data);
818
+		} catch (Exception $e) {
819 819
 			$data          += $this->build_display_items();
820 820
 			$data['result'] = 'invalid_shipping_address';
821 821
 
822
-			wp_send_json( $data );
822
+			wp_send_json($data);
823 823
 		}
824 824
 	}
825 825
 
@@ -827,22 +827,22 @@  discard block
 block discarded – undo
827 827
 	 * Update shipping method.
828 828
 	 */
829 829
 	public function ajax_update_shipping_method() {
830
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
830
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
831 831
 
832
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
833
-			define( 'WOOCOMMERCE_CART', true );
832
+		if ( ! defined('WOOCOMMERCE_CART')) {
833
+			define('WOOCOMMERCE_CART', true);
834 834
 		}
835 835
 
836
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
837
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
836
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
837
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
838 838
 
839
-		if ( is_array( $shipping_method ) ) {
840
-			foreach ( $shipping_method as $i => $value ) {
841
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
839
+		if (is_array($shipping_method)) {
840
+			foreach ($shipping_method as $i => $value) {
841
+				$chosen_shipping_methods[$i] = wc_clean($value);
842 842
 			}
843 843
 		}
844 844
 
845
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
845
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
846 846
 
847 847
 		WC()->cart->calculate_totals();
848 848
 
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 		$data          += $this->build_display_items();
851 851
 		$data['result'] = 'success';
852 852
 
853
-		wp_send_json( $data );
853
+		wp_send_json($data);
854 854
 	}
855 855
 
856 856
 	/**
@@ -861,38 +861,38 @@  discard block
 block discarded – undo
861 861
 	 * @return array $data
862 862
 	 */
863 863
 	public function ajax_get_selected_product_data() {
864
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
864
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
865 865
 
866 866
 		try {
867
-			$product_id   = absint( $_POST['product_id'] );
868
-			$qty          = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id );
869
-			$addon_value  = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0;
870
-			$product      = wc_get_product( $product_id );
867
+			$product_id   = absint($_POST['product_id']);
868
+			$qty          = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id);
869
+			$addon_value  = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0;
870
+			$product      = wc_get_product($product_id);
871 871
 			$variation_id = null;
872 872
 
873
-			if ( ! is_a( $product, 'WC_Product' ) ) {
874
-				throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) );
873
+			if ( ! is_a($product, 'WC_Product')) {
874
+				throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id));
875 875
 			}
876 876
 
877
-			if ( 'variable' === $product->get_type() && isset( $_POST['attributes'] ) ) {
878
-				$attributes = wc_clean( wp_unslash( $_POST['attributes'] ) );
877
+			if ('variable' === $product->get_type() && isset($_POST['attributes'])) {
878
+				$attributes = wc_clean(wp_unslash($_POST['attributes']));
879 879
 
880
-				$data_store   = WC_Data_Store::load( 'product' );
881
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
880
+				$data_store   = WC_Data_Store::load('product');
881
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
882 882
 
883
-				if ( ! empty( $variation_id ) ) {
884
-					$product = wc_get_product( $variation_id );
883
+				if ( ! empty($variation_id)) {
884
+					$product = wc_get_product($variation_id);
885 885
 				}
886 886
 			}
887 887
 
888 888
 			// Force quantity to 1 if sold individually and check for existing item in cart.
889
-			if ( $product->is_sold_individually() ) {
890
-				$qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id );
889
+			if ($product->is_sold_individually()) {
890
+				$qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id);
891 891
 			}
892 892
 
893
-			if ( ! $product->has_enough_stock( $qty ) ) {
893
+			if ( ! $product->has_enough_stock($qty)) {
894 894
 				/* translators: 1: product name 2: quantity in stock */
895
-				throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) );
895
+				throw new Exception(sprintf(__('You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe'), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity(), $product)));
896 896
 			}
897 897
 
898 898
 			$total = $qty * $product->get_price() + $addon_value;
@@ -904,27 +904,27 @@  discard block
 block discarded – undo
904 904
 
905 905
 			$items[] = array(
906 906
 				'label'  => $product->get_name() . $quantity_label,
907
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
907
+				'amount' => WC_Stripe_Helper::get_stripe_amount($total),
908 908
 			);
909 909
 
910
-			if ( wc_tax_enabled() ) {
910
+			if (wc_tax_enabled()) {
911 911
 				$items[] = array(
912
-					'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
912
+					'label'   => __('Tax', 'woocommerce-gateway-stripe'),
913 913
 					'amount'  => 0,
914 914
 					'pending' => true,
915 915
 				);
916 916
 			}
917 917
 
918
-			if ( wc_shipping_enabled() && $product->needs_shipping() ) {
918
+			if (wc_shipping_enabled() && $product->needs_shipping()) {
919 919
 				$items[] = array(
920
-					'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
920
+					'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
921 921
 					'amount'  => 0,
922 922
 					'pending' => true,
923 923
 				);
924 924
 
925 925
 				$data['shippingOptions'] = array(
926 926
 					'id'     => 'pending',
927
-					'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
927
+					'label'  => __('Pending', 'woocommerce-gateway-stripe'),
928 928
 					'detail' => '',
929 929
 					'amount' => 0,
930 930
 				);
@@ -933,17 +933,17 @@  discard block
 block discarded – undo
933 933
 			$data['displayItems'] = $items;
934 934
 			$data['total']        = array(
935 935
 				'label'   => $this->total_label,
936
-				'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
936
+				'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
937 937
 				'pending' => true,
938 938
 			);
939 939
 
940
-			$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
941
-			$data['currency']        = strtolower( get_woocommerce_currency() );
942
-			$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
940
+			$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
941
+			$data['currency']        = strtolower(get_woocommerce_currency());
942
+			$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
943 943
 
944
-			wp_send_json( $data );
945
-		} catch ( Exception $e ) {
946
-			wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) );
944
+			wp_send_json($data);
945
+		} catch (Exception $e) {
946
+			wp_send_json(array('error' => wp_strip_all_tags($e->getMessage())));
947 947
 		}
948 948
 	}
949 949
 
@@ -955,33 +955,33 @@  discard block
 block discarded – undo
955 955
 	 * @return array $data
956 956
 	 */
957 957
 	public function ajax_add_to_cart() {
958
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
958
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
959 959
 
960
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
961
-			define( 'WOOCOMMERCE_CART', true );
960
+		if ( ! defined('WOOCOMMERCE_CART')) {
961
+			define('WOOCOMMERCE_CART', true);
962 962
 		}
963 963
 
964 964
 		WC()->shipping->reset_shipping();
965 965
 
966
-		$product_id   = absint( $_POST['product_id'] );
967
-		$qty          = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
968
-		$product      = wc_get_product( $product_id );
966
+		$product_id   = absint($_POST['product_id']);
967
+		$qty          = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
968
+		$product      = wc_get_product($product_id);
969 969
 		$product_type = $product->get_type();
970 970
 
971 971
 		// First empty the cart to prevent wrong calculation.
972 972
 		WC()->cart->empty_cart();
973 973
 
974
-		if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {
975
-			$attributes = wc_clean( wp_unslash( $_POST['attributes'] ) );
974
+		if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) {
975
+			$attributes = wc_clean(wp_unslash($_POST['attributes']));
976 976
 
977
-			$data_store   = WC_Data_Store::load( 'product' );
978
-			$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
977
+			$data_store   = WC_Data_Store::load('product');
978
+			$variation_id = $data_store->find_matching_product_variation($product, $attributes);
979 979
 
980
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
980
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
981 981
 		}
982 982
 
983
-		if ( 'simple' === $product_type || 'subscription' === $product_type ) {
984
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
983
+		if ('simple' === $product_type || 'subscription' === $product_type) {
984
+			WC()->cart->add_to_cart($product->get_id(), $qty);
985 985
 		}
986 986
 
987 987
 		WC()->cart->calculate_totals();
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
 		$data          += $this->build_display_items();
991 991
 		$data['result'] = 'success';
992 992
 
993
-		wp_send_json( $data );
993
+		wp_send_json($data);
994 994
 	}
995 995
 
996 996
 	/**
@@ -1003,31 +1003,31 @@  discard block
 block discarded – undo
1003 1003
 	 * @version 4.0.0
1004 1004
 	 */
1005 1005
 	public function normalize_state() {
1006
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
1007
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
1008
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
1009
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
1006
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
1007
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
1008
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
1009
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
1010 1010
 
1011
-		if ( $billing_state && $billing_country ) {
1012
-			$valid_states = WC()->countries->get_states( $billing_country );
1011
+		if ($billing_state && $billing_country) {
1012
+			$valid_states = WC()->countries->get_states($billing_country);
1013 1013
 
1014 1014
 			// Valid states found for country.
1015
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
1016
-				foreach ( $valid_states as $state_abbr => $state ) {
1017
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
1015
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
1016
+				foreach ($valid_states as $state_abbr => $state) {
1017
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
1018 1018
 						$_POST['billing_state'] = $state_abbr;
1019 1019
 					}
1020 1020
 				}
1021 1021
 			}
1022 1022
 		}
1023 1023
 
1024
-		if ( $shipping_state && $shipping_country ) {
1025
-			$valid_states = WC()->countries->get_states( $shipping_country );
1024
+		if ($shipping_state && $shipping_country) {
1025
+			$valid_states = WC()->countries->get_states($shipping_country);
1026 1026
 
1027 1027
 			// Valid states found for country.
1028
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
1029
-				foreach ( $valid_states as $state_abbr => $state ) {
1030
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
1028
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
1029
+				foreach ($valid_states as $state_abbr => $state) {
1030
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
1031 1031
 						$_POST['shipping_state'] = $state_abbr;
1032 1032
 					}
1033 1033
 				}
@@ -1042,19 +1042,19 @@  discard block
 block discarded – undo
1042 1042
 	 * @version 4.0.0
1043 1043
 	 */
1044 1044
 	public function ajax_create_order() {
1045
-		if ( WC()->cart->is_empty() ) {
1046
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
1045
+		if (WC()->cart->is_empty()) {
1046
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
1047 1047
 		}
1048 1048
 
1049
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
1050
-			define( 'WOOCOMMERCE_CHECKOUT', true );
1049
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
1050
+			define('WOOCOMMERCE_CHECKOUT', true);
1051 1051
 		}
1052 1052
 
1053 1053
 		$this->normalize_state();
1054 1054
 
1055 1055
 		WC()->checkout()->process_checkout();
1056 1056
 
1057
-		die( 0 );
1057
+		die(0);
1058 1058
 	}
1059 1059
 
1060 1060
 	/**
@@ -1064,38 +1064,38 @@  discard block
 block discarded – undo
1064 1064
 	 * @version 4.0.0
1065 1065
 	 * @param array $address
1066 1066
 	 */
1067
-	protected function calculate_shipping( $address = array() ) {
1067
+	protected function calculate_shipping($address = array()) {
1068 1068
 		$country   = $address['country'];
1069 1069
 		$state     = $address['state'];
1070 1070
 		$postcode  = $address['postcode'];
1071 1071
 		$city      = $address['city'];
1072 1072
 		$address_1 = $address['address'];
1073 1073
 		$address_2 = $address['address_2'];
1074
-		$wc_states = WC()->countries->get_states( $country );
1074
+		$wc_states = WC()->countries->get_states($country);
1075 1075
 
1076 1076
 		/**
1077 1077
 		 * In some versions of Chrome, state can be a full name. So we need
1078 1078
 		 * to convert that to abbreviation as WC is expecting that.
1079 1079
 		 */
1080
-		if ( 2 < strlen( $state ) && ! empty( $wc_states ) ) {
1081
-			$state = array_search( ucwords( strtolower( $state ) ), $wc_states, true );
1080
+		if (2 < strlen($state) && ! empty($wc_states)) {
1081
+			$state = array_search(ucwords(strtolower($state)), $wc_states, true);
1082 1082
 		}
1083 1083
 
1084 1084
 		WC()->shipping->reset_shipping();
1085 1085
 
1086
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
1087
-			$postcode = wc_format_postcode( $postcode, $country );
1086
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
1087
+			$postcode = wc_format_postcode($postcode, $country);
1088 1088
 		}
1089 1089
 
1090
-		if ( $country ) {
1091
-			WC()->customer->set_location( $country, $state, $postcode, $city );
1092
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
1090
+		if ($country) {
1091
+			WC()->customer->set_location($country, $state, $postcode, $city);
1092
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
1093 1093
 		} else {
1094 1094
 			WC()->customer->set_billing_address_to_base();
1095 1095
 			WC()->customer->set_shipping_address_to_base();
1096 1096
 		}
1097 1097
 
1098
-		WC()->customer->set_calculated_shipping( true );
1098
+		WC()->customer->set_calculated_shipping(true);
1099 1099
 		WC()->customer->save();
1100 1100
 
1101 1101
 		$packages = array();
@@ -1111,17 +1111,17 @@  discard block
 block discarded – undo
1111 1111
 		$packages[0]['destination']['address']   = $address_1;
1112 1112
 		$packages[0]['destination']['address_2'] = $address_2;
1113 1113
 
1114
-		foreach ( WC()->cart->get_cart() as $item ) {
1115
-			if ( $item['data']->needs_shipping() ) {
1116
-				if ( isset( $item['line_total'] ) ) {
1114
+		foreach (WC()->cart->get_cart() as $item) {
1115
+			if ($item['data']->needs_shipping()) {
1116
+				if (isset($item['line_total'])) {
1117 1117
 					$packages[0]['contents_cost'] += $item['line_total'];
1118 1118
 				}
1119 1119
 			}
1120 1120
 		}
1121 1121
 
1122
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1122
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1123 1123
 
1124
-		WC()->shipping->calculate_shipping( $packages );
1124
+		WC()->shipping->calculate_shipping($packages);
1125 1125
 	}
1126 1126
 
1127 1127
 	/**
@@ -1130,19 +1130,19 @@  discard block
 block discarded – undo
1130 1130
 	 * @since 3.1.0
1131 1131
 	 * @version 4.0.0
1132 1132
 	 */
1133
-	protected function build_shipping_methods( $shipping_methods ) {
1134
-		if ( empty( $shipping_methods ) ) {
1133
+	protected function build_shipping_methods($shipping_methods) {
1134
+		if (empty($shipping_methods)) {
1135 1135
 			return array();
1136 1136
 		}
1137 1137
 
1138 1138
 		$shipping = array();
1139 1139
 
1140
-		foreach ( $shipping_methods as $method ) {
1140
+		foreach ($shipping_methods as $method) {
1141 1141
 			$shipping[] = array(
1142 1142
 				'id'     => $method['id'],
1143 1143
 				'label'  => $method['label'],
1144 1144
 				'detail' => '',
1145
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1145
+				'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1146 1146
 			);
1147 1147
 		}
1148 1148
 
@@ -1156,8 +1156,8 @@  discard block
 block discarded – undo
1156 1156
 	 * @version 4.0.0
1157 1157
 	 */
1158 1158
 	protected function build_display_items() {
1159
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1160
-			define( 'WOOCOMMERCE_CART', true );
1159
+		if ( ! defined('WOOCOMMERCE_CART')) {
1160
+			define('WOOCOMMERCE_CART', true);
1161 1161
 		}
1162 1162
 
1163 1163
 		$items     = array();
@@ -1165,8 +1165,8 @@  discard block
 block discarded – undo
1165 1165
 		$discounts = 0;
1166 1166
 
1167 1167
 		// Default show only subtotal instead of itemization.
1168
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1169
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1168
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1169
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1170 1170
 				$amount         = $cart_item['line_subtotal'];
1171 1171
 				$subtotal      += $cart_item['line_subtotal'];
1172 1172
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
@@ -1175,61 +1175,61 @@  discard block
 block discarded – undo
1175 1175
 
1176 1176
 				$item = array(
1177 1177
 					'label'  => $product_name . $quantity_label,
1178
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1178
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1179 1179
 				);
1180 1180
 
1181 1181
 				$items[] = $item;
1182 1182
 			}
1183 1183
 		}
1184 1184
 
1185
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1186
-			$discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1185
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1186
+			$discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1187 1187
 		} else {
1188
-			$applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() );
1188
+			$applied_coupons = array_values(WC()->cart->get_coupon_discount_totals());
1189 1189
 
1190
-			foreach ( $applied_coupons as $amount ) {
1190
+			foreach ($applied_coupons as $amount) {
1191 1191
 				$discounts += (float) $amount;
1192 1192
 			}
1193 1193
 		}
1194 1194
 
1195
-		$discounts   = wc_format_decimal( $discounts, WC()->cart->dp );
1196
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1197
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1198
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1199
-		$order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false );
1195
+		$discounts   = wc_format_decimal($discounts, WC()->cart->dp);
1196
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1197
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1198
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1199
+		$order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false);
1200 1200
 
1201
-		if ( wc_tax_enabled() ) {
1201
+		if (wc_tax_enabled()) {
1202 1202
 			$items[] = array(
1203
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1204
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1203
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1204
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1205 1205
 			);
1206 1206
 		}
1207 1207
 
1208
-		if ( WC()->cart->needs_shipping() ) {
1208
+		if (WC()->cart->needs_shipping()) {
1209 1209
 			$items[] = array(
1210
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1211
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1210
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1211
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1212 1212
 			);
1213 1213
 		}
1214 1214
 
1215
-		if ( WC()->cart->has_discount() ) {
1215
+		if (WC()->cart->has_discount()) {
1216 1216
 			$items[] = array(
1217
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1218
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1217
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1218
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1219 1219
 			);
1220 1220
 		}
1221 1221
 
1222
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1222
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1223 1223
 			$cart_fees = WC()->cart->fees;
1224 1224
 		} else {
1225 1225
 			$cart_fees = WC()->cart->get_fees();
1226 1226
 		}
1227 1227
 
1228 1228
 		// Include fees and taxes as display items.
1229
-		foreach ( $cart_fees as $key => $fee ) {
1229
+		foreach ($cart_fees as $key => $fee) {
1230 1230
 			$items[] = array(
1231 1231
 				'label'  => $fee->name,
1232
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1232
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1233 1233
 			);
1234 1234
 		}
1235 1235
 
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
 			'displayItems' => $items,
1238 1238
 			'total'        => array(
1239 1239
 				'label'   => $this->total_label,
1240
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1240
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1241 1241
 				'pending' => false,
1242 1242
 			),
1243 1243
 		);
Please login to merge, or discard this patch.