Completed
Push — master ( e0634c...a8a1a1 )
by Roy
02:22
created
includes/settings-stripe.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -1,149 +1,149 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-return apply_filters( 'wc_stripe_settings',
6
+return apply_filters('wc_stripe_settings',
7 7
 	array(
8 8
 		'enabled' => array(
9
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
10
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
9
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
10
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
11 11
 			'type'        => 'checkbox',
12 12
 			'description' => '',
13 13
 			'default'     => 'no',
14 14
 		),
15 15
 		'title' => array(
16
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
16
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
17 17
 			'type'        => 'text',
18
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
19
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
18
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
19
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
20 20
 			'desc_tip'    => true,
21 21
 		),
22 22
 		'description' => array(
23
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
23
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
24 24
 			'type'        => 'text',
25
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
26
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
25
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
26
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
27 27
 			'desc_tip'    => true,
28 28
 		),
29 29
 		'testmode' => array(
30
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
31
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
30
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
31
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
32 32
 			'type'        => 'checkbox',
33
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
33
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
34 34
 			'default'     => 'yes',
35 35
 			'desc_tip'    => true,
36 36
 		),
37 37
 		'test_secret_key' => array(
38
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
38
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
39 39
 			'type'        => 'text',
40
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
40
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
41 41
 			'default'     => '',
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.', 'woocommerce-gateway-stripe' ),
47
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
48 48
 			'default'     => '',
49 49
 			'desc_tip'    => true,
50 50
 		),
51 51
 		'secret_key' => array(
52
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
52
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
53 53
 			'type'        => 'text',
54
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
54
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
55 55
 			'default'     => '',
56 56
 			'desc_tip'    => true,
57 57
 		),
58 58
 		'publishable_key' => array(
59
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
59
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
60 60
 			'type'        => 'text',
61
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
61
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
62 62
 			'default'     => '',
63 63
 			'desc_tip'    => true,
64 64
 		),
65 65
 		'statement_descriptor' => array(
66
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
66
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
67 67
 			'type'        => 'text',
68
-			'description' => __( 'Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe' ),
68
+			'description' => __('Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe'),
69 69
 			'default'     => '',
70 70
 			'desc_tip'    => true,
71 71
 		),
72 72
 		'capture' => array(
73
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
74
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
73
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
74
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
75 75
 			'type'        => 'checkbox',
76
-			'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' ),
76
+			'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'),
77 77
 			'default'     => 'yes',
78 78
 			'desc_tip'    => true,
79 79
 		),
80 80
 		'stripe_checkout' => array(
81
-			'title'       => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ),
82
-			'label'       => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ),
81
+			'title'       => __('Stripe Checkout', 'woocommerce-gateway-stripe'),
82
+			'label'       => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'),
83 83
 			'type'        => 'checkbox',
84
-			'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ),
84
+			'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'),
85 85
 			'default'     => 'no',
86 86
 			'desc_tip'    => true,
87 87
 		),
88 88
 		'allow_remember_me' => array(
89
-			'title'       => __( 'Allow Remember Me', 'woocommerce-gateway-stripe' ),
90
-			'label'       => __( 'Enable Remember Me', 'woocommerce-gateway-stripe' ),
89
+			'title'       => __('Allow Remember Me', 'woocommerce-gateway-stripe'),
90
+			'label'       => __('Enable Remember Me', 'woocommerce-gateway-stripe'),
91 91
 			'type'        => 'checkbox',
92
-			'description' => __( 'If enabled, this option shows a "Remember Me" checkbox which when checked by the customer will persist their details.', 'woocommerce-gateway-stripe' ),
92
+			'description' => __('If enabled, this option shows a "Remember Me" checkbox which when checked by the customer will persist their details.', 'woocommerce-gateway-stripe'),
93 93
 			'default'     => 'yes',
94 94
 			'desc_tip'    => true,
95 95
 		),
96 96
 		'stripe_checkout_locale' => array(
97
-			'title'       => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ),
97
+			'title'       => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'),
98 98
 			'type'        => 'select',
99 99
 			'class'       => 'wc-enhanced-select',
100
-			'description' => __( 'Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe' ),
100
+			'description' => __('Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe'),
101 101
 			'default'     => 'en',
102 102
 			'desc_tip'    => true,
103 103
 			'options'     => array(
104
-				'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ),
105
-				'zh'   => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ),
106
-				'da'   => __( 'Danish', 'woocommerce-gateway-stripe' ),
107
-				'nl'   => __( 'Dutch', 'woocommerce-gateway-stripe' ),
108
-				'en'   => __( 'English', 'woocommerce-gateway-stripe' ),
109
-				'fi'   => __( 'Finnish', 'woocommerce-gateway-stripe' ),
110
-				'fr'   => __( 'French', 'woocommerce-gateway-stripe' ),
111
-				'de'   => __( 'German', 'woocommerce-gateway-stripe' ),
112
-				'it'   => __( 'Italian', 'woocommerce-gateway-stripe' ),
113
-				'ja'   => __( 'Japanese', 'woocommerce-gateway-stripe' ),
114
-				'no'   => __( 'Norwegian', 'woocommerce-gateway-stripe' ),
115
-				'es'   => __( 'Spanish', 'woocommerce-gateway-stripe' ),
116
-				'sv'   => __( 'Swedish', 'woocommerce-gateway-stripe' ),
104
+				'auto' => __('Auto', 'woocommerce-gateway-stripe'),
105
+				'zh'   => __('Simplified Chinese', 'woocommerce-gateway-stripe'),
106
+				'da'   => __('Danish', 'woocommerce-gateway-stripe'),
107
+				'nl'   => __('Dutch', 'woocommerce-gateway-stripe'),
108
+				'en'   => __('English', 'woocommerce-gateway-stripe'),
109
+				'fi'   => __('Finnish', 'woocommerce-gateway-stripe'),
110
+				'fr'   => __('French', 'woocommerce-gateway-stripe'),
111
+				'de'   => __('German', 'woocommerce-gateway-stripe'),
112
+				'it'   => __('Italian', 'woocommerce-gateway-stripe'),
113
+				'ja'   => __('Japanese', 'woocommerce-gateway-stripe'),
114
+				'no'   => __('Norwegian', 'woocommerce-gateway-stripe'),
115
+				'es'   => __('Spanish', 'woocommerce-gateway-stripe'),
116
+				'sv'   => __('Swedish', 'woocommerce-gateway-stripe'),
117 117
 			),
118 118
 		),
119 119
 		'stripe_bitcoin' => array(
120
-			'title'       => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ),
121
-			'label'       => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ),
120
+			'title'       => __('Bitcoin Currency', 'woocommerce-gateway-stripe'),
121
+			'label'       => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'),
122 122
 			'type'        => 'checkbox',
123
-			'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ),
123
+			'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'),
124 124
 			'default'     => 'no',
125 125
 			'desc_tip'    => true,
126 126
 		),
127 127
 		'stripe_checkout_image' => array(
128
-			'title'       => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ),
129
-			'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ),
128
+			'title'       => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'),
129
+			'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'),
130 130
 			'type'        => 'text',
131 131
 			'default'     => '',
132 132
 			'desc_tip'    => true,
133 133
 		),
134 134
 		'request_payment_api' => array(
135
-			'title'       => __( 'Payment Request API', 'woocommerce-gateway-stripe' ),
136
-			'label'       => __( 'Enable Payment Request API', 'woocommerce-gateway-stripe' ),
135
+			'title'       => __('Payment Request API', 'woocommerce-gateway-stripe'),
136
+			'label'       => __('Enable Payment Request API', 'woocommerce-gateway-stripe'),
137 137
 			'type'        => 'checkbox',
138
-			'description' => __( 'If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe' ),
138
+			'description' => __('If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe'),
139 139
 			'default'     => 'no',
140 140
 			'desc_tip'    => true,
141 141
 		),
142 142
 		'apple_pay' => array(
143
-			'title'       => __( 'Apple Pay', 'woocommerce-gateway-stripe' ),
144
-			'label'       => sprintf( __( 'Enable Apple Pay. %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>' ),
143
+			'title'       => __('Apple Pay', 'woocommerce-gateway-stripe'),
144
+			'label'       => sprintf(__('Enable Apple Pay. %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>'),
145 145
 			'type'        => 'checkbox',
146
-			'description' => __( 'If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe' ),
146
+			'description' => __('If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe'),
147 147
 			'default'     => 'no',
148 148
 			'desc_tip'    => true,
149 149
 		),
@@ -151,37 +151,37 @@  discard block
 block discarded – undo
151 151
 			'type'        => 'apple_pay_domain',
152 152
 		),
153 153
 		'apple_pay_button' => array(
154
-			'title'       => __( 'Apple Pay Button Style', 'woocommerce-gateway-stripe' ),
155
-			'label'       => __( 'Button Style', 'woocommerce-gateway-stripe' ),
154
+			'title'       => __('Apple Pay Button Style', 'woocommerce-gateway-stripe'),
155
+			'label'       => __('Button Style', 'woocommerce-gateway-stripe'),
156 156
 			'type'        => 'select',
157
-			'description' => __( 'Select the button style you would like to show.', 'woocommerce-gateway-stripe' ),
157
+			'description' => __('Select the button style you would like to show.', 'woocommerce-gateway-stripe'),
158 158
 			'default'     => 'black',
159 159
 			'desc_tip'    => true,
160 160
 			'options'     => array(
161
-				'black' => __( 'Black', 'woocommerce-gateway-stripe' ),
162
-				'white' => __( 'White', 'woocommerce-gateway-stripe' ),
161
+				'black' => __('Black', 'woocommerce-gateway-stripe'),
162
+				'white' => __('White', 'woocommerce-gateway-stripe'),
163 163
 			),
164 164
 		),
165 165
 		'apple_pay_button_lang' => array(
166
-			'title'       => __( 'Apple Pay Button Language', 'woocommerce-gateway-stripe' ),
167
-			'description' => __( 'Enter the 2 letter ISO code for the language you would like your Apple Pay Button to display in. Reference available ISO codes here <code>http://www.w3schools.com/tags/ref_language_codes.asp</code>', 'woocommerce-gateway-stripe' ),
166
+			'title'       => __('Apple Pay Button Language', 'woocommerce-gateway-stripe'),
167
+			'description' => __('Enter the 2 letter ISO code for the language you would like your Apple Pay Button to display in. Reference available ISO codes here <code>http://www.w3schools.com/tags/ref_language_codes.asp</code>', 'woocommerce-gateway-stripe'),
168 168
 			'type'        => 'text',
169 169
 			'default'     => 'en',
170 170
 			'desc_tip'    => false,
171 171
 		),
172 172
 		'saved_cards' => array(
173
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
174
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
173
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
174
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
175 175
 			'type'        => 'checkbox',
176
-			'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' ),
176
+			'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 177
 			'default'     => 'no',
178 178
 			'desc_tip'    => true,
179 179
 		),
180 180
 		'logging' => array(
181
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
182
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
181
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
182
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
183 183
 			'type'        => 'checkbox',
184
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
184
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
185 185
 			'default'     => 'no',
186 186
 			'desc_tip'    => true,
187 187
 		),
Please login to merge, or discard this patch.
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +249 added lines, -249 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
 
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	public function __construct() {
122 122
 		$this->id                   = 'stripe';
123
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
124
-		$this->method_description   = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' );
123
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
124
+		$this->method_description   = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe');
125 125
 		$this->has_fields           = true;
126 126
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
127 127
 		$this->supports             = array(
@@ -149,41 +149,41 @@  discard block
 block discarded – undo
149 149
 		$this->init_settings();
150 150
 
151 151
 		// Get setting values.
152
-		$this->title                  = $this->get_option( 'title' );
153
-		$this->description            = $this->get_option( 'description' );
154
-		$this->enabled                = $this->get_option( 'enabled' );
155
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
156
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
157
-		$this->statement_descriptor   = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
158
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
159
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
160
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
161
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
162
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
163
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
164
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
165
-		$this->apple_pay              = 'yes' === $this->get_option( 'apple_pay' );
166
-		$this->apple_pay_domain_set   = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
167
-		$this->apple_pay_button       = $this->get_option( 'apple_pay_button', 'black' );
168
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
169
-		$this->allow_remember_me      = 'yes' === $this->get_option( 'allow_remember_me', 'no' );
170
-
171
-		if ( $this->stripe_checkout ) {
172
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
173
-		}
174
-
175
-		if ( $this->testmode ) {
176
-			$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
177
-			$this->description  = trim( $this->description );
178
-		}
179
-
180
-		WC_Stripe_API::set_secret_key( $this->secret_key );
152
+		$this->title                  = $this->get_option('title');
153
+		$this->description            = $this->get_option('description');
154
+		$this->enabled                = $this->get_option('enabled');
155
+		$this->testmode               = 'yes' === $this->get_option('testmode');
156
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
157
+		$this->statement_descriptor   = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
158
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
159
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
160
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
161
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
162
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
163
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
164
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
165
+		$this->apple_pay              = 'yes' === $this->get_option('apple_pay');
166
+		$this->apple_pay_domain_set   = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
167
+		$this->apple_pay_button       = $this->get_option('apple_pay_button', 'black');
168
+		$this->logging                = 'yes' === $this->get_option('logging');
169
+		$this->allow_remember_me      = 'yes' === $this->get_option('allow_remember_me', 'no');
170
+
171
+		if ($this->stripe_checkout) {
172
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
173
+		}
174
+
175
+		if ($this->testmode) {
176
+			$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
177
+			$this->description  = trim($this->description);
178
+		}
179
+
180
+		WC_Stripe_API::set_secret_key($this->secret_key);
181 181
 
182 182
 		// Hooks.
183
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
184
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
185
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
186
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
183
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
184
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
185
+		add_action('admin_notices', array($this, 'admin_notices'));
186
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
187 187
 	}
188 188
 
189 189
 	/**
@@ -197,15 +197,15 @@  discard block
 block discarded – undo
197 197
 		?>
198 198
 		<tr valign="top">
199 199
 			<th scope="row" class="titledesc">
200
-				<label for="wc-to-square"><?php esc_html_e( 'Apple Pay Domain Verification', 'woocommerce-gateway-stripe' ); ?></label>
201
-				<?php echo wc_help_tip( __( 'Click button to verify your domain with Apple Pay. This is required.', 'woocommerce-gateway-stripe' ) ); ?>
200
+				<label for="wc-to-square"><?php esc_html_e('Apple Pay Domain Verification', 'woocommerce-gateway-stripe'); ?></label>
201
+				<?php echo wc_help_tip(__('Click button to verify your domain with Apple Pay. This is required.', 'woocommerce-gateway-stripe')); ?>
202 202
 			</th>
203 203
 			<td class="forminp">
204
-				<?php if ( ! empty( $this->secret_key ) && ! $this->apple_pay_domain_set ) { ?>
205
-					<a href="#" id="wc-gateway-stripe-apple-pay-domain" class="button button-secondary"><?php esc_html_e( 'Verify Domain', 'woocommerce-gateway-stripe' ); ?></a>
204
+				<?php if ( ! empty($this->secret_key) && ! $this->apple_pay_domain_set) { ?>
205
+					<a href="#" id="wc-gateway-stripe-apple-pay-domain" class="button button-secondary"><?php esc_html_e('Verify Domain', 'woocommerce-gateway-stripe'); ?></a>
206 206
 				<?php } else { ?>
207
-					<a href="#" id="wc-gateway-stripe-apple-pay-domain" class="button button-secondary"><?php esc_html_e( 'Re-verify Domain', 'woocommerce-gateway-stripe' ); ?></a>
208
-					<p class="wc-stripe-apple-pay-domain-message" style="color:green;"><?php esc_html_e( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ); ?></p>
207
+					<a href="#" id="wc-gateway-stripe-apple-pay-domain" class="button button-secondary"><?php esc_html_e('Re-verify Domain', 'woocommerce-gateway-stripe'); ?></a>
208
+					<p class="wc-stripe-apple-pay-domain-message" style="color:green;"><?php esc_html_e('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe'); ?></p>
209 209
 				<?php } ?>
210 210
 				<input type="hidden" name="woocommerce_stripe_apple_pay_domain_set" class="wc-gateway-stripe-apple-pay-domain-set" />
211 211
 			</td>
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
 	 * @version 3.1.0
222 222
 	 * @param string $key
223 223
 	 */
224
-	public function validate_apple_pay_domain_field( $key ) {
225
-		$value = isset( $_POST['woocommerce_stripe_apple_pay_domain_set'] ) ? 'yes' : 'no';
224
+	public function validate_apple_pay_domain_field($key) {
225
+		$value = isset($_POST['woocommerce_stripe_apple_pay_domain_set']) ? 'yes' : 'no';
226 226
 
227 227
 		return $value;
228 228
 	}
@@ -234,24 +234,24 @@  discard block
 block discarded – undo
234 234
 	 * @return string
235 235
 	 */
236 236
 	public function get_icon() {
237
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
238
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
237
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
238
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
239 239
 
240
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
241
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
242
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
240
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
241
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
242
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
243 243
 
244
-		if ( 'USD' === get_woocommerce_currency() ) {
245
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
246
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
247
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
244
+		if ('USD' === get_woocommerce_currency()) {
245
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
246
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
247
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
248 248
 		}
249 249
 
250
-		if ( $this->bitcoin && $this->stripe_checkout ) {
251
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
250
+		if ($this->bitcoin && $this->stripe_checkout) {
251
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
252 252
 		}
253 253
 
254
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
254
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
255 255
 	}
256 256
 
257 257
 	/**
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
 	 *
263 263
 	 * @return float|int
264 264
 	 */
265
-	public function get_stripe_amount( $total, $currency = '' ) {
266
-		if ( ! $currency ) {
265
+	public function get_stripe_amount($total, $currency = '') {
266
+		if ( ! $currency) {
267 267
 			$currency = get_woocommerce_currency();
268 268
 		}
269
-		switch ( strtoupper( $currency ) ) {
269
+		switch (strtoupper($currency)) {
270 270
 			// Zero decimal currencies.
271 271
 			case 'BIF' :
272 272
 			case 'CLP' :
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
 			case 'XAF' :
284 284
 			case 'XOF' :
285 285
 			case 'XPF' :
286
-				$total = absint( $total );
286
+				$total = absint($total);
287 287
 				break;
288 288
 			default :
289
-				$total = round( $total, 2 ) * 100; // In cents.
289
+				$total = round($total, 2) * 100; // In cents.
290 290
 				break;
291 291
 		}
292 292
 		return $total;
@@ -296,13 +296,13 @@  discard block
 block discarded – undo
296 296
 	 * Check if SSL is enabled and notify the user
297 297
 	 */
298 298
 	public function admin_notices() {
299
-		if ( 'no' === $this->enabled ) {
299
+		if ('no' === $this->enabled) {
300 300
 			return;
301 301
 		}
302 302
 
303 303
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
304
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
305
-			echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>';
304
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
305
+			echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>';
306 306
 		}
307 307
 	}
308 308
 
@@ -310,11 +310,11 @@  discard block
 block discarded – undo
310 310
 	 * Check if this gateway is enabled
311 311
 	 */
312 312
 	public function is_available() {
313
-		if ( 'yes' === $this->enabled ) {
314
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
313
+		if ('yes' === $this->enabled) {
314
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
315 315
 				return false;
316 316
 			}
317
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
317
+			if ( ! $this->secret_key || ! $this->publishable_key) {
318 318
 				return false;
319 319
 			}
320 320
 			return true;
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 * Initialise Gateway Settings Form Fields
327 327
 	 */
328 328
 	public function init_form_fields() {
329
-		$this->form_fields = include( 'settings-stripe.php' );
329
+		$this->form_fields = include('settings-stripe.php');
330 330
 	}
331 331
 
332 332
 	/**
@@ -334,54 +334,54 @@  discard block
 block discarded – undo
334 334
 	 */
335 335
 	public function payment_fields() {
336 336
 		$user                 = wp_get_current_user();
337
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
337
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
338 338
 		$total                = WC()->cart->total;
339 339
 
340 340
 		// If paying from order, we need to get total from order not cart.
341
-		if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) {
342
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
341
+		if (isset($_GET['pay_for_order']) && isset($_GET['key'])) {
342
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
343 343
 			$total = $order->get_total();
344 344
 		}
345 345
 
346
-		if ( $user->ID ) {
347
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
346
+		if ($user->ID) {
347
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
348 348
 			$user_email = $user_email ? $user_email : $user->user_email;
349 349
 		} else {
350 350
 			$user_email = '';
351 351
 		}
352 352
 
353
-		if ( is_add_payment_method_page() ) {
354
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
353
+		if (is_add_payment_method_page()) {
354
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
355 355
 		} else {
356 356
 			$pay_button_text = '';
357 357
 		}
358 358
 
359 359
 		echo '<div
360 360
 			id="stripe-payment-data"
361
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
361
+			data-panel-label="' . esc_attr($pay_button_text) . '"
362 362
 			data-description=""
363
-			data-email="' . esc_attr( $user_email ) . '"
364
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
365
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
366
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
367
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
368
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
369
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
370
-			data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">';
363
+			data-email="' . esc_attr($user_email) . '"
364
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
365
+			data-name="' . esc_attr($this->statement_descriptor) . '"
366
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
367
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
368
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
369
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
370
+			data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">';
371 371
 
372
-		if ( $this->description ) {
373
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
372
+		if ($this->description) {
373
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
374 374
 		}
375 375
 
376
-		if ( $display_tokenization ) {
376
+		if ($display_tokenization) {
377 377
 			$this->tokenization_script();
378 378
 			$this->saved_payment_methods();
379 379
 		}
380 380
 
381
-		if ( ! $this->stripe_checkout ) {
381
+		if ( ! $this->stripe_checkout) {
382 382
 			$this->form();
383 383
 
384
-			if ( $display_tokenization ) {
384
+			if ($display_tokenization) {
385 385
 				$this->save_payment_method_checkbox();
386 386
 			}
387 387
 		}
@@ -397,20 +397,20 @@  discard block
 block discarded – undo
397 397
 	 * @return array
398 398
 	 */
399 399
 	public function get_localized_messages() {
400
-		return apply_filters( 'wc_stripe_localized_messages', array(
401
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
402
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
403
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
404
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
405
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
406
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
407
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
408
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
409
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
410
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
411
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
412
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
413
-		) );
400
+		return apply_filters('wc_stripe_localized_messages', array(
401
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
402
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
403
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
404
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
405
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
406
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
407
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
408
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
409
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
410
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
411
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
412
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
413
+		));
414 414
 	}
415 415
 
416 416
 	/**
@@ -420,27 +420,27 @@  discard block
 block discarded – undo
420 420
 	 * @version 3.1.0
421 421
 	 */
422 422
 	public function admin_scripts() {
423
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
423
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
424 424
 			return;
425 425
 		}
426 426
 
427
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
427
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
428 428
 
429
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
429
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
430 430
 
431 431
 		$stripe_admin_params = array(
432 432
 			'localized_messages' => array(
433
-				'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ),
434
-				'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ),
435
-				're_verify_button_text'  => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ),
433
+				'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'),
434
+				'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'),
435
+				're_verify_button_text'  => __('Re-verify Domain', 'woocommerce-gateway-stripe'),
436 436
 			),
437
-			'ajaxurl'            => admin_url( 'admin-ajax.php' ),
437
+			'ajaxurl'            => admin_url('admin-ajax.php'),
438 438
 			'nonce'              => array( 
439
-				'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ),
439
+				'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'),
440 440
 			),
441 441
 		);
442 442
 
443
-		wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) );
443
+		wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params));
444 444
 	}
445 445
 
446 446
 	/**
@@ -451,30 +451,30 @@  discard block
 block discarded – undo
451 451
 	 * @access public
452 452
 	 */
453 453
 	public function payment_scripts() {
454
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
454
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
455 455
 			return;
456 456
 		}
457 457
 
458
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
458
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
459 459
 
460
-		if ( $this->stripe_checkout ) {
461
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
462
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
460
+		if ($this->stripe_checkout) {
461
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
462
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
463 463
 		} else {
464
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
465
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
464
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
465
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
466 466
 		}
467 467
 
468 468
 		$stripe_params = array(
469 469
 			'key'                  => $this->publishable_key,
470
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
471
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
470
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
471
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
472 472
 		);
473 473
 
474 474
 		// If we're on the pay page we need to pass stripe.js the address of the order.
475
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
476
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
477
-			$order    = wc_get_order( $order_id );
475
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
476
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
477
+			$order    = wc_get_order($order_id);
478 478
 
479 479
 			$stripe_params['billing_first_name'] = $order->billing_first_name;
480 480
 			$stripe_params['billing_last_name']  = $order->billing_last_name;
@@ -486,14 +486,14 @@  discard block
 block discarded – undo
486 486
 			$stripe_params['billing_country']    = $order->billing_country;
487 487
 		}
488 488
 
489
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
490
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
491
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
489
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
490
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
491
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
492 492
 
493 493
 		// merge localized messages to be use in JS
494
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
494
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
495 495
 
496
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
496
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
497 497
 	}
498 498
 
499 499
 	/**
@@ -502,31 +502,31 @@  discard block
 block discarded – undo
502 502
 	 * @param  object $source
503 503
 	 * @return array()
504 504
 	 */
505
-	protected function generate_payment_request( $order, $source ) {
505
+	protected function generate_payment_request($order, $source) {
506 506
 		$post_data                = array();
507
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
508
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
509
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
507
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
508
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
509
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
510 510
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
511 511
 
512
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
512
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
513 513
 			$post_data['receipt_email'] = $order->billing_email;
514 514
 		}
515 515
 
516
-		$post_data['expand[]']    = 'balance_transaction';
516
+		$post_data['expand[]'] = 'balance_transaction';
517 517
 
518 518
 		$metadata = array(
519
-			__( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $order->billing_first_name ) . ' ' . sanitize_text_field( $order->billing_last_name ),
520
-			__( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $order->billing_email ),
519
+			__('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($order->billing_first_name) . ' ' . sanitize_text_field($order->billing_last_name),
520
+			__('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($order->billing_email),
521 521
 		);
522 522
 
523
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
523
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
524 524
 
525
-		if ( $source->customer ) {
525
+		if ($source->customer) {
526 526
 			$post_data['customer'] = $source->customer;
527 527
 		}
528 528
 
529
-		if ( $source->source ) {
529
+		if ($source->source) {
530 530
 			$post_data['source'] = $source->source;
531 531
 		}
532 532
 
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 		 * @param WC_Order $order
539 539
 		 * @param object $source
540 540
 		 */
541
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
541
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
542 542
 	}
543 543
 
544 544
 	/**
@@ -550,37 +550,37 @@  discard block
 block discarded – undo
550 550
 	 * @throws Exception When card was not added or for and invalid card.
551 551
 	 * @return object
552 552
 	 */
553
-	protected function get_source( $user_id, $force_customer = false ) {
554
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
553
+	protected function get_source($user_id, $force_customer = false) {
554
+		$stripe_customer = new WC_Stripe_Customer($user_id);
555 555
 		$stripe_source   = false;
556 556
 		$token_id        = false;
557 557
 
558 558
 		// New CC info was entered and we have a new token to process
559
-		if ( isset( $_POST['stripe_token'] ) ) {
560
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
561
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
559
+		if (isset($_POST['stripe_token'])) {
560
+			$stripe_token     = wc_clean($_POST['stripe_token']);
561
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
562 562
 
563 563
 			// This is true if the user wants to store the card to their account.
564
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
565
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
564
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
565
+				$stripe_source = $stripe_customer->add_card($stripe_token);
566 566
 
567
-				if ( is_wp_error( $stripe_source ) ) {
568
-					throw new Exception( $stripe_source->get_error_message() );
567
+				if (is_wp_error($stripe_source)) {
568
+					throw new Exception($stripe_source->get_error_message());
569 569
 				}
570 570
 			} else {
571 571
 				// Not saving token, so don't define customer either.
572 572
 				$stripe_source   = $stripe_token;
573 573
 				$stripe_customer = false;
574 574
 			}
575
-		} elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
575
+		} elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
576 576
 			// Use an existing token, and then process the payment
577 577
 
578
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
579
-			$token    = WC_Payment_Tokens::get( $token_id );
578
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
579
+			$token    = WC_Payment_Tokens::get($token_id);
580 580
 
581
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
582
-				WC()->session->set( 'refresh_totals', true );
583
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
581
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
582
+				WC()->session->set('refresh_totals', true);
583
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
584 584
 			}
585 585
 
586 586
 			$stripe_source = $token->get_token();
@@ -604,16 +604,16 @@  discard block
 block discarded – undo
604 604
 	 * @param object $order
605 605
 	 * @return object
606 606
 	 */
607
-	protected function get_order_source( $order = null ) {
607
+	protected function get_order_source($order = null) {
608 608
 		$stripe_customer = new WC_Stripe_Customer();
609 609
 		$stripe_source   = false;
610 610
 		$token_id        = false;
611 611
 
612
-		if ( $order ) {
613
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
614
-				$stripe_customer->set_id( $meta_value );
612
+		if ($order) {
613
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
614
+				$stripe_customer->set_id($meta_value);
615 615
 			}
616
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
616
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
617 617
 				$stripe_source = $meta_value;
618 618
 			}
619 619
 		}
@@ -636,57 +636,57 @@  discard block
 block discarded – undo
636 636
 	 *
637 637
 	 * @return array|void
638 638
 	 */
639
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
639
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
640 640
 		try {
641
-			$order  = wc_get_order( $order_id );
642
-			$source = $this->get_source( get_current_user_id(), $force_customer );
641
+			$order  = wc_get_order($order_id);
642
+			$source = $this->get_source(get_current_user_id(), $force_customer);
643 643
 
644
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
645
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
646
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
647
-				throw new Exception( $error_msg );
644
+			if (empty($source->source) && empty($source->customer)) {
645
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
646
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
647
+				throw new Exception($error_msg);
648 648
 			}
649 649
 
650 650
 			// Store source to order meta.
651
-			$this->save_source( $order, $source );
651
+			$this->save_source($order, $source);
652 652
 
653 653
 			// Handle payment.
654
-			if ( $order->get_total() > 0 ) {
654
+			if ($order->get_total() > 0) {
655 655
 
656
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
657
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
656
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
657
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
658 658
 				}
659 659
 
660
-				$this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
660
+				$this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
661 661
 
662 662
 				// Make the request.
663
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
663
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
664 664
 
665
-				if ( is_wp_error( $response ) ) {
665
+				if (is_wp_error($response)) {
666 666
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
667
-					if ( 'customer' === $response->get_error_code() && $retry ) {
668
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
669
-						return $this->process_payment( $order_id, false, $force_customer );
667
+					if ('customer' === $response->get_error_code() && $retry) {
668
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
669
+						return $this->process_payment($order_id, false, $force_customer);
670 670
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
671
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
672
-						$token = WC_Payment_Tokens::get( $source->token_id );
671
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
672
+						$token = WC_Payment_Tokens::get($source->token_id);
673 673
 						$token->delete();
674
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
675
-						$order->add_order_note( $message );
676
-						throw new Exception( $message );
674
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
675
+						$order->add_order_note($message);
676
+						throw new Exception($message);
677 677
 					}
678 678
 
679 679
 					$localized_messages = $this->get_localized_messages();
680 680
 
681
-					$message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message();
681
+					$message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message();
682 682
 
683
-					$order->add_order_note( $message );
683
+					$order->add_order_note($message);
684 684
 
685
-					throw new Exception( $message );
685
+					throw new Exception($message);
686 686
 				}
687 687
 
688 688
 				// Process valid response.
689
-				$this->process_response( $response, $order );
689
+				$this->process_response($response, $order);
690 690
 			} else {
691 691
 				$order->payment_complete();
692 692
 			}
@@ -694,23 +694,23 @@  discard block
 block discarded – undo
694 694
 			// Remove cart.
695 695
 			WC()->cart->empty_cart();
696 696
 
697
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
697
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
698 698
 
699 699
 			// Return thank you page redirect.
700 700
 			return array(
701 701
 				'result'   => 'success',
702
-				'redirect' => $this->get_return_url( $order ),
702
+				'redirect' => $this->get_return_url($order),
703 703
 			);
704 704
 
705
-		} catch ( Exception $e ) {
706
-			wc_add_notice( $e->getMessage(), 'error' );
707
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
705
+		} catch (Exception $e) {
706
+			wc_add_notice($e->getMessage(), 'error');
707
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
708 708
 
709
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
710
-				$this->send_failed_order_email( $order_id );
709
+			if ($order->has_status(array('pending', 'failed'))) {
710
+				$this->send_failed_order_email($order_id);
711 711
 			}
712 712
 
713
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
713
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
714 714
 
715 715
 			return array(
716 716
 				'result'   => 'fail',
@@ -725,52 +725,52 @@  discard block
 block discarded – undo
725 725
 	 * @param WC_Order $order For to which the source applies.
726 726
 	 * @param stdClass $source Source information.
727 727
 	 */
728
-	protected function save_source( $order, $source ) {
728
+	protected function save_source($order, $source) {
729 729
 		// Store source in the order.
730
-		if ( $source->customer ) {
731
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
730
+		if ($source->customer) {
731
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
732 732
 		}
733
-		if ( $source->source ) {
734
-			update_post_meta( $order->id, '_stripe_card_id', $source->source );
733
+		if ($source->source) {
734
+			update_post_meta($order->id, '_stripe_card_id', $source->source);
735 735
 		}
736 736
 	}
737 737
 
738 738
 	/**
739 739
 	 * Store extra meta data for an order from a Stripe Response.
740 740
 	 */
741
-	public function process_response( $response, $order ) {
742
-		$this->log( 'Processing response: ' . print_r( $response, true ) );
741
+	public function process_response($response, $order) {
742
+		$this->log('Processing response: ' . print_r($response, true));
743 743
 
744 744
 		// Store charge data
745
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
746
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
745
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
746
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
747 747
 
748 748
 		// Store other data such as fees
749
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
749
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
750 750
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
751 751
 			// values are in the local currency of the Stripe account, not from WC.
752
-			$fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0;
753
-			$net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0;
754
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
755
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
752
+			$fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0;
753
+			$net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0;
754
+			update_post_meta($order->id, 'Stripe Fee', $fee);
755
+			update_post_meta($order->id, 'Net Revenue From Stripe', $net);
756 756
 		}
757 757
 
758
-		if ( $response->captured ) {
759
-			$order->payment_complete( $response->id );
758
+		if ($response->captured) {
759
+			$order->payment_complete($response->id);
760 760
 
761
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
762
-			$order->add_order_note( $message );
763
-			$this->log( 'Success: ' . $message );
761
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
762
+			$order->add_order_note($message);
763
+			$this->log('Success: ' . $message);
764 764
 
765 765
 		} else {
766
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
766
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
767 767
 
768
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
768
+			if ($order->has_status(array('pending', 'failed'))) {
769 769
 				$order->reduce_order_stock();
770 770
 			}
771 771
 
772
-			$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 ) );
773
-			$this->log( "Successful auth: $response->id" );
772
+			$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));
773
+			$this->log("Successful auth: $response->id");
774 774
 		}
775 775
 
776 776
 		return $response;
@@ -782,32 +782,32 @@  discard block
 block discarded – undo
782 782
 	 * @since 3.0.0
783 783
 	 */
784 784
 	public function add_payment_method() {
785
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
786
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
785
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
786
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
787 787
 			return;
788 788
 		}
789 789
 
790
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
791
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
790
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
791
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
792 792
 
793
-		if ( is_wp_error( $card ) ) {
793
+		if (is_wp_error($card)) {
794 794
 			$localized_messages = $this->get_localized_messages();
795
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
795
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
796 796
 
797 797
 			// loop through the errors to find matching localized message
798
-			foreach ( $card->errors as $error => $msg ) {
799
-				if ( isset( $localized_messages[ $error ] ) ) {
800
-					$error_msg = $localized_messages[ $error ];
798
+			foreach ($card->errors as $error => $msg) {
799
+				if (isset($localized_messages[$error])) {
800
+					$error_msg = $localized_messages[$error];
801 801
 				}
802 802
 			}
803 803
 
804
-			wc_add_notice( $error_msg, 'error' );
804
+			wc_add_notice($error_msg, 'error');
805 805
 			return;
806 806
 		}
807 807
 
808 808
 		return array(
809 809
 			'result'   => 'success',
810
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
810
+			'redirect' => wc_get_endpoint_url('payment-methods'),
811 811
 		);
812 812
 	}
813 813
 
@@ -817,36 +817,36 @@  discard block
 block discarded – undo
817 817
 	 * @param  float $amount
818 818
 	 * @return bool
819 819
 	 */
820
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
821
-		$order = wc_get_order( $order_id );
820
+	public function process_refund($order_id, $amount = null, $reason = '') {
821
+		$order = wc_get_order($order_id);
822 822
 
823
-		if ( ! $order || ! $order->get_transaction_id() ) {
823
+		if ( ! $order || ! $order->get_transaction_id()) {
824 824
 			return false;
825 825
 		}
826 826
 
827 827
 		$body = array();
828 828
 
829
-		if ( ! is_null( $amount ) ) {
830
-			$body['amount']	= $this->get_stripe_amount( $amount );
829
+		if ( ! is_null($amount)) {
830
+			$body['amount'] = $this->get_stripe_amount($amount);
831 831
 		}
832 832
 
833
-		if ( $reason ) {
833
+		if ($reason) {
834 834
 			$body['metadata'] = array(
835 835
 				'reason'	=> $reason,
836 836
 			);
837 837
 		}
838 838
 
839
-		$this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
839
+		$this->log("Info: Beginning refund for order $order_id for the amount of {$amount}");
840 840
 
841
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
841
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
842 842
 
843
-		if ( is_wp_error( $response ) ) {
844
-			$this->log( 'Error: ' . $response->get_error_message() );
843
+		if (is_wp_error($response)) {
844
+			$this->log('Error: ' . $response->get_error_message());
845 845
 			return $response;
846
-		} elseif ( ! empty( $response->id ) ) {
847
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
848
-			$order->add_order_note( $refund_message );
849
-			$this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
846
+		} elseif ( ! empty($response->id)) {
847
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
848
+			$order->add_order_note($refund_message);
849
+			$this->log('Success: ' . html_entity_decode(strip_tags($refund_message)));
850 850
 			return true;
851 851
 		}
852 852
 	}
@@ -859,10 +859,10 @@  discard block
 block discarded – undo
859 859
 	 * @param int $order_id
860 860
 	 * @return null
861 861
 	 */
862
-	public function send_failed_order_email( $order_id ) {
862
+	public function send_failed_order_email($order_id) {
863 863
 		$emails = WC()->mailer()->get_emails();
864
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
865
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
864
+		if ( ! empty($emails) && ! empty($order_id)) {
865
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
866 866
 		}
867 867
 	}
868 868
 
@@ -874,9 +874,9 @@  discard block
 block discarded – undo
874 874
 	 *
875 875
 	 * @param string $message
876 876
 	 */
877
-	public function log( $message ) {
878
-		if ( $this->logging ) {
879
-			WC_Stripe::log( $message );
877
+	public function log($message) {
878
+		if ($this->logging) {
879
+			WC_Stripe::log($message);
880 880
 		}
881 881
 	}
882 882
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +199 added lines, -199 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
 
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
 	public function __construct() {
48 48
 		self::$_this = $this;
49 49
 
50
-		$this->_gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
50
+		$this->_gateway_settings = get_option('woocommerce_stripe_settings', '');
51 51
 
52
-		$this->statement_descriptor = ! empty( $this->_gateway_settings['statement_descriptor'] ) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
52
+		$this->statement_descriptor = ! empty($this->_gateway_settings['statement_descriptor']) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
53 53
 
54 54
 		$this->init();
55 55
 	}
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
 	 * @version 3.1.0
67 67
 	 */
68 68
 	public function init() {
69
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
70
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 20 );
71
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ) );
72
-		add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
73
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
74
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
75
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
76
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
69
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
70
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 20);
71
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'));
72
+		add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
73
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
74
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
75
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
76
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
77 77
 	}
78 78
 
79 79
 	/**
@@ -84,45 +84,45 @@  discard block
 block discarded – undo
84 84
 	 * @version 3.1.0
85 85
 	 */
86 86
 	public static function process_apple_pay_domain() {
87
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_domain_nonce' ) ) {
88
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
87
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_domain_nonce')) {
88
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
89 89
 		}
90 90
 
91 91
 		try {
92
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
92
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
93 93
 			$dir      = '.well-known';
94 94
 			$file     = 'apple-developer-merchantid-domain-association';
95 95
 			$fullpath = $path . '/' . $dir . '/' . $file;
96
-			$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
96
+			$gateway_settings = get_option('woocommerce_stripe_settings', '');
97 97
 
98
-			if ( ! file_exists( $path . '/' . $dir ) || ! file_exists( $fullpath ) ) {
99
-				if ( ! mkdir( $path . '/' . $dir, 0755 ) ) {
100
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
98
+			if ( ! file_exists($path . '/' . $dir) || ! file_exists($fullpath)) {
99
+				if ( ! mkdir($path . '/' . $dir, 0755)) {
100
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
101 101
 				}
102 102
 
103
-				if ( ! file_exists( $path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association' ) ) {
104
-					if ( ! copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
105
-						throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
103
+				if ( ! file_exists($path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association')) {
104
+					if ( ! copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
105
+						throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
106 106
 					}
107 107
 				}
108 108
 			}
109 109
 
110 110
 			// At this point then the domain association folder and file should be available.
111 111
 			// Proceed to verify/and or verify again.
112
-			WC_Stripe_Apple_Pay::_register_apple_pay_domain( $gateway_settings );
112
+			WC_Stripe_Apple_Pay::_register_apple_pay_domain($gateway_settings);
113 113
 
114 114
 			// No errors to this point, verification success!
115 115
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
116 116
 
117
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
117
+			update_option('woocommerce_stripe_settings', $gateway_settings);
118 118
 
119
-			wp_send_json( array( 'success' => true, 'message' => __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) ) );
120
-		} catch ( Exception $e ) {
119
+			wp_send_json(array('success' => true, 'message' => __('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe')));
120
+		} catch (Exception $e) {
121 121
 			$gateway_settings['apple_pay_domain_set'] = 'no';
122 122
 
123
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
123
+			update_option('woocommerce_stripe_settings', $gateway_settings);
124 124
 
125
-			wp_send_json( array( 'success' => false, 'message' => $e->getMessage() ) );
125
+			wp_send_json(array('success' => false, 'message' => $e->getMessage()));
126 126
 		}
127 127
 	}
128 128
 
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
 	 * @version 3.1.0
134 134
 	 * @param array $gateway_settings
135 135
 	 */
136
-	private static function _register_apple_pay_domain( $gateway_settings = array() ) {
137
-		if ( empty( $gateway_settings ) ) {
138
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
136
+	private static function _register_apple_pay_domain($gateway_settings = array()) {
137
+		if (empty($gateway_settings)) {
138
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
139 139
 		}
140 140
 
141 141
 		$secret_key = 'yes' === $gateway_settings['testmode'] ? $gateway_settings['test_secret_key'] : $gateway_settings['secret_key'];
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
 			'Authorization' => 'Bearer ' . $secret_key,
152 152
 		);
153 153
 
154
-		$response = wp_remote_post( $endpoint, array(
154
+		$response = wp_remote_post($endpoint, array(
155 155
 			'headers' => $headers,
156
-			'body'    => http_build_query( $data ),
157
-		) );
156
+			'body'    => http_build_query($data),
157
+		));
158 158
 
159
-		if ( 200 !== $response['response']['code'] ) {
160
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response['response']['message'] ) );
159
+		if (200 !== $response['response']['code']) {
160
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response['response']['message']));
161 161
 		}
162 162
 	}
163 163
 
@@ -165,16 +165,16 @@  discard block
 block discarded – undo
165 165
 	 * Filters the gateway title to reflect Apple Pay.
166 166
 	 *
167 167
 	 */
168
-	public function filter_gateway_title( $title, $id ) {
168
+	public function filter_gateway_title($title, $id) {
169 169
 		global $post;
170 170
 
171
-		if ( ! is_object( $post ) ) {
171
+		if ( ! is_object($post)) {
172 172
 			return $title;
173 173
 		}
174 174
 
175
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
175
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
176 176
 
177
-		if ( 'stripe' === $id && ! empty( $method_title ) ) {
177
+		if ('stripe' === $id && ! empty($method_title)) {
178 178
 			return $method_title;
179 179
 		}
180 180
 
@@ -188,38 +188,38 @@  discard block
 block discarded – undo
188 188
 	 * @version 3.1.0
189 189
 	 */
190 190
 	public function payment_scripts() {
191
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
191
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
192 192
 			return;
193 193
 		}
194 194
 
195
-		if ( ! $this->is_supported_product_type() ) {
195
+		if ( ! $this->is_supported_product_type()) {
196 196
 			return;
197 197
 		}
198 198
 
199
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
199
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
200 200
 
201
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
201
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
202 202
 
203
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
204
-		wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
203
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
204
+		wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
205 205
 
206 206
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
207 207
 
208 208
 		$stripe_params = array(
209 209
 			'key'                                           => $publishable_key,
210 210
 			'currency_code'                                 => get_woocommerce_currency(),
211
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
211
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
212 212
 			'label'                                         => $this->statement_descriptor,
213
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
214
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
215
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
216
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
217
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
213
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
214
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
215
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
216
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
217
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
218 218
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
219 219
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
220 220
 		);
221 221
 
222
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
222
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
223 223
 	}
224 224
 
225 225
 	/**
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 */
229 229
 	public function is_supported_product_type() {
230
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
231
-			if ( 'subscription' === $values['data']->product_type ) {
230
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
231
+			if ('subscription' === $values['data']->product_type) {
232 232
 				return false;
233 233
 			}
234 234
 		}
@@ -251,19 +251,19 @@  discard block
 block discarded – undo
251 251
 		 */
252 252
 		if (
253 253
 			'yes' !== $this->_gateway_settings['apple_pay']
254
-			|| ! isset( $gateways['stripe'] )
254
+			|| ! isset($gateways['stripe'])
255 255
 		) {
256 256
 			return;
257 257
 		}
258 258
 
259
-		if ( ! $this->is_supported_product_type() ) {
259
+		if ( ! $this->is_supported_product_type()) {
260 260
 			return;
261 261
 		}
262 262
 
263
-		$apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black';
264
-		$button_lang      = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en';
263
+		$apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black';
264
+		$button_lang      = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en';
265 265
 		?>
266
-		<button class="apple-pay-button" lang="<?php echo esc_attr( $button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $apple_pay_button ); ?>;"></button>
266
+		<button class="apple-pay-button" lang="<?php echo esc_attr($button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($apple_pay_button); ?>;"></button>
267 267
 		<?php
268 268
 	}
269 269
 
@@ -274,11 +274,11 @@  discard block
 block discarded – undo
274 274
 	 * @version 3.1.0
275 275
 	 */
276 276
 	public function generate_apple_pay_cart() {
277
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
278
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
277
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
278
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
279 279
 		}
280 280
 
281
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
281
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
282 282
 	}
283 283
 
284 284
 	/**
@@ -288,29 +288,29 @@  discard block
 block discarded – undo
288 288
 	 * @version 3.1.0
289 289
 	 * @param array $address
290 290
 	 */
291
-	public function calculate_shipping( $address = array() ) {
292
-		$country  = strtoupper( $address['countryCode'] );
293
-		$state    = strtoupper( $address['administrativeArea'] );
291
+	public function calculate_shipping($address = array()) {
292
+		$country  = strtoupper($address['countryCode']);
293
+		$state    = strtoupper($address['administrativeArea']);
294 294
 		$postcode = $address['postalCode'];
295 295
 		$city     = $address['locality'];
296 296
 
297 297
 		WC()->shipping->reset_shipping();
298 298
 
299
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
300
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
301
-		} elseif ( $postcode ) {
302
-			$postcode = wc_format_postcode( $postcode, $country );
299
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
300
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
301
+		} elseif ($postcode) {
302
+			$postcode = wc_format_postcode($postcode, $country);
303 303
 		}
304 304
 
305
-		if ( $country ) {
306
-			WC()->customer->set_location( $country, $state, $postcode, $city );
307
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
305
+		if ($country) {
306
+			WC()->customer->set_location($country, $state, $postcode, $city);
307
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
308 308
 		} else {
309 309
 			WC()->customer->set_to_base();
310 310
 			WC()->customer->set_shipping_to_base();
311 311
 		}
312 312
 
313
-		WC()->customer->calculated_shipping( true );
313
+		WC()->customer->calculated_shipping(true);
314 314
 
315 315
 		/**
316 316
 		 * Set the shipping package.
@@ -332,17 +332,17 @@  discard block
 block discarded – undo
332 332
 		$packages[0]['destination']['postcode']  = $postcode;
333 333
 		$packages[0]['destination']['city']      = $city;
334 334
 
335
-		foreach ( WC()->cart->get_cart() as $item ) {
336
-			if ( $item['data']->needs_shipping() ) {
337
-				if ( isset( $item['line_total'] ) ) {
335
+		foreach (WC()->cart->get_cart() as $item) {
336
+			if ($item['data']->needs_shipping()) {
337
+				if (isset($item['line_total'])) {
338 338
 					$packages[0]['contents_cost'] += $item['line_total'];
339 339
 				}
340 340
 			}
341 341
 		}
342 342
 
343
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
343
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
344 344
 
345
-		WC()->shipping->calculate_shipping( $packages );
345
+		WC()->shipping->calculate_shipping($packages);
346 346
 	}
347 347
 
348 348
 	/**
@@ -352,18 +352,18 @@  discard block
 block discarded – undo
352 352
 	 * @version 3.1.0
353 353
 	 */
354 354
 	public function get_shipping_methods() {
355
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
356
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
355
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
356
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
357 357
 		}
358 358
 
359
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
360
-			define( 'WOOCOMMERCE_CART', true );
359
+		if ( ! defined('WOOCOMMERCE_CART')) {
360
+			define('WOOCOMMERCE_CART', true);
361 361
 		}
362 362
 
363 363
 		try {
364
-			$address = array_map( 'wc_clean', $_POST['address'] );
364
+			$address = array_map('wc_clean', $_POST['address']);
365 365
 
366
-			$this->calculate_shipping( $address );
366
+			$this->calculate_shipping($address);
367 367
 
368 368
 			// Set the shipping options.
369 369
 			$currency = get_woocommerce_currency();
@@ -371,13 +371,13 @@  discard block
 block discarded – undo
371 371
 
372 372
 			$packages = WC()->shipping->get_packages();
373 373
 
374
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
375
-				foreach ( $packages as $package_key => $package ) {
376
-					if ( empty( $package['rates'] ) ) {
377
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
374
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
375
+				foreach ($packages as $package_key => $package) {
376
+					if (empty($package['rates'])) {
377
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
378 378
 					}
379 379
 
380
-					foreach ( $package['rates'] as $key => $rate ) {
380
+					foreach ($package['rates'] as $key => $rate) {
381 381
 						$data[] = array(
382 382
 							'id'       => $rate->id,
383 383
 							'label'    => $rate->label,
@@ -391,16 +391,16 @@  discard block
 block discarded – undo
391 391
 				}
392 392
 
393 393
 				// Auto select the first shipping method.
394
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
394
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
395 395
 
396 396
 				WC()->cart->calculate_totals();
397 397
 
398
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
398
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
399 399
 			} else {
400
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
400
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
401 401
 			}
402
-		} catch ( Exception $e ) {
403
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
402
+		} catch (Exception $e) {
403
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
404 404
 		}
405 405
 	}
406 406
 
@@ -411,29 +411,29 @@  discard block
 block discarded – undo
411 411
 	 * @version 3.1.0
412 412
 	 */
413 413
 	public function update_shipping_method() {
414
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
415
-			define( 'WOOCOMMERCE_CART', true );
414
+		if ( ! defined('WOOCOMMERCE_CART')) {
415
+			define('WOOCOMMERCE_CART', true);
416 416
 		}
417 417
 
418
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
419
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
418
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
419
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
420 420
 		}
421 421
 
422
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
422
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
423 423
 
424
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
424
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
425 425
 
426 426
 		WC()->cart->calculate_totals();
427 427
 
428 428
 		// Send back the new cart total.
429 429
 		$currency  = get_woocommerce_currency();
430
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
430
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
431 431
 		$data      = array(
432 432
 			'total' => WC()->cart->total,
433 433
 		);
434 434
 
435 435
 		// Include fees and taxes as displayItems.
436
-		foreach ( WC()->cart->fees as $key => $fee ) {
436
+		foreach (WC()->cart->fees as $key => $fee) {
437 437
 			$data['items'][] = array(
438 438
 				'label'  => $fee->name,
439 439
 				'amount' => array(
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
 				),
443 443
 			);
444 444
 		}
445
-		if ( 0 < $tax_total ) {
445
+		if (0 < $tax_total) {
446 446
 			$data['items'][] = array(
447
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
447
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
448 448
 				'amount' => array(
449 449
 					'currency' => $currency,
450 450
 					'value'    => $tax_total,
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 			);
453 453
 		}
454 454
 
455
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
455
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
456 456
 	}
457 457
 
458 458
 	/**
@@ -463,35 +463,35 @@  discard block
 block discarded – undo
463 463
 	 * @version 3.1.0
464 464
 	 */
465 465
 	public function process_apple_pay() {
466
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
467
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
466
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
467
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
468 468
 		}
469 469
 
470 470
 		try {
471
-			$result = array_map( 'wc_clean', $_POST['result'] );
471
+			$result = array_map('wc_clean', $_POST['result']);
472 472
 
473
-			$order = $this->create_order( $result );
473
+			$order = $this->create_order($result);
474 474
 
475 475
 			// Handle payment.
476
-			if ( $order->get_total() > 0 ) {
476
+			if ($order->get_total() > 0) {
477 477
 
478
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
479
-					return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
478
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
479
+					return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
480 480
 				}
481 481
 
482
-				WC_Stripe::log( "Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}" );
482
+				WC_Stripe::log("Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}");
483 483
 
484 484
 				// Make the request.
485
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
485
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
486 486
 
487
-				if ( is_wp_error( $response ) ) {
487
+				if (is_wp_error($response)) {
488 488
 					$localized_messages = $this->get_localized_messages();
489 489
 
490
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
490
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
491 491
 				}
492 492
 
493 493
 				// Process valid response.
494
-				$this->process_response( $response, $order );
494
+				$this->process_response($response, $order);
495 495
 			} else {
496 496
 				$order->payment_complete();
497 497
 			}
@@ -499,24 +499,24 @@  discard block
 block discarded – undo
499 499
 			// Remove cart.
500 500
 			WC()->cart->empty_cart();
501 501
 
502
-			update_post_meta( $order->id, '_customer_user', get_current_user_id() );
503
-			update_post_meta( $order->id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) );
502
+			update_post_meta($order->id, '_customer_user', get_current_user_id());
503
+			update_post_meta($order->id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe'));
504 504
 
505 505
 			// Return thank you page redirect.
506
-			wp_send_json( array(
506
+			wp_send_json(array(
507 507
 				'success'  => 'true',
508
-				'redirect' => $this->get_return_url( $order ),
509
-			) );
508
+				'redirect' => $this->get_return_url($order),
509
+			));
510 510
 
511
-		} catch ( Exception $e ) {
512
-			WC()->session->set( 'refresh_totals', true );
513
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
511
+		} catch (Exception $e) {
512
+			WC()->session->set('refresh_totals', true);
513
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
514 514
 
515
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
516
-				$this->send_failed_order_email( $order->id );
515
+			if ($order->has_status(array('pending', 'failed'))) {
516
+				$this->send_failed_order_email($order->id);
517 517
 			}
518 518
 
519
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
519
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
520 520
 		}
521 521
 	}
522 522
 
@@ -526,14 +526,14 @@  discard block
 block discarded – undo
526 526
 	 * @param string $source token
527 527
 	 * @return array()
528 528
 	 */
529
-	protected function generate_payment_request( $order, $source ) {
529
+	protected function generate_payment_request($order, $source) {
530 530
 		$post_data                = array();
531
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
532
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
533
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
531
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
532
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
533
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
534 534
 		$post_data['capture']     = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false';
535 535
 
536
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
536
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
537 537
 			$post_data['receipt_email'] = $order->billing_email;
538 538
 		}
539 539
 
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 		 * @param WC_Order $order
549 549
 		 * @param object $source
550 550
 		 */
551
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
551
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
552 552
 	}
553 553
 
554 554
 	/**
@@ -557,14 +557,14 @@  discard block
 block discarded – undo
557 557
 	 * @since 3.1.0
558 558
 	 * @version 3.1.0
559 559
 	 */
560
-	public function build_shipping_methods( $shipping_methods ) {
561
-		if ( empty( $shipping_methods ) ) {
560
+	public function build_shipping_methods($shipping_methods) {
561
+		if (empty($shipping_methods)) {
562 562
 			return array();
563 563
 		}
564 564
 
565 565
 		$shipping = array();
566 566
 
567
-		foreach ( $shipping_methods as $method ) {
567
+		foreach ($shipping_methods as $method) {
568 568
 			$shipping[] = array(
569 569
 				'label'      => $method['label'],
570 570
 				'detail'     => '',
@@ -583,53 +583,53 @@  discard block
 block discarded – undo
583 583
 	 * @version 3.1.0
584 584
 	 */
585 585
 	public function build_line_items() {
586
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
587
-			define( 'WOOCOMMERCE_CART', true );
586
+		if ( ! defined('WOOCOMMERCE_CART')) {
587
+			define('WOOCOMMERCE_CART', true);
588 588
 		}
589 589
 
590
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
590
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
591 591
 
592 592
 		$items = array();
593 593
 
594
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
595
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
594
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
595
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
596 596
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
597 597
 
598 598
 			$item = array(
599 599
 				'type'   => 'final',
600 600
 				'label'  => $values['data']->post->post_title . $quantity_label,
601
-				'amount' => wc_format_decimal( $amount, $decimals ),
601
+				'amount' => wc_format_decimal($amount, $decimals),
602 602
 			);
603 603
 
604 604
 			$items[] = $item;
605 605
 		}
606 606
 
607
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
608
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
609
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
610
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
611
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
607
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
608
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
609
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
610
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
611
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
612 612
 
613
-		if ( wc_tax_enabled() ) {
613
+		if (wc_tax_enabled()) {
614 614
 			$items[] = array(
615 615
 				'type'   => 'final',
616
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
616
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
617 617
 				'amount' => $tax,
618 618
 			);
619 619
 		}
620 620
 
621
-		if ( WC()->cart->needs_shipping() ) {
621
+		if (WC()->cart->needs_shipping()) {
622 622
 			$items[] = array(
623 623
 				'type'   => 'final',
624
-				'label'  => __( 'Shipping', 'woocommerce-gateway-stripe' ),
624
+				'label'  => __('Shipping', 'woocommerce-gateway-stripe'),
625 625
 				'amount' => $shipping,
626 626
 			);
627 627
 		}
628 628
 
629
-		if ( WC()->cart->has_discount() ) {
629
+		if (WC()->cart->has_discount()) {
630 630
 			$items[] = array(
631 631
 				'type'   => 'final',
632
-				'label'  => __( 'Discount', 'woocommerce-gateway-stripe' ),
632
+				'label'  => __('Discount', 'woocommerce-gateway-stripe'),
633 633
 				'amount' => $discounts,
634 634
 			);
635 635
 		}
@@ -645,24 +645,24 @@  discard block
 block discarded – undo
645 645
 	 * @param array $data
646 646
 	 * @return object $order
647 647
 	 */
648
-	public function create_order( $data = array() ) {
649
-		if ( empty( $data ) ) {
650
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
648
+	public function create_order($data = array()) {
649
+		if (empty($data)) {
650
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
651 651
 		}
652 652
 
653 653
 		$order = wc_create_order();
654 654
 
655
-		if ( is_wp_error( $order ) ) {
656
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
657
-		} elseif ( false === $order ) {
658
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
655
+		if (is_wp_error($order)) {
656
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
657
+		} elseif (false === $order) {
658
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
659 659
 		} else {
660 660
 			$order_id = $order->id;
661
-			do_action( 'woocommerce_new_order', $order_id );
661
+			do_action('woocommerce_new_order', $order_id);
662 662
 		}
663 663
 
664 664
 		// Store the line items to the new/resumed order
665
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
665
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
666 666
 			$item_id = $order->add_product(
667 667
 				$values['data'],
668 668
 				$values['quantity'],
@@ -678,47 +678,47 @@  discard block
 block discarded – undo
678 678
 				)
679 679
 			);
680 680
 
681
-			if ( ! $item_id ) {
682
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
681
+			if ( ! $item_id) {
682
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
683 683
 			}
684 684
 
685 685
 			// Allow plugins to add order item meta
686
-			do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
686
+			do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
687 687
 		}
688 688
 
689 689
 		// Store fees
690
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
691
-			$item_id = $order->add_fee( $fee );
690
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
691
+			$item_id = $order->add_fee($fee);
692 692
 
693
-			if ( ! $item_id ) {
694
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
693
+			if ( ! $item_id) {
694
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
695 695
 			}
696 696
 
697 697
 			// Allow plugins to add order item meta to fees
698
-			do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
698
+			do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
699 699
 		}
700 700
 
701 701
 		// Store tax rows
702
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
703
-			if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
704
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
702
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
703
+			if ($tax_rate_id && ! $order->add_tax($tax_rate_id, WC()->cart->get_tax_amount($tax_rate_id), WC()->cart->get_shipping_tax_amount($tax_rate_id)) && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
704
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
705 705
 			}
706 706
 		}
707 707
 
708 708
 		// Store coupons
709
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
710
-			if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
711
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
709
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
710
+			if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) {
711
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
712 712
 			}
713 713
 		}
714 714
 
715 715
 		// Billing address
716 716
 		$billing_address = array();
717
-		if ( ! empty( $data['token']['card'] ) ) {
717
+		if ( ! empty($data['token']['card'])) {
718 718
 			// Name from Stripe is a full name string.
719
-			$name                          = explode( ' ', $data['token']['card']['name'] );
720
-			$lastname                      = array_pop( $name );
721
-			$firstname                     = implode( ' ', $name );
719
+			$name                          = explode(' ', $data['token']['card']['name']);
720
+			$lastname                      = array_pop($name);
721
+			$firstname                     = implode(' ', $name);
722 722
 			$billing_address['first_name'] = $firstname;
723 723
 			$billing_address['last_name']  = $lastname;
724 724
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 
734 734
 		// Shipping address.
735 735
 		$shipping_address = array();
736
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
736
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
737 737
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
738 738
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
739 739
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 			$shipping_address['city']       = $data['shippingContact']['locality'];
745 745
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
746 746
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
747
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
747
+		} elseif ( ! empty($data['shippingContact'])) {
748 748
 			$shipping_address['first_name'] = $firstname;
749 749
 			$shipping_address['last_name']  = $lastname;
750 750
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -757,34 +757,34 @@  discard block
 block discarded – undo
757 757
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
758 758
 		}
759 759
 
760
-		$order->set_address( $billing_address, 'billing' );
761
-		$order->set_address( $shipping_address, 'shipping' );
760
+		$order->set_address($billing_address, 'billing');
761
+		$order->set_address($shipping_address, 'shipping');
762 762
 
763
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
763
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
764 764
 
765 765
 		// Get the rate object selected by user.
766
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
767
-			foreach ( $package['rates'] as $key => $rate ) {
766
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
767
+			foreach ($package['rates'] as $key => $rate) {
768 768
 				// Loop through user chosen shipping methods.
769
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
770
-					if ( $method === $key ) {
771
-						$order->add_shipping( $rate );
769
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
770
+					if ($method === $key) {
771
+						$order->add_shipping($rate);
772 772
 					}
773 773
 				}
774 774
 			}
775 775
 		}
776 776
 
777 777
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
778
-		$order->set_payment_method( $available_gateways['stripe'] );
779
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
780
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
781
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
782
-		$order->set_total( WC()->cart->tax_total, 'tax' );
783
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
784
-		$order->set_total( WC()->cart->total );
778
+		$order->set_payment_method($available_gateways['stripe']);
779
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
780
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
781
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
782
+		$order->set_total(WC()->cart->tax_total, 'tax');
783
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
784
+		$order->set_total(WC()->cart->total);
785 785
 
786 786
 		// If we got here, the order was created without problems!
787
-		wc_transaction_query( 'commit' );
787
+		wc_transaction_query('commit');
788 788
 
789 789
 		return $order;
790 790
 	}
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -25,21 +25,21 @@  discard block
 block discarded – undo
25 25
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 26
 */
27 27
 
28
-if ( ! defined( 'ABSPATH' ) ) {
28
+if ( ! defined('ABSPATH')) {
29 29
 	exit;
30 30
 }
31 31
 
32 32
 /**
33 33
  * Required minimums and constants
34 34
  */
35
-define( 'WC_STRIPE_VERSION', '3.0.6' );
36
-define( 'WC_STRIPE_MIN_PHP_VER', '5.3.0' );
37
-define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' );
38
-define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
39
-define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
40
-define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
35
+define('WC_STRIPE_VERSION', '3.0.6');
36
+define('WC_STRIPE_MIN_PHP_VER', '5.3.0');
37
+define('WC_STRIPE_MIN_WC_VER', '2.5.0');
38
+define('WC_STRIPE_MAIN_FILE', __FILE__);
39
+define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
40
+define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
41 41
 
42
-if ( ! class_exists( 'WC_Stripe' ) ) :
42
+if ( ! class_exists('WC_Stripe')) :
43 43
 
44 44
 	class WC_Stripe {
45 45
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		 * @return Singleton The *Singleton* instance.
60 60
 		 */
61 61
 		public static function get_instance() {
62
-			if ( null === self::$instance ) {
62
+			if (null === self::$instance) {
63 63
 				self::$instance = new self();
64 64
 			}
65 65
 			return self::$instance;
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 		 * *Singleton* via the `new` operator from outside of this class.
109 109
 		 */
110 110
 		protected function __construct() {
111
-			add_action( 'admin_init', array( $this, 'check_environment' ) );
112
-			add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
113
-			add_action( 'plugins_loaded', array( $this, 'init' ) );
111
+			add_action('admin_init', array($this, 'check_environment'));
112
+			add_action('admin_notices', array($this, 'admin_notices'), 15);
113
+			add_action('plugins_loaded', array($this, 'init'));
114 114
 		}
115 115
 
116 116
 		/**
@@ -118,33 +118,33 @@  discard block
 block discarded – undo
118 118
 		 */
119 119
 		public function init() {
120 120
 			// Don't hook anything else in the plugin if we're in an incompatible environment
121
-			if ( self::get_environment_warning() ) {
121
+			if (self::get_environment_warning()) {
122 122
 				return;
123 123
 			}
124 124
 
125
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
126
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
125
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
126
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
127 127
 
128 128
 			// Init the gateway itself
129 129
 			$this->init_gateways();
130 130
 
131
-			add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
132
-			add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
133
-			add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
134
-			add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
135
-			add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
136
-			add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
137
-			add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
138
-			add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );
131
+			add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
132
+			add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
133
+			add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
134
+			add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
135
+			add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
136
+			add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
137
+			add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
138
+			add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));
139 139
 
140
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' );
140
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php');
141 141
 		}
142 142
 
143 143
 		/**
144 144
 		 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
145 145
 		 */
146
-		public function add_admin_notice( $slug, $class, $message ) {
147
-			$this->notices[ $slug ] = array(
146
+		public function add_admin_notice($slug, $class, $message) {
147
+			$this->notices[$slug] = array(
148 148
 				'class'   => $class,
149 149
 				'message' => $message,
150 150
 			);
@@ -157,21 +157,21 @@  discard block
 block discarded – undo
157 157
 		public function check_environment() {
158 158
 			$environment_warning = self::get_environment_warning();
159 159
 
160
-			if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
161
-				$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
160
+			if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
161
+				$this->add_admin_notice('bad_environment', 'error', $environment_warning);
162 162
 			}
163 163
 
164 164
 			// Check if secret key present. Otherwise prompt, via notice, to go to
165 165
 			// setting.
166
-			if ( ! class_exists( 'WC_Stripe_API' ) ) {
167
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
166
+			if ( ! class_exists('WC_Stripe_API')) {
167
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
168 168
 			}
169 169
 
170 170
 			$secret = WC_Stripe_API::get_secret_key();
171 171
 
172
-			if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
172
+			if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
173 173
 				$setting_link = $this->get_setting_link();
174
-				$this->add_admin_notice( 'prompt_connect', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ) );
174
+				$this->add_admin_notice('prompt_connect', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link));
175 175
 			}
176 176
 		}
177 177
 
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
 		 * found or false if the environment has no problems.
181 181
 		 */
182 182
 		static function get_environment_warning() {
183
-			if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
184
-				$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
183
+			if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
184
+				$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
185 185
 
186
-				return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
186
+				return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
187 187
 			}
188 188
 
189
-			if ( ! defined( 'WC_VERSION' ) ) {
190
-				return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
189
+			if ( ! defined('WC_VERSION')) {
190
+				return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
191 191
 			}
192 192
 
193
-			if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
194
-				$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
193
+			if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
194
+				$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
195 195
 
196
-				return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
196
+				return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
197 197
 			}
198 198
 
199
-			if ( ! function_exists( 'curl_init' ) ) {
200
-				return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
199
+			if ( ! function_exists('curl_init')) {
200
+				return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
201 201
 			}
202 202
 
203 203
 			return false;
@@ -208,15 +208,15 @@  discard block
 block discarded – undo
208 208
 		 *
209 209
 		 * @since 1.0.0
210 210
 		 */
211
-		public function plugin_action_links( $links ) {
211
+		public function plugin_action_links($links) {
212 212
 			$setting_link = $this->get_setting_link();
213 213
 
214 214
 			$plugin_links = array(
215
-				'<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
216
-				'<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
217
-				'<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
215
+				'<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>',
216
+				'<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>',
217
+				'<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>',
218 218
 			);
219
-			return array_merge( $plugin_links, $links );
219
+			return array_merge($plugin_links, $links);
220 220
 		}
221 221
 
222 222
 		/**
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
 		 * @return string Setting link
228 228
 		 */
229 229
 		public function get_setting_link() {
230
-			$use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
230
+			$use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
231 231
 
232
-			$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
232
+			$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
233 233
 
234
-			return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
234
+			return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
235 235
 		}
236 236
 
237 237
 		/**
238 238
 		 * Display any notices we've collected thus far (e.g. for connection, disconnection)
239 239
 		 */
240 240
 		public function admin_notices() {
241
-			foreach ( (array) $this->notices as $notice_key => $notice ) {
242
-				echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
243
-				echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
241
+			foreach ((array) $this->notices as $notice_key => $notice) {
242
+				echo "<div class='" . esc_attr($notice['class']) . "'><p>";
243
+				echo wp_kses($notice['message'], array('a' => array('href' => array())));
244 244
 				echo '</p></div>';
245 245
 			}
246 246
 		}
@@ -251,31 +251,31 @@  discard block
 block discarded – undo
251 251
 		 * @since 1.0.0
252 252
 		 */
253 253
 		public function init_gateways() {
254
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
254
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
255 255
 				$this->subscription_support_enabled = true;
256 256
 			}
257 257
 
258
-			if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
258
+			if (class_exists('WC_Pre_Orders_Order')) {
259 259
 				$this->pre_order_enabled = true;
260 260
 			}
261 261
 
262
-			if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
262
+			if ( ! class_exists('WC_Payment_Gateway')) {
263 263
 				return;
264 264
 			}
265 265
 
266
-			if ( class_exists( 'WC_Payment_Gateway_CC' ) ) {
267
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
268
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' );
266
+			if (class_exists('WC_Payment_Gateway_CC')) {
267
+				include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
268
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php');
269 269
 			} else {
270
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' );
271
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' );
270
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php');
271
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php');
272 272
 			}
273 273
 
274
-			load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
275
-			add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
274
+			load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
275
+			add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
276 276
 
277
-			if ( is_admin() ) {
278
-				add_action( 'wp_ajax_wc_stripe_apple_pay_domain', 'WC_Stripe_Apple_Pay::process_apple_pay_domain' );
277
+			if (is_admin()) {
278
+				add_action('wp_ajax_wc_stripe_apple_pay_domain', 'WC_Stripe_Apple_Pay::process_apple_pay_domain');
279 279
 			}
280 280
 			
281 281
 			$load_addons = (
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 				$this->pre_order_enabled
285 285
 			);
286 286
 
287
-			if ( $load_addons ) {
288
-				require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' );
287
+			if ($load_addons) {
288
+				require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php');
289 289
 			}
290 290
 		}
291 291
 
@@ -294,8 +294,8 @@  discard block
 block discarded – undo
294 294
 		 *
295 295
 		 * @since 1.0.0
296 296
 		 */
297
-		public function add_gateways( $methods ) {
298
-			if ( $this->subscription_support_enabled || $this->pre_order_enabled ) {
297
+		public function add_gateways($methods) {
298
+			if ($this->subscription_support_enabled || $this->pre_order_enabled) {
299 299
 				$methods[] = 'WC_Gateway_Stripe_Addons';
300 300
 			} else {
301 301
 				$methods[] = 'WC_Gateway_Stripe';
@@ -308,35 +308,35 @@  discard block
 block discarded – undo
308 308
 		 *
309 309
 		 * @param  int $order_id
310 310
 		 */
311
-		public function capture_payment( $order_id ) {
312
-			$order = wc_get_order( $order_id );
311
+		public function capture_payment($order_id) {
312
+			$order = wc_get_order($order_id);
313 313
 
314
-			if ( 'stripe' === $order->payment_method ) {
315
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
316
-				$captured = get_post_meta( $order_id, '_stripe_charge_captured', true );
314
+			if ('stripe' === $order->payment_method) {
315
+				$charge   = get_post_meta($order_id, '_stripe_charge_id', true);
316
+				$captured = get_post_meta($order_id, '_stripe_charge_captured', true);
317 317
 
318
-				if ( $charge && 'no' === $captured ) {
319
-					$result = WC_Stripe_API::request( array(
318
+				if ($charge && 'no' === $captured) {
319
+					$result = WC_Stripe_API::request(array(
320 320
 						'amount'   => $order->get_total() * 100,
321 321
 						'expand[]' => 'balance_transaction',
322
-					), 'charges/' . $charge . '/capture' );
322
+					), 'charges/' . $charge . '/capture');
323 323
 
324
-					if ( is_wp_error( $result ) ) {
325
-						$order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
324
+					if (is_wp_error($result)) {
325
+						$order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
326 326
 					} else {
327
-						$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
328
-						update_post_meta( $order->id, '_stripe_charge_captured', 'yes' );
327
+						$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
328
+						update_post_meta($order->id, '_stripe_charge_captured', 'yes');
329 329
 
330 330
 						// Store other data such as fees
331
-						update_post_meta( $order->id, 'Stripe Payment ID', $result->id );
331
+						update_post_meta($order->id, 'Stripe Payment ID', $result->id);
332 332
 
333
-						if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
333
+						if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
334 334
 							// Fees and Net needs to both come from Stripe to be accurate as the returned
335 335
 							// values are in the local currency of the Stripe account, not from WC.
336
-							$fee = ! empty( $result->balance_transaction->fee ) ? number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) : 0;
337
-							$net = ! empty( $result->balance_transaction->net ) ? number_format( $result->balance_transaction->net / 100, 2, '.', '' ) : 0;
338
-							update_post_meta( $order->id, 'Stripe Fee', $fee );
339
-							update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
336
+							$fee = ! empty($result->balance_transaction->fee) ? number_format($result->balance_transaction->fee / 100, 2, '.', '') : 0;
337
+							$net = ! empty($result->balance_transaction->net) ? number_format($result->balance_transaction->net / 100, 2, '.', '') : 0;
338
+							update_post_meta($order->id, 'Stripe Fee', $fee);
339
+							update_post_meta($order->id, 'Net Revenue From Stripe', $net);
340 340
 						}
341 341
 					}
342 342
 				}
@@ -348,23 +348,23 @@  discard block
 block discarded – undo
348 348
 		 *
349 349
 		 * @param  int $order_id
350 350
 		 */
351
-		public function cancel_payment( $order_id ) {
352
-			$order = wc_get_order( $order_id );
351
+		public function cancel_payment($order_id) {
352
+			$order = wc_get_order($order_id);
353 353
 
354
-			if ( 'stripe' === $order->payment_method ) {
355
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
354
+			if ('stripe' === $order->payment_method) {
355
+				$charge = get_post_meta($order_id, '_stripe_charge_id', true);
356 356
 
357
-				if ( $charge ) {
358
-					$result = WC_Stripe_API::request( array(
357
+				if ($charge) {
358
+					$result = WC_Stripe_API::request(array(
359 359
 						'amount' => $order->get_total() * 100,
360
-					), 'charges/' . $charge . '/refund' );
360
+					), 'charges/' . $charge . '/refund');
361 361
 
362
-					if ( is_wp_error( $result ) ) {
363
-						$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
362
+					if (is_wp_error($result)) {
363
+						$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
364 364
 					} else {
365
-						$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
366
-						delete_post_meta( $order->id, '_stripe_charge_captured' );
367
-						delete_post_meta( $order->id, '_stripe_charge_id' );
365
+						$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
366
+						delete_post_meta($order->id, '_stripe_charge_captured');
367
+						delete_post_meta($order->id, '_stripe_charge_id');
368 368
 					}
369 369
 				}
370 370
 			}
@@ -375,28 +375,28 @@  discard block
 block discarded – undo
375 375
 		 * @param array $tokens
376 376
 		 * @return array
377 377
 		 */
378
-		public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) {
379
-			if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) {
380
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
378
+		public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) {
379
+			if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) {
380
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
381 381
 				$stripe_cards    = $stripe_customer->get_cards();
382 382
 				$stored_tokens   = array();
383 383
 
384
-				foreach ( $tokens as $token ) {
384
+				foreach ($tokens as $token) {
385 385
 					$stored_tokens[] = $token->get_token();
386 386
 				}
387 387
 
388
-				foreach ( $stripe_cards as $card ) {
389
-					if ( ! in_array( $card->id, $stored_tokens ) ) {
388
+				foreach ($stripe_cards as $card) {
389
+					if ( ! in_array($card->id, $stored_tokens)) {
390 390
 						$token = new WC_Payment_Token_CC();
391
-						$token->set_token( $card->id );
392
-						$token->set_gateway_id( 'stripe' );
393
-						$token->set_card_type( strtolower( $card->brand ) );
394
-						$token->set_last4( $card->last4 );
395
-						$token->set_expiry_month( $card->exp_month );
396
-						$token->set_expiry_year( $card->exp_year );
397
-						$token->set_user_id( $customer_id );
391
+						$token->set_token($card->id);
392
+						$token->set_gateway_id('stripe');
393
+						$token->set_card_type(strtolower($card->brand));
394
+						$token->set_last4($card->last4);
395
+						$token->set_expiry_month($card->exp_month);
396
+						$token->set_expiry_year($card->exp_year);
397
+						$token->set_user_id($customer_id);
398 398
 						$token->save();
399
-						$tokens[ $token->get_id() ] = $token;
399
+						$tokens[$token->get_id()] = $token;
400 400
 					}
401 401
 				}
402 402
 			}
@@ -406,21 +406,21 @@  discard block
 block discarded – undo
406 406
 		/**
407 407
 		 * Delete token from Stripe
408 408
 		 */
409
-		public function woocommerce_payment_token_deleted( $token_id, $token ) {
410
-			if ( 'stripe' === $token->get_gateway_id() ) {
411
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
412
-				$stripe_customer->delete_card( $token->get_token() );
409
+		public function woocommerce_payment_token_deleted($token_id, $token) {
410
+			if ('stripe' === $token->get_gateway_id()) {
411
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
412
+				$stripe_customer->delete_card($token->get_token());
413 413
 			}
414 414
 		}
415 415
 
416 416
 		/**
417 417
 		 * Set as default in Stripe
418 418
 		 */
419
-		public function woocommerce_payment_token_set_default( $token_id ) {
420
-			$token = WC_Payment_Tokens::get( $token_id );
421
-			if ( 'stripe' === $token->get_gateway_id() ) {
422
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
423
-				$stripe_customer->set_default_card( $token->get_token() );
419
+		public function woocommerce_payment_token_set_default($token_id) {
420
+			$token = WC_Payment_Tokens::get($token_id);
421
+			if ('stripe' === $token->get_gateway_id()) {
422
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
423
+				$stripe_customer->set_default_card($token->get_token());
424 424
 			}
425 425
 		}
426 426
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 		 */
430 430
 		public static function get_minimum_amount() {
431 431
 			// Check order amount
432
-			switch ( get_woocommerce_currency() ) {
432
+			switch (get_woocommerce_currency()) {
433 433
 				case 'USD':
434 434
 				case 'CAD':
435 435
 				case 'EUR':
@@ -473,12 +473,12 @@  discard block
 block discarded – undo
473 473
 		 * And fits on your back?
474 474
 		 * It's log, log, log
475 475
 		 */
476
-		public static function log( $message ) {
477
-			if ( empty( self::$log ) ) {
476
+		public static function log($message) {
477
+			if (empty(self::$log)) {
478 478
 				self::$log = new WC_Logger();
479 479
 			}
480 480
 
481
-			self::$log->add( 'woocommerce-gateway-stripe', $message );
481
+			self::$log->add('woocommerce-gateway-stripe', $message);
482 482
 		}
483 483
 	}
484 484
 
Please login to merge, or discard this patch.