@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | * @param int $user_id The WP user ID |
34 | 34 | */ |
35 | - public function __construct( $user_id = 0 ) { |
|
36 | - if ( $user_id ) { |
|
37 | - $this->set_user_id( $user_id ); |
|
38 | - $this->set_id( $this->get_id_from_meta( $user_id ) ); |
|
35 | + public function __construct($user_id = 0) { |
|
36 | + if ($user_id) { |
|
37 | + $this->set_user_id($user_id); |
|
38 | + $this->set_id($this->get_id_from_meta($user_id)); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
54 | + public function set_id($id) { |
|
55 | 55 | // Backwards compat for customer ID stored in array format. (Pre 3.0) |
56 | - if ( is_array( $id ) && isset( $id['customer_id'] ) ) { |
|
56 | + if (is_array($id) && isset($id['customer_id'])) { |
|
57 | 57 | $id = $id['customer_id']; |
58 | 58 | |
59 | - $this->update_id_in_meta( $id ); |
|
59 | + $this->update_id_in_meta($id); |
|
60 | 60 | } |
61 | 61 | |
62 | - $this->id = wc_clean( $id ); |
|
62 | + $this->id = wc_clean($id); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | * @return int |
68 | 68 | */ |
69 | 69 | public function get_user_id() { |
70 | - return absint( $this->user_id ); |
|
70 | + return absint($this->user_id); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Set User ID used by WordPress. |
75 | 75 | * @param int $user_id |
76 | 76 | */ |
77 | - public function set_user_id( $user_id ) { |
|
78 | - $this->user_id = absint( $user_id ); |
|
77 | + public function set_user_id($user_id) { |
|
78 | + $this->user_id = absint($user_id); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -83,13 +83,13 @@ discard block |
||
83 | 83 | * @return WP_User |
84 | 84 | */ |
85 | 85 | protected function get_user() { |
86 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
86 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | 90 | * Store data from the Stripe API about this customer |
91 | 91 | */ |
92 | - public function set_customer_data( $data ) { |
|
92 | + public function set_customer_data($data) { |
|
93 | 93 | $this->customer_data = $data; |
94 | 94 | } |
95 | 95 | |
@@ -99,37 +99,37 @@ discard block |
||
99 | 99 | * @param array $args Additional arguments (optional). |
100 | 100 | * @return array |
101 | 101 | */ |
102 | - protected function generate_customer_request( $args = array() ) { |
|
103 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
102 | + protected function generate_customer_request($args = array()) { |
|
103 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
104 | 104 | $user = $this->get_user(); |
105 | 105 | |
106 | - if ( $user ) { |
|
107 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
108 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
106 | + if ($user) { |
|
107 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
108 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
109 | 109 | |
110 | 110 | // If billing first name does not exists try the user first name. |
111 | - if ( empty( $billing_first_name ) ) { |
|
112 | - $billing_first_name = get_user_meta( $user->ID, 'first_name', true ); |
|
111 | + if (empty($billing_first_name)) { |
|
112 | + $billing_first_name = get_user_meta($user->ID, 'first_name', true); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | // If billing last name does not exists try the user last name. |
116 | - if ( empty( $billing_last_name ) ) { |
|
117 | - $billing_last_name = get_user_meta( $user->ID, 'last_name', true ); |
|
116 | + if (empty($billing_last_name)) { |
|
117 | + $billing_last_name = get_user_meta($user->ID, 'last_name', true); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | // translators: %1$s First name, %2$s Second name, %3$s Username. |
121 | - $description = sprintf( __( 'Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name, $user->user_login ); |
|
121 | + $description = sprintf(__('Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name, $user->user_login); |
|
122 | 122 | |
123 | 123 | $defaults = array( |
124 | 124 | 'email' => $user->user_email, |
125 | 125 | 'description' => $description, |
126 | 126 | ); |
127 | 127 | } else { |
128 | - $billing_first_name = isset( $_POST['billing_first_name'] ) ? filter_var( wp_unslash( $_POST['billing_first_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
129 | - $billing_last_name = isset( $_POST['billing_last_name'] ) ? filter_var( wp_unslash( $_POST['billing_last_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
128 | + $billing_first_name = isset($_POST['billing_first_name']) ? filter_var(wp_unslash($_POST['billing_first_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
129 | + $billing_last_name = isset($_POST['billing_last_name']) ? filter_var(wp_unslash($_POST['billing_last_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
130 | 130 | |
131 | 131 | // translators: %1$s First name, %2$s Second name. |
132 | - $description = sprintf( __( 'Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name ); |
|
132 | + $description = sprintf(__('Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name); |
|
133 | 133 | |
134 | 134 | $defaults = array( |
135 | 135 | 'email' => $billing_email, |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | $metadata = array(); |
141 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
141 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
142 | 142 | |
143 | - return wp_parse_args( $args, $defaults ); |
|
143 | + return wp_parse_args($args, $defaults); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,23 +148,23 @@ discard block |
||
148 | 148 | * @param array $args |
149 | 149 | * @return WP_Error|int |
150 | 150 | */ |
151 | - public function create_customer( $args = array() ) { |
|
152 | - $args = $this->generate_customer_request( $args ); |
|
153 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
151 | + public function create_customer($args = array()) { |
|
152 | + $args = $this->generate_customer_request($args); |
|
153 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
154 | 154 | |
155 | - if ( ! empty( $response->error ) ) { |
|
156 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
155 | + if ( ! empty($response->error)) { |
|
156 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
157 | 157 | } |
158 | 158 | |
159 | - $this->set_id( $response->id ); |
|
159 | + $this->set_id($response->id); |
|
160 | 160 | $this->clear_cache(); |
161 | - $this->set_customer_data( $response ); |
|
161 | + $this->set_customer_data($response); |
|
162 | 162 | |
163 | - if ( $this->get_user_id() ) { |
|
164 | - $this->update_id_in_meta( $response->id ); |
|
163 | + if ($this->get_user_id()) { |
|
164 | + $this->update_id_in_meta($response->id); |
|
165 | 165 | } |
166 | 166 | |
167 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
167 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
168 | 168 | |
169 | 169 | return $response->id; |
170 | 170 | } |
@@ -174,43 +174,43 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @param array $args Additional arguments for the request (optional). |
176 | 176 | */ |
177 | - public function update_customer( $args = array() ) { |
|
178 | - if ( empty( $this->get_id() ) ) { |
|
179 | - throw new WC_Stripe_Exception( 'id_required_to_update_user', __( 'Attempting to update a Stripe customer without a customer ID.', 'woocommerce-gateway-stripe' ) ); |
|
177 | + public function update_customer($args = array()) { |
|
178 | + if (empty($this->get_id())) { |
|
179 | + throw new WC_Stripe_Exception('id_required_to_update_user', __('Attempting to update a Stripe customer without a customer ID.', 'woocommerce-gateway-stripe')); |
|
180 | 180 | } |
181 | 181 | |
182 | - $args = $this->generate_customer_request( $args ); |
|
183 | - $args = apply_filters( 'wc_stripe_update_customer_args', $args ); |
|
184 | - $response = WC_Stripe_API::request( $args, 'customers/' . $this->get_id() ); |
|
182 | + $args = $this->generate_customer_request($args); |
|
183 | + $args = apply_filters('wc_stripe_update_customer_args', $args); |
|
184 | + $response = WC_Stripe_API::request($args, 'customers/' . $this->get_id()); |
|
185 | 185 | |
186 | - if ( ! empty( $response->error ) ) { |
|
187 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
186 | + if ( ! empty($response->error)) { |
|
187 | + if ($this->is_no_such_customer_error($response->error)) { |
|
188 | 188 | $message = $response->error->message; |
189 | 189 | |
190 | - if ( ! preg_match( '/similar object exists/i', $message ) ) { |
|
191 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
192 | - $testmode = isset( $options['testmode'] ) && 'yes' === $options['testmode']; |
|
190 | + if ( ! preg_match('/similar object exists/i', $message)) { |
|
191 | + $options = get_option('woocommerce_stripe_settings'); |
|
192 | + $testmode = isset($options['testmode']) && 'yes' === $options['testmode']; |
|
193 | 193 | |
194 | 194 | $message = sprintf( |
195 | - ( $testmode |
|
195 | + ($testmode |
|
196 | 196 | // Translators: %s is a message, which states that no such customer exists, without a full stop at the end. |
197 | - ? __( '%s. Was the customer created in live mode? ', 'woocommerce-gateway-stripe' ) |
|
197 | + ? __('%s. Was the customer created in live mode? ', 'woocommerce-gateway-stripe') |
|
198 | 198 | // Translators: %s is a message, which states that no such customer exists, without a full stop at the end. |
199 | - : __( '%s. Was the customer created in test mode? ', 'woocommerce-gateway-stripe' ) ), |
|
199 | + : __('%s. Was the customer created in test mode? ', 'woocommerce-gateway-stripe')), |
|
200 | 200 | $message |
201 | 201 | ); |
202 | 202 | } |
203 | 203 | |
204 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
204 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
205 | 205 | } |
206 | 206 | |
207 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
207 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | $this->clear_cache(); |
211 | - $this->set_customer_data( $response ); |
|
211 | + $this->set_customer_data($response); |
|
212 | 212 | |
213 | - do_action( 'woocommerce_stripe_update_customer', $args, $response ); |
|
213 | + do_action('woocommerce_stripe_update_customer', $args, $response); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -220,11 +220,11 @@ discard block |
||
220 | 220 | * @since 4.1.2 |
221 | 221 | * @param array $error |
222 | 222 | */ |
223 | - public function is_no_such_customer_error( $error ) { |
|
223 | + public function is_no_such_customer_error($error) { |
|
224 | 224 | return ( |
225 | 225 | $error && |
226 | 226 | 'invalid_request_error' === $error->type && |
227 | - preg_match( '/No such customer/i', $error->message ) |
|
227 | + preg_match('/No such customer/i', $error->message) |
|
228 | 228 | ); |
229 | 229 | } |
230 | 230 | |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | * @param string $source_id |
234 | 234 | * @return WP_Error|int |
235 | 235 | */ |
236 | - public function add_source( $source_id ) { |
|
237 | - if ( ! $this->get_id() ) { |
|
238 | - $this->set_id( $this->create_customer() ); |
|
236 | + public function add_source($source_id) { |
|
237 | + if ( ! $this->get_id()) { |
|
238 | + $this->set_id($this->create_customer()); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | $response = WC_Stripe_API::request( |
@@ -247,63 +247,63 @@ discard block |
||
247 | 247 | |
248 | 248 | $wc_token = false; |
249 | 249 | |
250 | - if ( ! empty( $response->error ) ) { |
|
250 | + if ( ! empty($response->error)) { |
|
251 | 251 | // It is possible the WC user once was linked to a customer on Stripe |
252 | 252 | // but no longer exists. Instead of failing, lets try to create a |
253 | 253 | // new customer. |
254 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
254 | + if ($this->is_no_such_customer_error($response->error)) { |
|
255 | 255 | $this->delete_id_from_meta(); |
256 | 256 | $this->create_customer(); |
257 | - return $this->add_source( $source_id ); |
|
257 | + return $this->add_source($source_id); |
|
258 | 258 | } else { |
259 | 259 | return $response; |
260 | 260 | } |
261 | - } elseif ( empty( $response->id ) ) { |
|
262 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
261 | + } elseif (empty($response->id)) { |
|
262 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | // Add token to WooCommerce. |
266 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
267 | - if ( ! empty( $response->type ) ) { |
|
268 | - switch ( $response->type ) { |
|
266 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
267 | + if ( ! empty($response->type)) { |
|
268 | + switch ($response->type) { |
|
269 | 269 | case 'alipay': |
270 | 270 | break; |
271 | 271 | case 'sepa_debit': |
272 | 272 | $wc_token = new WC_Payment_Token_SEPA(); |
273 | - $wc_token->set_token( $response->id ); |
|
274 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
275 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
273 | + $wc_token->set_token($response->id); |
|
274 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
275 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
276 | 276 | break; |
277 | 277 | default: |
278 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
278 | + if ('source' === $response->object && 'card' === $response->type) { |
|
279 | 279 | $wc_token = new WC_Payment_Token_CC(); |
280 | - $wc_token->set_token( $response->id ); |
|
281 | - $wc_token->set_gateway_id( 'stripe' ); |
|
282 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
283 | - $wc_token->set_last4( $response->card->last4 ); |
|
284 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
285 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
280 | + $wc_token->set_token($response->id); |
|
281 | + $wc_token->set_gateway_id('stripe'); |
|
282 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
283 | + $wc_token->set_last4($response->card->last4); |
|
284 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
285 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
286 | 286 | } |
287 | 287 | break; |
288 | 288 | } |
289 | 289 | } else { |
290 | 290 | // Legacy. |
291 | 291 | $wc_token = new WC_Payment_Token_CC(); |
292 | - $wc_token->set_token( $response->id ); |
|
293 | - $wc_token->set_gateway_id( 'stripe' ); |
|
294 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
295 | - $wc_token->set_last4( $response->last4 ); |
|
296 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
297 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
292 | + $wc_token->set_token($response->id); |
|
293 | + $wc_token->set_gateway_id('stripe'); |
|
294 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
295 | + $wc_token->set_last4($response->last4); |
|
296 | + $wc_token->set_expiry_month($response->exp_month); |
|
297 | + $wc_token->set_expiry_year($response->exp_year); |
|
298 | 298 | } |
299 | 299 | |
300 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
300 | + $wc_token->set_user_id($this->get_user_id()); |
|
301 | 301 | $wc_token->save(); |
302 | 302 | } |
303 | 303 | |
304 | 304 | $this->clear_cache(); |
305 | 305 | |
306 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
306 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
307 | 307 | |
308 | 308 | return $response->id; |
309 | 309 | } |
@@ -315,11 +315,11 @@ discard block |
||
315 | 315 | * @return array |
316 | 316 | */ |
317 | 317 | public function get_sources() { |
318 | - if ( ! $this->get_id() ) { |
|
318 | + if ( ! $this->get_id()) { |
|
319 | 319 | return array(); |
320 | 320 | } |
321 | 321 | |
322 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
322 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
323 | 323 | |
324 | 324 | $response = WC_Stripe_API::request( |
325 | 325 | array( |
@@ -329,32 +329,32 @@ discard block |
||
329 | 329 | 'GET' |
330 | 330 | ); |
331 | 331 | |
332 | - if ( ! empty( $response->error ) ) { |
|
332 | + if ( ! empty($response->error)) { |
|
333 | 333 | return array(); |
334 | 334 | } |
335 | 335 | |
336 | - if ( is_array( $response->data ) ) { |
|
336 | + if (is_array($response->data)) { |
|
337 | 337 | $sources = $response->data; |
338 | 338 | } |
339 | 339 | |
340 | - return empty( $sources ) ? array() : $sources; |
|
340 | + return empty($sources) ? array() : $sources; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
344 | 344 | * Delete a source from stripe. |
345 | 345 | * @param string $source_id |
346 | 346 | */ |
347 | - public function delete_source( $source_id ) { |
|
348 | - if ( ! $this->get_id() ) { |
|
347 | + public function delete_source($source_id) { |
|
348 | + if ( ! $this->get_id()) { |
|
349 | 349 | return false; |
350 | 350 | } |
351 | 351 | |
352 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
352 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
353 | 353 | |
354 | 354 | $this->clear_cache(); |
355 | 355 | |
356 | - if ( empty( $response->error ) ) { |
|
357 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
356 | + if (empty($response->error)) { |
|
357 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
358 | 358 | |
359 | 359 | return true; |
360 | 360 | } |
@@ -366,10 +366,10 @@ discard block |
||
366 | 366 | * Set default source in Stripe |
367 | 367 | * @param string $source_id |
368 | 368 | */ |
369 | - public function set_default_source( $source_id ) { |
|
369 | + public function set_default_source($source_id) { |
|
370 | 370 | $response = WC_Stripe_API::request( |
371 | 371 | array( |
372 | - 'default_source' => sanitize_text_field( $source_id ), |
|
372 | + 'default_source' => sanitize_text_field($source_id), |
|
373 | 373 | ), |
374 | 374 | 'customers/' . $this->get_id(), |
375 | 375 | 'POST' |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | |
378 | 378 | $this->clear_cache(); |
379 | 379 | |
380 | - if ( empty( $response->error ) ) { |
|
381 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
380 | + if (empty($response->error)) { |
|
381 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
382 | 382 | |
383 | 383 | return true; |
384 | 384 | } |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | * Deletes caches for this users cards. |
391 | 391 | */ |
392 | 392 | public function clear_cache() { |
393 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
394 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
393 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
394 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
395 | 395 | $this->customer_data = array(); |
396 | 396 | } |
397 | 397 | |
@@ -401,8 +401,8 @@ discard block |
||
401 | 401 | * @param int $user_id The ID of the WordPress user. |
402 | 402 | * @return string|bool Either the Stripe ID or false. |
403 | 403 | */ |
404 | - public function get_id_from_meta( $user_id ) { |
|
405 | - return get_user_option( '_stripe_customer_id', $user_id ); |
|
404 | + public function get_id_from_meta($user_id) { |
|
405 | + return get_user_option('_stripe_customer_id', $user_id); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
@@ -410,14 +410,14 @@ discard block |
||
410 | 410 | * |
411 | 411 | * @param string $id The Stripe customer ID. |
412 | 412 | */ |
413 | - public function update_id_in_meta( $id ) { |
|
414 | - update_user_option( $this->get_user_id(), '_stripe_customer_id', $id, false ); |
|
413 | + public function update_id_in_meta($id) { |
|
414 | + update_user_option($this->get_user_id(), '_stripe_customer_id', $id, false); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
418 | 418 | * Deletes the user ID from the meta table with the right key. |
419 | 419 | */ |
420 | 420 | public function delete_id_from_meta() { |
421 | - delete_user_option( $this->get_user_id(), '_stripe_customer_id', false ); |
|
421 | + delete_user_option($this->get_user_id(), '_stripe_customer_id', false); |
|
422 | 422 | } |
423 | 423 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct() { |
41 | 41 | $this->retry_interval = 2; |
42 | - $stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
43 | - $this->testmode = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false; |
|
44 | - $secret_key = ( $this->testmode ? 'test_' : '' ) . 'webhook_secret'; |
|
45 | - $this->secret = ! empty( $stripe_settings[ $secret_key ] ) ? $stripe_settings[ $secret_key ] : false; |
|
42 | + $stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
43 | + $this->testmode = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false; |
|
44 | + $secret_key = ($this->testmode ? 'test_' : '') . 'webhook_secret'; |
|
45 | + $this->secret = ! empty($stripe_settings[$secret_key]) ? $stripe_settings[$secret_key] : false; |
|
46 | 46 | |
47 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
47 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -54,24 +54,24 @@ discard block |
||
54 | 54 | * @version 4.0.0 |
55 | 55 | */ |
56 | 56 | public function check_for_webhook() { |
57 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
58 | - || ! isset( $_GET['wc-api'] ) |
|
59 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
57 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
58 | + || ! isset($_GET['wc-api']) |
|
59 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
60 | 60 | ) { |
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - $request_body = file_get_contents( 'php://input' ); |
|
65 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
64 | + $request_body = file_get_contents('php://input'); |
|
65 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
66 | 66 | |
67 | 67 | // Validate it to make sure it is legit. |
68 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
69 | - $this->process_webhook( $request_body ); |
|
70 | - status_header( 200 ); |
|
68 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
69 | + $this->process_webhook($request_body); |
|
70 | + status_header(200); |
|
71 | 71 | exit; |
72 | 72 | } else { |
73 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
74 | - status_header( 400 ); |
|
73 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
74 | + status_header(400); |
|
75 | 75 | exit; |
76 | 76 | } |
77 | 77 | } |
@@ -85,34 +85,34 @@ discard block |
||
85 | 85 | * @param string $request_body The request body from Stripe. |
86 | 86 | * @return bool |
87 | 87 | */ |
88 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
89 | - if ( null === $request_headers || null === $request_body ) { |
|
88 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
89 | + if (null === $request_headers || null === $request_body) { |
|
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
93 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | - if ( ! empty( $this->secret ) ) { |
|
97 | + if ( ! empty($this->secret)) { |
|
98 | 98 | // Check for a valid signature. |
99 | 99 | $signature_format = '/^t=(?P<timestamp>\d+)(?P<signatures>(,v\d+=[a-z0-9]+){1,2})$/'; |
100 | - if ( empty( $request_headers['STRIPE-SIGNATURE'] ) || ! preg_match( $signature_format, $request_headers['STRIPE-SIGNATURE'], $matches ) ) { |
|
100 | + if (empty($request_headers['STRIPE-SIGNATURE']) || ! preg_match($signature_format, $request_headers['STRIPE-SIGNATURE'], $matches)) { |
|
101 | 101 | return false; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // Verify the timestamp. |
105 | - $timestamp = intval( $matches['timestamp'] ); |
|
106 | - if ( abs( $timestamp - time() ) > 5 * MINUTE_IN_SECONDS ) { |
|
105 | + $timestamp = intval($matches['timestamp']); |
|
106 | + if (abs($timestamp - time()) > 5 * MINUTE_IN_SECONDS) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
110 | 110 | // Generate the expected signature. |
111 | 111 | $signed_payload = $timestamp . '.' . $request_body; |
112 | - $expected_signature = hash_hmac( 'sha256', $signed_payload, $this->secret ); |
|
112 | + $expected_signature = hash_hmac('sha256', $signed_payload, $this->secret); |
|
113 | 113 | |
114 | 114 | // Check if the expected signature is present. |
115 | - if ( ! preg_match( '/,v\d+=' . preg_quote( $expected_signature, '/' ) . '/', $matches['signatures'] ) ) { |
|
115 | + if ( ! preg_match('/,v\d+=' . preg_quote($expected_signature, '/') . '/', $matches['signatures'])) { |
|
116 | 116 | return false; |
117 | 117 | } |
118 | 118 | } |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | * @version 4.0.0 |
130 | 130 | */ |
131 | 131 | public function get_request_headers() { |
132 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
132 | + if ( ! function_exists('getallheaders')) { |
|
133 | 133 | $headers = array(); |
134 | 134 | |
135 | - foreach ( $_SERVER as $name => $value ) { |
|
136 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
137 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
135 | + foreach ($_SERVER as $name => $value) { |
|
136 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
137 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -153,30 +153,30 @@ discard block |
||
153 | 153 | * @param object $notification |
154 | 154 | * @param bool $retry |
155 | 155 | */ |
156 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
156 | + public function process_webhook_payment($notification, $retry = true) { |
|
157 | 157 | // The following 3 payment methods are synchronous so does not need to be handle via webhook. |
158 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) { |
|
158 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | 161 | |
162 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
162 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
163 | 163 | |
164 | - if ( ! $order ) { |
|
165 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
164 | + if ( ! $order) { |
|
165 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
169 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
169 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
170 | 170 | $source_id = $notification->data->object->id; |
171 | 171 | |
172 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
172 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
173 | 173 | |
174 | 174 | try { |
175 | - if ( $order->has_status( array( 'processing', 'completed' ) ) ) { |
|
175 | + if ($order->has_status(array('processing', 'completed'))) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | - if ( $order->has_status( 'on-hold' ) && ! $is_pending_receiver ) { |
|
179 | + if ($order->has_status('on-hold') && ! $is_pending_receiver) { |
|
180 | 180 | return; |
181 | 181 | } |
182 | 182 | |
@@ -184,94 +184,94 @@ discard block |
||
184 | 184 | $response = null; |
185 | 185 | |
186 | 186 | // This will throw exception if not valid. |
187 | - $this->validate_minimum_order_amount( $order ); |
|
187 | + $this->validate_minimum_order_amount($order); |
|
188 | 188 | |
189 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
189 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
190 | 190 | |
191 | 191 | // Prep source object. |
192 | 192 | $source_object = new stdClass(); |
193 | 193 | $source_object->token_id = ''; |
194 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
194 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
195 | 195 | $source_object->source = $source_id; |
196 | 196 | |
197 | 197 | // Make the request. |
198 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true ); |
|
198 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true); |
|
199 | 199 | $headers = $response['headers']; |
200 | 200 | $response = $response['body']; |
201 | 201 | |
202 | - if ( ! empty( $response->error ) ) { |
|
202 | + if ( ! empty($response->error)) { |
|
203 | 203 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
204 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
205 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
206 | - delete_user_option( $order->customer_user, '_stripe_customer_id' ); |
|
207 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
204 | + if ($this->is_no_such_customer_error($response->error)) { |
|
205 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
206 | + delete_user_option($order->customer_user, '_stripe_customer_id'); |
|
207 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
208 | 208 | } else { |
209 | - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); |
|
210 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
209 | + delete_user_option($order->get_customer_id(), '_stripe_customer_id'); |
|
210 | + $order->delete_meta_data('_stripe_customer_id'); |
|
211 | 211 | $order->save(); |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
215 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
216 | 216 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
217 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
217 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
218 | 218 | $wc_token->delete(); |
219 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
220 | - $order->add_order_note( $localized_message ); |
|
221 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
219 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
220 | + $order->add_order_note($localized_message); |
|
221 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | // We want to retry. |
225 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
226 | - if ( $retry ) { |
|
225 | + if ($this->is_retryable_error($response->error)) { |
|
226 | + if ($retry) { |
|
227 | 227 | // Don't do anymore retries after this. |
228 | - if ( 5 <= $this->retry_interval ) { |
|
228 | + if (5 <= $this->retry_interval) { |
|
229 | 229 | |
230 | - return $this->process_webhook_payment( $notification, false ); |
|
230 | + return $this->process_webhook_payment($notification, false); |
|
231 | 231 | } |
232 | 232 | |
233 | - sleep( $this->retry_interval ); |
|
233 | + sleep($this->retry_interval); |
|
234 | 234 | |
235 | 235 | $this->retry_interval++; |
236 | - return $this->process_webhook_payment( $notification, true ); |
|
236 | + return $this->process_webhook_payment($notification, true); |
|
237 | 237 | } else { |
238 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
239 | - $order->add_order_note( $localized_message ); |
|
240 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
238 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
239 | + $order->add_order_note($localized_message); |
|
240 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | 244 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
245 | 245 | |
246 | - if ( 'card_error' === $response->error->type ) { |
|
247 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
246 | + if ('card_error' === $response->error->type) { |
|
247 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
248 | 248 | } else { |
249 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
249 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
250 | 250 | } |
251 | 251 | |
252 | - $order->add_order_note( $localized_message ); |
|
252 | + $order->add_order_note($localized_message); |
|
253 | 253 | |
254 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
254 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | // To prevent double processing the order on WC side. |
258 | - if ( ! $this->is_original_request( $headers ) ) { |
|
258 | + if ( ! $this->is_original_request($headers)) { |
|
259 | 259 | return; |
260 | 260 | } |
261 | 261 | |
262 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
262 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
263 | 263 | |
264 | - $this->process_response( $response, $order ); |
|
264 | + $this->process_response($response, $order); |
|
265 | 265 | |
266 | - } catch ( WC_Stripe_Exception $e ) { |
|
267 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
266 | + } catch (WC_Stripe_Exception $e) { |
|
267 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
268 | 268 | |
269 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e ); |
|
269 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e); |
|
270 | 270 | |
271 | - $statuses = array( 'pending', 'failed' ); |
|
271 | + $statuses = array('pending', 'failed'); |
|
272 | 272 | |
273 | - if ( $order->has_status( $statuses ) ) { |
|
274 | - $this->send_failed_order_email( $order_id ); |
|
273 | + if ($order->has_status($statuses)) { |
|
274 | + $this->send_failed_order_email($order_id); |
|
275 | 275 | } |
276 | 276 | } |
277 | 277 | } |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | * @since 4.0.0 |
285 | 285 | * @param object $notification |
286 | 286 | */ |
287 | - public function process_webhook_dispute( $notification ) { |
|
288 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
287 | + public function process_webhook_dispute($notification) { |
|
288 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
289 | 289 | |
290 | - if ( ! $order ) { |
|
291 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
290 | + if ( ! $order) { |
|
291 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
292 | 292 | return; |
293 | 293 | } |
294 | 294 | |
295 | 295 | /* translators: 1) The URL to the order. */ |
296 | - $order->update_status( 'on-hold', sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ) ); |
|
296 | + $order->update_status('on-hold', sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order))); |
|
297 | 297 | |
298 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
298 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
299 | 299 | |
300 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
301 | - $this->send_failed_order_email( $order_id ); |
|
300 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
301 | + $this->send_failed_order_email($order_id); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -309,45 +309,45 @@ discard block |
||
309 | 309 | * @version 4.0.0 |
310 | 310 | * @param object $notification |
311 | 311 | */ |
312 | - public function process_webhook_capture( $notification ) { |
|
313 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
312 | + public function process_webhook_capture($notification) { |
|
313 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
314 | 314 | |
315 | - if ( ! $order ) { |
|
316 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
315 | + if ( ! $order) { |
|
316 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
317 | 317 | return; |
318 | 318 | } |
319 | 319 | |
320 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
320 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
321 | 321 | |
322 | - if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
323 | - $charge = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
324 | - $captured = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
322 | + if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) { |
|
323 | + $charge = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
324 | + $captured = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
325 | 325 | |
326 | - if ( $charge && 'no' === $captured ) { |
|
327 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
326 | + if ($charge && 'no' === $captured) { |
|
327 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
328 | 328 | |
329 | 329 | // Store other data such as fees |
330 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
330 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
331 | 331 | |
332 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
333 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
332 | + if (isset($notification->data->object->balance_transaction)) { |
|
333 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | // Check and see if capture is partial. |
337 | - if ( $this->is_partial_capture( $notification ) ) { |
|
338 | - $partial_amount = $this->get_partial_amount_to_charge( $notification ); |
|
339 | - $order->set_total( $partial_amount ); |
|
340 | - $this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction ); |
|
337 | + if ($this->is_partial_capture($notification)) { |
|
338 | + $partial_amount = $this->get_partial_amount_to_charge($notification); |
|
339 | + $order->set_total($partial_amount); |
|
340 | + $this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction); |
|
341 | 341 | /* translators: partial captured amount */ |
342 | - $order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) ); |
|
342 | + $order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount)); |
|
343 | 343 | } else { |
344 | - $order->payment_complete( $notification->data->object->id ); |
|
344 | + $order->payment_complete($notification->data->object->id); |
|
345 | 345 | |
346 | 346 | /* translators: transaction id */ |
347 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
347 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
348 | 348 | } |
349 | 349 | |
350 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
350 | + if (is_callable(array($order, 'save'))) { |
|
351 | 351 | $order->save(); |
352 | 352 | } |
353 | 353 | } |
@@ -362,43 +362,43 @@ discard block |
||
362 | 362 | * @version 4.0.0 |
363 | 363 | * @param object $notification |
364 | 364 | */ |
365 | - public function process_webhook_charge_succeeded( $notification ) { |
|
365 | + public function process_webhook_charge_succeeded($notification) { |
|
366 | 366 | // Ignore the notification for charges, created through PaymentIntents. |
367 | - if ( isset( $notification->data->object->payment_intent ) && $notification->data->object->payment_intent ) { |
|
367 | + if (isset($notification->data->object->payment_intent) && $notification->data->object->payment_intent) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | 371 | // The following payment methods are synchronous so does not need to be handle via webhook. |
372 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
372 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
373 | 373 | return; |
374 | 374 | } |
375 | 375 | |
376 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
376 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
377 | 377 | |
378 | - if ( ! $order ) { |
|
379 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
378 | + if ( ! $order) { |
|
379 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
380 | 380 | return; |
381 | 381 | } |
382 | 382 | |
383 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
383 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
384 | 384 | |
385 | - if ( ! $order->has_status( 'on-hold' ) ) { |
|
385 | + if ( ! $order->has_status('on-hold')) { |
|
386 | 386 | return; |
387 | 387 | } |
388 | 388 | |
389 | 389 | // Store other data such as fees |
390 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
390 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
391 | 391 | |
392 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
393 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
392 | + if (isset($notification->data->object->balance_transaction)) { |
|
393 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
394 | 394 | } |
395 | 395 | |
396 | - $order->payment_complete( $notification->data->object->id ); |
|
396 | + $order->payment_complete($notification->data->object->id); |
|
397 | 397 | |
398 | 398 | /* translators: transaction id */ |
399 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
399 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
400 | 400 | |
401 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
401 | + if (is_callable(array($order, 'save'))) { |
|
402 | 402 | $order->save(); |
403 | 403 | } |
404 | 404 | } |
@@ -410,24 +410,24 @@ discard block |
||
410 | 410 | * @since 4.1.5 Can handle any fail payments from any methods. |
411 | 411 | * @param object $notification |
412 | 412 | */ |
413 | - public function process_webhook_charge_failed( $notification ) { |
|
414 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
413 | + public function process_webhook_charge_failed($notification) { |
|
414 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
415 | 415 | |
416 | - if ( ! $order ) { |
|
417 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
416 | + if ( ! $order) { |
|
417 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
418 | 418 | return; |
419 | 419 | } |
420 | 420 | |
421 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
421 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
422 | 422 | |
423 | 423 | // If order status is already in failed status don't continue. |
424 | - if ( $order->has_status( 'failed' ) ) { |
|
424 | + if ($order->has_status('failed')) { |
|
425 | 425 | return; |
426 | 426 | } |
427 | 427 | |
428 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
428 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
429 | 429 | |
430 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
430 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -438,30 +438,30 @@ discard block |
||
438 | 438 | * @since 4.1.15 Add check to make sure order is processed by Stripe. |
439 | 439 | * @param object $notification |
440 | 440 | */ |
441 | - public function process_webhook_source_canceled( $notification ) { |
|
442 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
441 | + public function process_webhook_source_canceled($notification) { |
|
442 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
443 | 443 | |
444 | 444 | // If can't find order by charge ID, try source ID. |
445 | - if ( ! $order ) { |
|
446 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
445 | + if ( ! $order) { |
|
446 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
447 | 447 | |
448 | - if ( ! $order ) { |
|
449 | - WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id ); |
|
448 | + if ( ! $order) { |
|
449 | + WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id); |
|
450 | 450 | return; |
451 | 451 | } |
452 | 452 | } |
453 | 453 | |
454 | 454 | // Don't proceed if payment method isn't Stripe. |
455 | - if ( 'stripe' !== $order->get_payment_method() ) { |
|
456 | - WC_Stripe_Logger::log( 'Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id() ); |
|
455 | + if ('stripe' !== $order->get_payment_method()) { |
|
456 | + WC_Stripe_Logger::log('Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id()); |
|
457 | 457 | return; |
458 | 458 | } |
459 | 459 | |
460 | - if ( ! $order->has_status( 'cancelled' ) ) { |
|
461 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
460 | + if ( ! $order->has_status('cancelled')) { |
|
461 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
462 | 462 | } |
463 | 463 | |
464 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
464 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /** |
@@ -471,59 +471,59 @@ discard block |
||
471 | 471 | * @version 4.0.0 |
472 | 472 | * @param object $notification |
473 | 473 | */ |
474 | - public function process_webhook_refund( $notification ) { |
|
475 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
474 | + public function process_webhook_refund($notification) { |
|
475 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
476 | 476 | |
477 | - if ( ! $order ) { |
|
478 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
477 | + if ( ! $order) { |
|
478 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
479 | 479 | return; |
480 | 480 | } |
481 | 481 | |
482 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
482 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
483 | 483 | |
484 | - if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
485 | - $charge = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
486 | - $captured = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
487 | - $refund_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true ); |
|
484 | + if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) { |
|
485 | + $charge = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
486 | + $captured = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
487 | + $refund_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true); |
|
488 | 488 | |
489 | 489 | // If the refund ID matches, don't continue to prevent double refunding. |
490 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
490 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
491 | 491 | return; |
492 | 492 | } |
493 | 493 | |
494 | 494 | // Only refund captured charge. |
495 | - if ( $charge ) { |
|
496 | - $reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
495 | + if ($charge) { |
|
496 | + $reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
497 | 497 | |
498 | 498 | // Create the refund. |
499 | 499 | $refund = wc_create_refund( |
500 | 500 | array( |
501 | 501 | 'order_id' => $order_id, |
502 | - 'amount' => $this->get_refund_amount( $notification ), |
|
502 | + 'amount' => $this->get_refund_amount($notification), |
|
503 | 503 | 'reason' => $reason, |
504 | 504 | ) |
505 | 505 | ); |
506 | 506 | |
507 | - if ( is_wp_error( $refund ) ) { |
|
508 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
507 | + if (is_wp_error($refund)) { |
|
508 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
509 | 509 | } |
510 | 510 | |
511 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ) : $order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ); |
|
511 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id) : $order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id); |
|
512 | 512 | |
513 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 ); |
|
513 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount / 100); |
|
514 | 514 | |
515 | - if ( in_array( strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
516 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount ); |
|
515 | + if (in_array(strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
516 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount); |
|
517 | 517 | } |
518 | 518 | |
519 | - if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) { |
|
520 | - $this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction ); |
|
519 | + if (isset($notification->data->object->refunds->data[0]->balance_transaction)) { |
|
520 | + $this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
524 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $notification->data->object->refunds->data[0]->id, $reason ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
524 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe'), $amount, $notification->data->object->refunds->data[0]->id, $reason) : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
525 | 525 | |
526 | - $order->add_order_note( $refund_message ); |
|
526 | + $order->add_order_note($refund_message); |
|
527 | 527 | } |
528 | 528 | } |
529 | 529 | } |
@@ -534,30 +534,30 @@ discard block |
||
534 | 534 | * @since 4.0.6 |
535 | 535 | * @param object $notification |
536 | 536 | */ |
537 | - public function process_review_opened( $notification ) { |
|
538 | - if ( isset( $notification->data->object->payment_intent ) ) { |
|
539 | - $order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent ); |
|
537 | + public function process_review_opened($notification) { |
|
538 | + if (isset($notification->data->object->payment_intent)) { |
|
539 | + $order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent); |
|
540 | 540 | |
541 | - if ( ! $order ) { |
|
542 | - WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent ); |
|
541 | + if ( ! $order) { |
|
542 | + WC_Stripe_Logger::log('[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent); |
|
543 | 543 | return; |
544 | 544 | } |
545 | 545 | } else { |
546 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
546 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
547 | 547 | |
548 | - if ( ! $order ) { |
|
549 | - WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
548 | + if ( ! $order) { |
|
549 | + WC_Stripe_Logger::log('[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge); |
|
550 | 550 | return; |
551 | 551 | } |
552 | 552 | } |
553 | 553 | |
554 | 554 | /* translators: 1) The URL to the order. 2) The reason type. */ |
555 | - $message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason ); |
|
555 | + $message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason); |
|
556 | 556 | |
557 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) { |
|
558 | - $order->update_status( 'on-hold', $message ); |
|
557 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) { |
|
558 | + $order->update_status('on-hold', $message); |
|
559 | 559 | } else { |
560 | - $order->add_order_note( $message ); |
|
560 | + $order->add_order_note($message); |
|
561 | 561 | } |
562 | 562 | } |
563 | 563 | |
@@ -567,34 +567,34 @@ discard block |
||
567 | 567 | * @since 4.0.6 |
568 | 568 | * @param object $notification |
569 | 569 | */ |
570 | - public function process_review_closed( $notification ) { |
|
571 | - if ( isset( $notification->data->object->payment_intent ) ) { |
|
572 | - $order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent ); |
|
570 | + public function process_review_closed($notification) { |
|
571 | + if (isset($notification->data->object->payment_intent)) { |
|
572 | + $order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent); |
|
573 | 573 | |
574 | - if ( ! $order ) { |
|
575 | - WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent ); |
|
574 | + if ( ! $order) { |
|
575 | + WC_Stripe_Logger::log('[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent); |
|
576 | 576 | return; |
577 | 577 | } |
578 | 578 | } else { |
579 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
579 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
580 | 580 | |
581 | - if ( ! $order ) { |
|
582 | - WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
581 | + if ( ! $order) { |
|
582 | + WC_Stripe_Logger::log('[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge); |
|
583 | 583 | return; |
584 | 584 | } |
585 | 585 | } |
586 | 586 | |
587 | 587 | /* translators: 1) The reason type. */ |
588 | - $message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ); |
|
588 | + $message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason); |
|
589 | 589 | |
590 | - if ( $order->has_status( 'on-hold' ) ) { |
|
591 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) { |
|
592 | - $order->update_status( 'processing', $message ); |
|
590 | + if ($order->has_status('on-hold')) { |
|
591 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) { |
|
592 | + $order->update_status('processing', $message); |
|
593 | 593 | } else { |
594 | - $order->add_order_note( $message ); |
|
594 | + $order->add_order_note($message); |
|
595 | 595 | } |
596 | 596 | } else { |
597 | - $order->add_order_note( $message ); |
|
597 | + $order->add_order_note($message); |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | * @version 4.0.0 |
606 | 606 | * @param object $notification |
607 | 607 | */ |
608 | - public function is_partial_capture( $notification ) { |
|
608 | + public function is_partial_capture($notification) { |
|
609 | 609 | return 0 < $notification->data->object->amount_refunded; |
610 | 610 | } |
611 | 611 | |
@@ -616,11 +616,11 @@ discard block |
||
616 | 616 | * @version 4.0.0 |
617 | 617 | * @param object $notification |
618 | 618 | */ |
619 | - public function get_refund_amount( $notification ) { |
|
620 | - if ( $this->is_partial_capture( $notification ) ) { |
|
619 | + public function get_refund_amount($notification) { |
|
620 | + if ($this->is_partial_capture($notification)) { |
|
621 | 621 | $amount = $notification->data->object->refunds->data[0]->amount / 100; |
622 | 622 | |
623 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
623 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
624 | 624 | $amount = $notification->data->object->refunds->data[0]->amount; |
625 | 625 | } |
626 | 626 | |
@@ -637,12 +637,12 @@ discard block |
||
637 | 637 | * @version 4.0.0 |
638 | 638 | * @param object $notification |
639 | 639 | */ |
640 | - public function get_partial_amount_to_charge( $notification ) { |
|
641 | - if ( $this->is_partial_capture( $notification ) ) { |
|
642 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
640 | + public function get_partial_amount_to_charge($notification) { |
|
641 | + if ($this->is_partial_capture($notification)) { |
|
642 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
643 | 643 | |
644 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
645 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
644 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
645 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | return $amount; |
@@ -651,69 +651,69 @@ discard block |
||
651 | 651 | return false; |
652 | 652 | } |
653 | 653 | |
654 | - public function process_payment_intent_success( $notification ) { |
|
654 | + public function process_payment_intent_success($notification) { |
|
655 | 655 | $intent = $notification->data->object; |
656 | - $order = WC_Stripe_Helper::get_order_by_intent_id( $intent->id ); |
|
656 | + $order = WC_Stripe_Helper::get_order_by_intent_id($intent->id); |
|
657 | 657 | |
658 | - if ( ! $order ) { |
|
659 | - WC_Stripe_Logger::log( 'Could not find order via intent ID: ' . $intent->id ); |
|
658 | + if ( ! $order) { |
|
659 | + WC_Stripe_Logger::log('Could not find order via intent ID: ' . $intent->id); |
|
660 | 660 | return; |
661 | 661 | } |
662 | 662 | |
663 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
663 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
664 | 664 | return; |
665 | 665 | } |
666 | 666 | |
667 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
667 | + if ($this->lock_order_payment($order, $intent)) { |
|
668 | 668 | return; |
669 | 669 | } |
670 | 670 | |
671 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
672 | - if ( 'payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type ) { |
|
673 | - $charge = end( $intent->charges->data ); |
|
674 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" ); |
|
671 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
672 | + if ('payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type) { |
|
673 | + $charge = end($intent->charges->data); |
|
674 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id"); |
|
675 | 675 | |
676 | - do_action( 'wc_gateway_stripe_process_payment', $charge, $order ); |
|
676 | + do_action('wc_gateway_stripe_process_payment', $charge, $order); |
|
677 | 677 | |
678 | 678 | // Process valid response. |
679 | - $this->process_response( $charge, $order ); |
|
679 | + $this->process_response($charge, $order); |
|
680 | 680 | |
681 | 681 | } else { |
682 | 682 | $error_message = $intent->last_payment_error ? $intent->last_payment_error->message : ""; |
683 | 683 | |
684 | 684 | /* translators: 1) The error message that was received from Stripe. */ |
685 | - $order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) ); |
|
685 | + $order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message)); |
|
686 | 686 | |
687 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
687 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
688 | 688 | |
689 | - $this->send_failed_order_email( $order_id ); |
|
689 | + $this->send_failed_order_email($order_id); |
|
690 | 690 | } |
691 | 691 | |
692 | - $this->unlock_order_payment( $order ); |
|
692 | + $this->unlock_order_payment($order); |
|
693 | 693 | } |
694 | 694 | |
695 | - public function process_setup_intent( $notification ) { |
|
695 | + public function process_setup_intent($notification) { |
|
696 | 696 | $intent = $notification->data->object; |
697 | - $order = WC_Stripe_Helper::get_order_by_setup_intent_id( $intent->id ); |
|
697 | + $order = WC_Stripe_Helper::get_order_by_setup_intent_id($intent->id); |
|
698 | 698 | |
699 | - if ( ! $order ) { |
|
700 | - WC_Stripe_Logger::log( 'Could not find order via setup intent ID: ' . $intent->id ); |
|
699 | + if ( ! $order) { |
|
700 | + WC_Stripe_Logger::log('Could not find order via setup intent ID: ' . $intent->id); |
|
701 | 701 | return; |
702 | 702 | } |
703 | 703 | |
704 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
704 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
705 | 705 | return; |
706 | 706 | } |
707 | 707 | |
708 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
708 | + if ($this->lock_order_payment($order, $intent)) { |
|
709 | 709 | return; |
710 | 710 | } |
711 | 711 | |
712 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
713 | - if ( 'setup_intent.succeeded' === $notification->type ) { |
|
714 | - WC_Stripe_Logger::log( "Stripe SetupIntent $intent->id succeeded for order $order_id" ); |
|
715 | - if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) { |
|
716 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
712 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
713 | + if ('setup_intent.succeeded' === $notification->type) { |
|
714 | + WC_Stripe_Logger::log("Stripe SetupIntent $intent->id succeeded for order $order_id"); |
|
715 | + if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) { |
|
716 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
717 | 717 | } else { |
718 | 718 | $order->payment_complete(); |
719 | 719 | } |
@@ -721,12 +721,12 @@ discard block |
||
721 | 721 | $error_message = $intent->last_setup_error ? $intent->last_setup_error->message : ""; |
722 | 722 | |
723 | 723 | /* translators: 1) The error message that was received from Stripe. */ |
724 | - $order->update_status( 'failed', sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ) ); |
|
724 | + $order->update_status('failed', sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message)); |
|
725 | 725 | |
726 | - $this->send_failed_order_email( $order_id ); |
|
726 | + $this->send_failed_order_email($order_id); |
|
727 | 727 | } |
728 | 728 | |
729 | - $this->unlock_order_payment( $order ); |
|
729 | + $this->unlock_order_payment($order); |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | /** |
@@ -736,55 +736,55 @@ discard block |
||
736 | 736 | * @version 4.0.0 |
737 | 737 | * @param string $request_body |
738 | 738 | */ |
739 | - public function process_webhook( $request_body ) { |
|
740 | - $notification = json_decode( $request_body ); |
|
739 | + public function process_webhook($request_body) { |
|
740 | + $notification = json_decode($request_body); |
|
741 | 741 | |
742 | - switch ( $notification->type ) { |
|
742 | + switch ($notification->type) { |
|
743 | 743 | case 'source.chargeable': |
744 | - $this->process_webhook_payment( $notification ); |
|
744 | + $this->process_webhook_payment($notification); |
|
745 | 745 | break; |
746 | 746 | |
747 | 747 | case 'source.canceled': |
748 | - $this->process_webhook_source_canceled( $notification ); |
|
748 | + $this->process_webhook_source_canceled($notification); |
|
749 | 749 | break; |
750 | 750 | |
751 | 751 | case 'charge.succeeded': |
752 | - $this->process_webhook_charge_succeeded( $notification ); |
|
752 | + $this->process_webhook_charge_succeeded($notification); |
|
753 | 753 | break; |
754 | 754 | |
755 | 755 | case 'charge.failed': |
756 | - $this->process_webhook_charge_failed( $notification ); |
|
756 | + $this->process_webhook_charge_failed($notification); |
|
757 | 757 | break; |
758 | 758 | |
759 | 759 | case 'charge.captured': |
760 | - $this->process_webhook_capture( $notification ); |
|
760 | + $this->process_webhook_capture($notification); |
|
761 | 761 | break; |
762 | 762 | |
763 | 763 | case 'charge.dispute.created': |
764 | - $this->process_webhook_dispute( $notification ); |
|
764 | + $this->process_webhook_dispute($notification); |
|
765 | 765 | break; |
766 | 766 | |
767 | 767 | case 'charge.refunded': |
768 | - $this->process_webhook_refund( $notification ); |
|
768 | + $this->process_webhook_refund($notification); |
|
769 | 769 | break; |
770 | 770 | |
771 | 771 | case 'review.opened': |
772 | - $this->process_review_opened( $notification ); |
|
772 | + $this->process_review_opened($notification); |
|
773 | 773 | break; |
774 | 774 | |
775 | 775 | case 'review.closed': |
776 | - $this->process_review_closed( $notification ); |
|
776 | + $this->process_review_closed($notification); |
|
777 | 777 | break; |
778 | 778 | |
779 | 779 | case 'payment_intent.succeeded': |
780 | 780 | case 'payment_intent.payment_failed': |
781 | 781 | case 'payment_intent.amount_capturable_updated': |
782 | - $this->process_payment_intent_success( $notification ); |
|
782 | + $this->process_payment_intent_success($notification); |
|
783 | 783 | break; |
784 | 784 | |
785 | 785 | case 'setup_intent.succeeded': |
786 | 786 | case 'setup_intent.setup_failed': |
787 | - $this->process_setup_intent( $notification ); |
|
787 | + $this->process_setup_intent($notification); |
|
788 | 788 | |
789 | 789 | } |
790 | 790 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,21 +15,21 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
23 | - add_action( 'wc_stripe_cards_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) ); |
|
24 | - add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | + add_action('wc_stripe_cards_payment_fields', array($this, 'display_update_subs_payment_checkout')); |
|
24 | + add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2); |
|
25 | 25 | |
26 | 26 | // display the credit card used for a subscription in the "My Subscriptions" table |
27 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
27 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
28 | 28 | |
29 | 29 | // allow store managers to manually set Stripe as the payment method on a subscription |
30 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
31 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
32 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
30 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
31 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
32 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
33 | 33 | |
34 | 34 | /* |
35 | 35 | * WC subscriptions hooks into the "template_redirect" hook with priority 100. |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * See: https://github.com/woocommerce/woocommerce-subscriptions/blob/99a75687e109b64cbc07af6e5518458a6305f366/includes/class-wcs-cart-renewal.php#L165 |
38 | 38 | * If we are in the "You just need to authorize SCA" flow, we don't want that redirection to happen. |
39 | 39 | */ |
40 | - add_action( 'template_redirect', array( $this, 'remove_order_pay_var' ), 99 ); |
|
41 | - add_action( 'template_redirect', array( $this, 'restore_order_pay_var' ), 101 ); |
|
40 | + add_action('template_redirect', array($this, 'remove_order_pay_var'), 99); |
|
41 | + add_action('template_redirect', array($this, 'restore_order_pay_var'), 101); |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | * @since 4.0.0 |
50 | 50 | * @version 4.0.0 |
51 | 51 | */ |
52 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
53 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
52 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
53 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @param int $order_id |
63 | 63 | * @return boolean |
64 | 64 | */ |
65 | - public function has_subscription( $order_id ) { |
|
66 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
65 | + public function has_subscription($order_id) { |
|
66 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return bool |
74 | 74 | */ |
75 | 75 | public function is_subs_change_payment() { |
76 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
76 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -83,20 +83,20 @@ discard block |
||
83 | 83 | * @since 4.1.11 |
84 | 84 | */ |
85 | 85 | public function display_update_subs_payment_checkout() { |
86 | - $subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) ); |
|
86 | + $subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active')); |
|
87 | 87 | if ( |
88 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
89 | - wcs_user_has_subscription( get_current_user_id(), '', $subs_statuses ) && |
|
88 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
89 | + wcs_user_has_subscription(get_current_user_id(), '', $subs_statuses) && |
|
90 | 90 | is_add_payment_method_page() |
91 | 91 | ) { |
92 | - $label = esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe' ) ) ); |
|
93 | - $id = sprintf( 'wc-%1$s-update-subs-payment-method-card', $this->id ); |
|
92 | + $label = esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe'))); |
|
93 | + $id = sprintf('wc-%1$s-update-subs-payment-method-card', $this->id); |
|
94 | 94 | woocommerce_form_field( |
95 | 95 | $id, |
96 | 96 | array( |
97 | 97 | 'type' => 'checkbox', |
98 | 98 | 'label' => $label, |
99 | - 'default' => apply_filters( 'wc_stripe_save_to_subs_checked', false ), |
|
99 | + 'default' => apply_filters('wc_stripe_save_to_subs_checked', false), |
|
100 | 100 | ) |
101 | 101 | ); |
102 | 102 | } |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | * @param string $source_id |
110 | 110 | * @param object $source_object |
111 | 111 | */ |
112 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
113 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
112 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
113 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
114 | 114 | $all_subs = wcs_get_users_subscriptions(); |
115 | - $subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) ); |
|
116 | - |
|
117 | - if ( ! empty( $all_subs ) ) { |
|
118 | - foreach ( $all_subs as $sub ) { |
|
119 | - if ( $sub->has_status( $subs_statuses ) ) { |
|
120 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
121 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
122 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
115 | + $subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active')); |
|
116 | + |
|
117 | + if ( ! empty($all_subs)) { |
|
118 | + foreach ($all_subs as $sub) { |
|
119 | + if ($sub->has_status($subs_statuses)) { |
|
120 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
121 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
122 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
@@ -133,24 +133,24 @@ discard block |
||
133 | 133 | * @since 4.1.11 Remove 3DS check as it is not needed. |
134 | 134 | * @param int $order_id |
135 | 135 | */ |
136 | - public function change_subs_payment_method( $order_id ) { |
|
136 | + public function change_subs_payment_method($order_id) { |
|
137 | 137 | try { |
138 | - $subscription = wc_get_order( $order_id ); |
|
139 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
138 | + $subscription = wc_get_order($order_id); |
|
139 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
140 | 140 | |
141 | - $this->maybe_disallow_prepaid_card( $prepared_source ); |
|
142 | - $this->check_source( $prepared_source ); |
|
143 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
141 | + $this->maybe_disallow_prepaid_card($prepared_source); |
|
142 | + $this->check_source($prepared_source); |
|
143 | + $this->save_source_to_order($subscription, $prepared_source); |
|
144 | 144 | |
145 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
145 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
146 | 146 | |
147 | 147 | return array( |
148 | 148 | 'result' => 'success', |
149 | - 'redirect' => $this->get_return_url( $subscription ), |
|
149 | + 'redirect' => $this->get_return_url($subscription), |
|
150 | 150 | ); |
151 | - } catch ( WC_Stripe_Exception $e ) { |
|
152 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
153 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
151 | + } catch (WC_Stripe_Exception $e) { |
|
152 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
153 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
@@ -159,16 +159,16 @@ discard block |
||
159 | 159 | * @param int $order_id |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
163 | - if ( $this->has_subscription( $order_id ) ) { |
|
164 | - if ( $this->is_subs_change_payment() ) { |
|
165 | - return $this->change_subs_payment_method( $order_id ); |
|
162 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
163 | + if ($this->has_subscription($order_id)) { |
|
164 | + if ($this->is_subs_change_payment()) { |
|
165 | + return $this->change_subs_payment_method($order_id); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // Regular payment with force customer enabled |
169 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
169 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
170 | 170 | } else { |
171 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
171 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | * @param object $prepared_source The source that is used for the payment. |
181 | 181 | * @return array The arguments for the request. |
182 | 182 | */ |
183 | - public function generate_create_intent_request( $order, $prepared_source ) { |
|
184 | - $request = parent::generate_create_intent_request( $order, $prepared_source ); |
|
183 | + public function generate_create_intent_request($order, $prepared_source) { |
|
184 | + $request = parent::generate_create_intent_request($order, $prepared_source); |
|
185 | 185 | |
186 | 186 | // Non-subscription orders do not need any additional parameters. |
187 | - if ( ! $this->has_subscription( $order ) ) { |
|
187 | + if ( ! $this->has_subscription($order)) { |
|
188 | 188 | return $request; |
189 | 189 | } |
190 | 190 | |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | * @param $amount_to_charge float The amount to charge. |
201 | 201 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
202 | 202 | */ |
203 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
204 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
203 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
204 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -215,115 +215,115 @@ discard block |
||
215 | 215 | * @param bool $retry Should we retry the process? |
216 | 216 | * @param object $previous_error |
217 | 217 | */ |
218 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
218 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
219 | 219 | try { |
220 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
220 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
221 | 221 | /* translators: minimum amount */ |
222 | - 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_Helper::get_minimum_amount() / 100 ) ) ); |
|
222 | + 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_Helper::get_minimum_amount() / 100))); |
|
223 | 223 | } |
224 | 224 | |
225 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
225 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
226 | 226 | |
227 | 227 | // Check for an existing intent, which is associated with the order. |
228 | - if ( $this->has_authentication_already_failed( $renewal_order ) ) { |
|
228 | + if ($this->has_authentication_already_failed($renewal_order)) { |
|
229 | 229 | return; |
230 | 230 | } |
231 | 231 | |
232 | 232 | // Get source from order |
233 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
233 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
234 | 234 | $source_object = $prepared_source->source_object; |
235 | 235 | |
236 | - if ( ! $prepared_source->customer ) { |
|
237 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
236 | + if ( ! $prepared_source->customer) { |
|
237 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
238 | 238 | } |
239 | 239 | |
240 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
240 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
241 | 241 | |
242 | 242 | /* If we're doing a retry and source is chargeable, we need to pass |
243 | 243 | * a different idempotency key and retry for success. |
244 | 244 | */ |
245 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
246 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
245 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
246 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
247 | 247 | } |
248 | 248 | |
249 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
249 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
250 | 250 | // Passing empty source will charge customer default. |
251 | 251 | $prepared_source->source = ''; |
252 | 252 | } |
253 | 253 | |
254 | - $this->lock_order_payment( $renewal_order ); |
|
254 | + $this->lock_order_payment($renewal_order); |
|
255 | 255 | |
256 | - $response = $this->create_and_confirm_intent_for_off_session( $renewal_order, $prepared_source, $amount ); |
|
257 | - $is_authentication_required = $this->is_authentication_required_for_payment( $response ); |
|
256 | + $response = $this->create_and_confirm_intent_for_off_session($renewal_order, $prepared_source, $amount); |
|
257 | + $is_authentication_required = $this->is_authentication_required_for_payment($response); |
|
258 | 258 | |
259 | 259 | // It's only a failed payment if it's an error and it's not of the type 'authentication_required'. |
260 | 260 | // If it's 'authentication_required', then we should email the user and ask them to authenticate. |
261 | - if ( ! empty( $response->error ) && ! $is_authentication_required ) { |
|
261 | + if ( ! empty($response->error) && ! $is_authentication_required) { |
|
262 | 262 | // We want to retry. |
263 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
264 | - if ( $retry ) { |
|
263 | + if ($this->is_retryable_error($response->error)) { |
|
264 | + if ($retry) { |
|
265 | 265 | // Don't do anymore retries after this. |
266 | - if ( 5 <= $this->retry_interval ) { |
|
267 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
266 | + if (5 <= $this->retry_interval) { |
|
267 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
268 | 268 | } |
269 | 269 | |
270 | - sleep( $this->retry_interval ); |
|
270 | + sleep($this->retry_interval); |
|
271 | 271 | |
272 | 272 | $this->retry_interval++; |
273 | 273 | |
274 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
274 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
275 | 275 | } else { |
276 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
277 | - $renewal_order->add_order_note( $localized_message ); |
|
278 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
276 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
277 | + $renewal_order->add_order_note($localized_message); |
|
278 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | 282 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
283 | 283 | |
284 | - if ( 'card_error' === $response->error->type ) { |
|
285 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
284 | + if ('card_error' === $response->error->type) { |
|
285 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
286 | 286 | } else { |
287 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
287 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
288 | 288 | } |
289 | 289 | |
290 | - $renewal_order->add_order_note( $localized_message ); |
|
290 | + $renewal_order->add_order_note($localized_message); |
|
291 | 291 | |
292 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
292 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | // Either the charge was successfully captured, or it requires further authentication. |
296 | 296 | |
297 | - if ( $is_authentication_required ) { |
|
298 | - do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response ); |
|
297 | + if ($is_authentication_required) { |
|
298 | + do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response); |
|
299 | 299 | |
300 | - $error_message = __( 'This transaction requires authentication.', 'woocommerce-gateway-stripe' ); |
|
301 | - $renewal_order->add_order_note( $error_message ); |
|
300 | + $error_message = __('This transaction requires authentication.', 'woocommerce-gateway-stripe'); |
|
301 | + $renewal_order->add_order_note($error_message); |
|
302 | 302 | |
303 | - $charge = end( $response->error->payment_intent->charges->data ); |
|
303 | + $charge = end($response->error->payment_intent->charges->data); |
|
304 | 304 | $id = $charge->id; |
305 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
305 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
306 | 306 | |
307 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $id ) : $renewal_order->set_transaction_id( $id ); |
|
308 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $id ) ); |
|
309 | - if ( is_callable( array( $renewal_order, 'save' ) ) ) { |
|
307 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $id) : $renewal_order->set_transaction_id($id); |
|
308 | + $renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $id)); |
|
309 | + if (is_callable(array($renewal_order, 'save'))) { |
|
310 | 310 | $renewal_order->save(); |
311 | 311 | } |
312 | 312 | } else { |
313 | 313 | // The charge was successfully captured |
314 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
314 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
315 | 315 | |
316 | - $this->process_response( end( $response->charges->data ), $renewal_order ); |
|
316 | + $this->process_response(end($response->charges->data), $renewal_order); |
|
317 | 317 | } |
318 | 318 | |
319 | - $this->unlock_order_payment( $renewal_order ); |
|
320 | - } catch ( WC_Stripe_Exception $e ) { |
|
321 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
319 | + $this->unlock_order_payment($renewal_order); |
|
320 | + } catch (WC_Stripe_Exception $e) { |
|
321 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
322 | 322 | |
323 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
323 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
324 | 324 | |
325 | 325 | /* translators: error message */ |
326 | - $renewal_order->update_status( 'failed' ); |
|
326 | + $renewal_order->update_status('failed'); |
|
327 | 327 | } |
328 | 328 | } |
329 | 329 | |
@@ -333,24 +333,24 @@ discard block |
||
333 | 333 | * @since 3.1.0 |
334 | 334 | * @version 4.0.0 |
335 | 335 | */ |
336 | - public function save_source_to_order( $order, $source ) { |
|
337 | - parent::save_source_to_order( $order, $source ); |
|
336 | + public function save_source_to_order($order, $source) { |
|
337 | + parent::save_source_to_order($order, $source); |
|
338 | 338 | |
339 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
339 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
340 | 340 | |
341 | 341 | // Also store it on the subscriptions being purchased or paid for in the order |
342 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
343 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
344 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
345 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
342 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
343 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
344 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
345 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
346 | 346 | } else { |
347 | 347 | $subscriptions = array(); |
348 | 348 | } |
349 | 349 | |
350 | - foreach ( $subscriptions as $subscription ) { |
|
351 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
352 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
353 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
350 | + foreach ($subscriptions as $subscription) { |
|
351 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
352 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
353 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
354 | 354 | } |
355 | 355 | } |
356 | 356 | |
@@ -358,26 +358,26 @@ discard block |
||
358 | 358 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
359 | 359 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
360 | 360 | */ |
361 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
362 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
363 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
361 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
362 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
363 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
364 | 364 | // For BW compat will remove in future |
365 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
365 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
366 | 366 | // delete payment intent ID |
367 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_intent_id' ); |
|
368 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
367 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_intent_id'); |
|
368 | + $this->delete_renewal_meta($resubscribe_order); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
372 | 372 | * Don't transfer Stripe fee/ID meta to renewal orders. |
373 | 373 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
374 | 374 | */ |
375 | - public function delete_renewal_meta( $renewal_order ) { |
|
376 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
377 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
375 | + public function delete_renewal_meta($renewal_order) { |
|
376 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
377 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
378 | 378 | |
379 | 379 | // delete payment intent ID |
380 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id() ), '_stripe_intent_id' ); |
|
380 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id()), '_stripe_intent_id'); |
|
381 | 381 | |
382 | 382 | return $renewal_order; |
383 | 383 | } |
@@ -391,14 +391,14 @@ discard block |
||
391 | 391 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
392 | 392 | * @return void |
393 | 393 | */ |
394 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
395 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
396 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
397 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
394 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
395 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
396 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
397 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
398 | 398 | |
399 | 399 | } else { |
400 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
401 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
400 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
401 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
@@ -411,23 +411,23 @@ discard block |
||
411 | 411 | * @param WC_Subscription $subscription An instance of a subscription object |
412 | 412 | * @return array |
413 | 413 | */ |
414 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
415 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
416 | - $source_id = get_post_meta( $subscription_id, '_stripe_source_id', true ); |
|
414 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
415 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
416 | + $source_id = get_post_meta($subscription_id, '_stripe_source_id', true); |
|
417 | 417 | |
418 | 418 | // For BW compat will remove in future. |
419 | - if ( empty( $source_id ) ) { |
|
420 | - $source_id = get_post_meta( $subscription_id, '_stripe_card_id', true ); |
|
419 | + if (empty($source_id)) { |
|
420 | + $source_id = get_post_meta($subscription_id, '_stripe_card_id', true); |
|
421 | 421 | |
422 | 422 | // Take this opportunity to update the key name. |
423 | - update_post_meta( $subscription_id, '_stripe_source_id', $source_id ); |
|
424 | - delete_post_meta( $subscription_id, '_stripe_card_id', $source_id ); |
|
423 | + update_post_meta($subscription_id, '_stripe_source_id', $source_id); |
|
424 | + delete_post_meta($subscription_id, '_stripe_card_id', $source_id); |
|
425 | 425 | } |
426 | 426 | |
427 | - $payment_meta[ $this->id ] = array( |
|
427 | + $payment_meta[$this->id] = array( |
|
428 | 428 | 'post_meta' => array( |
429 | 429 | '_stripe_customer_id' => array( |
430 | - 'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ), |
|
430 | + 'value' => get_post_meta($subscription_id, '_stripe_customer_id', true), |
|
431 | 431 | 'label' => 'Stripe Customer ID', |
432 | 432 | ), |
433 | 433 | '_stripe_source_id' => array( |
@@ -450,22 +450,22 @@ discard block |
||
450 | 450 | * @param array $payment_meta associative array of meta data required for automatic payments |
451 | 451 | * @return array |
452 | 452 | */ |
453 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
454 | - if ( $this->id === $payment_method_id ) { |
|
453 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
454 | + if ($this->id === $payment_method_id) { |
|
455 | 455 | |
456 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
457 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
458 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
459 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
456 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
457 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
458 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
459 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | if ( |
463 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
464 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
465 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
466 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
463 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
464 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
465 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
466 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
467 | 467 | |
468 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
468 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
469 | 469 | } |
470 | 470 | } |
471 | 471 | } |
@@ -478,75 +478,75 @@ discard block |
||
478 | 478 | * @param WC_Subscription $subscription the subscription details |
479 | 479 | * @return string the subscription payment method |
480 | 480 | */ |
481 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
482 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
481 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
482 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
483 | 483 | |
484 | 484 | // bail for other payment methods |
485 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
485 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
486 | 486 | return $payment_method_to_display; |
487 | 487 | } |
488 | 488 | |
489 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
489 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
490 | 490 | |
491 | 491 | // For BW compat will remove in future. |
492 | - if ( empty( $stripe_source_id ) ) { |
|
493 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
492 | + if (empty($stripe_source_id)) { |
|
493 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
494 | 494 | |
495 | 495 | // Take this opportunity to update the key name. |
496 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
496 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | $stripe_customer = new WC_Stripe_Customer(); |
500 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
500 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
501 | 501 | |
502 | 502 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
503 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
503 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
504 | 504 | $user_id = $customer_user; |
505 | - $stripe_customer_id = get_user_option( '_stripe_customer_id', $user_id ); |
|
506 | - $stripe_source_id = get_user_option( '_stripe_source_id', $user_id ); |
|
505 | + $stripe_customer_id = get_user_option('_stripe_customer_id', $user_id); |
|
506 | + $stripe_source_id = get_user_option('_stripe_source_id', $user_id); |
|
507 | 507 | |
508 | 508 | // For BW compat will remove in future. |
509 | - if ( empty( $stripe_source_id ) ) { |
|
510 | - $stripe_source_id = get_user_option( '_stripe_card_id', $user_id ); |
|
509 | + if (empty($stripe_source_id)) { |
|
510 | + $stripe_source_id = get_user_option('_stripe_card_id', $user_id); |
|
511 | 511 | |
512 | 512 | // Take this opportunity to update the key name. |
513 | - update_user_option( $user_id, '_stripe_source_id', $stripe_source_id, false ); |
|
513 | + update_user_option($user_id, '_stripe_source_id', $stripe_source_id, false); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
517 | 517 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
518 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
519 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
520 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
518 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
519 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
520 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
521 | 521 | |
522 | 522 | // For BW compat will remove in future. |
523 | - if ( empty( $stripe_source_id ) ) { |
|
524 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
523 | + if (empty($stripe_source_id)) { |
|
524 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
525 | 525 | |
526 | 526 | // Take this opportunity to update the key name. |
527 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
527 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
528 | 528 | } |
529 | 529 | } |
530 | 530 | |
531 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
531 | + $stripe_customer->set_id($stripe_customer_id); |
|
532 | 532 | |
533 | 533 | $sources = $stripe_customer->get_sources(); |
534 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
534 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
535 | 535 | |
536 | - if ( $sources ) { |
|
536 | + if ($sources) { |
|
537 | 537 | $card = false; |
538 | 538 | |
539 | - foreach ( $sources as $source ) { |
|
540 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
539 | + foreach ($sources as $source) { |
|
540 | + if (isset($source->type) && 'card' === $source->type) { |
|
541 | 541 | $card = $source->card; |
542 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
542 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
543 | 543 | $card = $source; |
544 | 544 | } |
545 | 545 | |
546 | - if ( $source->id === $stripe_source_id ) { |
|
547 | - if ( $card ) { |
|
546 | + if ($source->id === $stripe_source_id) { |
|
547 | + if ($card) { |
|
548 | 548 | /* translators: 1) card brand 2) last 4 digits */ |
549 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
549 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | break; |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | */ |
564 | 564 | public function remove_order_pay_var() { |
565 | 565 | global $wp; |
566 | - if ( isset( $_GET['wc-stripe-confirmation'] ) ) { |
|
566 | + if (isset($_GET['wc-stripe-confirmation'])) { |
|
567 | 567 | $this->order_pay_var = $wp->query_vars['order-pay']; |
568 | 568 | $wp->query_vars['order-pay'] = null; |
569 | 569 | } |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | */ |
575 | 575 | public function restore_order_pay_var() { |
576 | 576 | global $wp; |
577 | - if ( isset( $this->order_pay_var ) ) { |
|
577 | + if (isset($this->order_pay_var)) { |
|
578 | 578 | $wp->query_vars['order-pay'] = $this->order_pay_var; |
579 | 579 | } |
580 | 580 | } |
@@ -585,13 +585,13 @@ discard block |
||
585 | 585 | * @param WC_Order $renewal_order The renewal order. |
586 | 586 | * @return boolean |
587 | 587 | */ |
588 | - public function has_authentication_already_failed( $renewal_order ) { |
|
589 | - $existing_intent = $this->get_intent_from_order( $renewal_order ); |
|
588 | + public function has_authentication_already_failed($renewal_order) { |
|
589 | + $existing_intent = $this->get_intent_from_order($renewal_order); |
|
590 | 590 | |
591 | 591 | if ( |
592 | 592 | ! $existing_intent |
593 | 593 | || 'requires_payment_method' !== $existing_intent->status |
594 | - || empty( $existing_intent->last_payment_error ) |
|
594 | + || empty($existing_intent->last_payment_error) |
|
595 | 595 | || 'authentication_required' !== $existing_intent->last_payment_error->code |
596 | 596 | ) { |
597 | 597 | return false; |
@@ -605,12 +605,12 @@ discard block |
||
605 | 605 | * |
606 | 606 | * @param WC_Order $renewal_order The order that is being renewed. |
607 | 607 | */ |
608 | - do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order ); |
|
608 | + do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order); |
|
609 | 609 | |
610 | 610 | // Fail the payment attempt (order would be currently pending because of retry rules). |
611 | - $charge = end( $existing_intent->charges->data ); |
|
611 | + $charge = end($existing_intent->charges->data); |
|
612 | 612 | $charge_id = $charge->id; |
613 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $charge_id ) ); |
|
613 | + $renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $charge_id)); |
|
614 | 614 | |
615 | 615 | return true; |
616 | 616 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,21 +15,21 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
23 | - add_action( 'wc_stripe_sepa_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) ); |
|
24 | - add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | + add_action('wc_stripe_sepa_payment_fields', array($this, 'display_update_subs_payment_checkout')); |
|
24 | + add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2); |
|
25 | 25 | |
26 | 26 | // Display the credit card used for a subscription in the "My Subscriptions" table. |
27 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
27 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
28 | 28 | |
29 | 29 | // Allow store managers to manually set Stripe as the payment method on a subscription. |
30 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
31 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
32 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
30 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
31 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
32 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | * @since 4.0.0 |
41 | 41 | * @version 4.0.0 |
42 | 42 | */ |
43 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
44 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
43 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
44 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | * @param int $order_id |
54 | 54 | * @return boolean |
55 | 55 | */ |
56 | - public function has_subscription( $order_id ) { |
|
57 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
56 | + public function has_subscription($order_id) { |
|
57 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return bool |
65 | 65 | */ |
66 | 66 | public function is_subs_change_payment() { |
67 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
67 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,20 +74,20 @@ discard block |
||
74 | 74 | * @since 4.1.11 |
75 | 75 | */ |
76 | 76 | public function display_update_subs_payment_checkout() { |
77 | - $subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) ); |
|
77 | + $subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active')); |
|
78 | 78 | if ( |
79 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
80 | - wcs_user_has_subscription( get_current_user_id(), '', $subs_statuses ) && |
|
79 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
80 | + wcs_user_has_subscription(get_current_user_id(), '', $subs_statuses) && |
|
81 | 81 | is_add_payment_method_page() |
82 | 82 | ) { |
83 | - $label = esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe' ) ) ); |
|
84 | - $id = sprintf( 'wc-%1$s-update-subs-payment-method-card', $this->id ); |
|
83 | + $label = esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe'))); |
|
84 | + $id = sprintf('wc-%1$s-update-subs-payment-method-card', $this->id); |
|
85 | 85 | woocommerce_form_field( |
86 | 86 | $id, |
87 | 87 | array( |
88 | 88 | 'type' => 'checkbox', |
89 | 89 | 'label' => $label, |
90 | - 'default' => apply_filters( 'wc_stripe_save_to_subs_checked', false ), |
|
90 | + 'default' => apply_filters('wc_stripe_save_to_subs_checked', false), |
|
91 | 91 | ) |
92 | 92 | ); |
93 | 93 | } |
@@ -100,17 +100,17 @@ discard block |
||
100 | 100 | * @param string $source_id |
101 | 101 | * @param object $source_object |
102 | 102 | */ |
103 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
104 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
103 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
104 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
105 | 105 | $all_subs = wcs_get_users_subscriptions(); |
106 | - $subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) ); |
|
107 | - |
|
108 | - if ( ! empty( $all_subs ) ) { |
|
109 | - foreach ( $all_subs as $sub ) { |
|
110 | - if ( $sub->has_status( $subs_statuses ) ) { |
|
111 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
112 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
113 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
106 | + $subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active')); |
|
107 | + |
|
108 | + if ( ! empty($all_subs)) { |
|
109 | + foreach ($all_subs as $sub) { |
|
110 | + if ($sub->has_status($subs_statuses)) { |
|
111 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
112 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
113 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | } |
@@ -123,24 +123,24 @@ discard block |
||
123 | 123 | * @since 3.1.0 |
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | - public function save_source_to_order( $order, $source ) { |
|
127 | - parent::save_source_to_order( $order, $source ); |
|
126 | + public function save_source_to_order($order, $source) { |
|
127 | + parent::save_source_to_order($order, $source); |
|
128 | 128 | |
129 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
129 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
130 | 130 | |
131 | 131 | // Also store it on the subscriptions being purchased or paid for in the order. |
132 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
133 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
134 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
135 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
132 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
133 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
134 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
135 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
136 | 136 | } else { |
137 | 137 | $subscriptions = array(); |
138 | 138 | } |
139 | 139 | |
140 | - foreach ( $subscriptions as $subscription ) { |
|
141 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
142 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
143 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
140 | + foreach ($subscriptions as $subscription) { |
|
141 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
142 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
143 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
@@ -149,16 +149,16 @@ discard block |
||
149 | 149 | * @param int $order_id |
150 | 150 | * @return array |
151 | 151 | */ |
152 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
153 | - if ( $this->has_subscription( $order_id ) ) { |
|
154 | - if ( $this->is_subs_change_payment() ) { |
|
155 | - return $this->change_subs_payment_method( $order_id ); |
|
152 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
153 | + if ($this->has_subscription($order_id)) { |
|
154 | + if ($this->is_subs_change_payment()) { |
|
155 | + return $this->change_subs_payment_method($order_id); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Regular payment with force customer enabled |
159 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
159 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
160 | 160 | } else { |
161 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
161 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -168,27 +168,27 @@ discard block |
||
168 | 168 | * @since 4.0.4 |
169 | 169 | * @param int $order_id |
170 | 170 | */ |
171 | - public function change_subs_payment_method( $order_id ) { |
|
171 | + public function change_subs_payment_method($order_id) { |
|
172 | 172 | try { |
173 | - $subscription = wc_get_order( $order_id ); |
|
174 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
173 | + $subscription = wc_get_order($order_id); |
|
174 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
175 | 175 | |
176 | - if ( empty( $prepared_source->source ) ) { |
|
177 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
178 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
176 | + if (empty($prepared_source->source)) { |
|
177 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
178 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
179 | 179 | } |
180 | 180 | |
181 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
181 | + $this->save_source_to_order($subscription, $prepared_source); |
|
182 | 182 | |
183 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
183 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
184 | 184 | |
185 | 185 | return array( |
186 | 186 | 'result' => 'success', |
187 | - 'redirect' => $this->get_return_url( $subscription ), |
|
187 | + 'redirect' => $this->get_return_url($subscription), |
|
188 | 188 | ); |
189 | - } catch ( WC_Stripe_Exception $e ) { |
|
190 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
191 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
189 | + } catch (WC_Stripe_Exception $e) { |
|
190 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
191 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | * @param $amount_to_charge float The amount to charge. |
199 | 199 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
200 | 200 | */ |
201 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
202 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
201 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
202 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -213,86 +213,86 @@ discard block |
||
213 | 213 | * @param bool $retry Should we retry the process? |
214 | 214 | * @param object $previous_error |
215 | 215 | */ |
216 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
216 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
217 | 217 | try { |
218 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
218 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
219 | 219 | /* translators: minimum amount */ |
220 | - 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_Helper::get_minimum_amount() / 100 ) ) ); |
|
220 | + 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_Helper::get_minimum_amount() / 100))); |
|
221 | 221 | } |
222 | 222 | |
223 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
223 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
224 | 224 | |
225 | 225 | // Get source from order |
226 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
226 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
227 | 227 | $source_object = $prepared_source->source_object; |
228 | 228 | |
229 | - if ( ! $prepared_source->customer ) { |
|
230 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
229 | + if ( ! $prepared_source->customer) { |
|
230 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
231 | 231 | } |
232 | 232 | |
233 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
233 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
234 | 234 | |
235 | 235 | /* If we're doing a retry and source is chargeable, we need to pass |
236 | 236 | * a different idempotency key and retry for success. |
237 | 237 | */ |
238 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
239 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
238 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
239 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
240 | 240 | } |
241 | 241 | |
242 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
242 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
243 | 243 | // Passing empty source will charge customer default. |
244 | 244 | $prepared_source->source = ''; |
245 | 245 | } |
246 | 246 | |
247 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
247 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
248 | 248 | $request['capture'] = 'true'; |
249 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
250 | - $response = WC_Stripe_API::request( $request ); |
|
249 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
250 | + $response = WC_Stripe_API::request($request); |
|
251 | 251 | |
252 | - if ( ! empty( $response->error ) ) { |
|
252 | + if ( ! empty($response->error)) { |
|
253 | 253 | // We want to retry. |
254 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
255 | - if ( $retry ) { |
|
254 | + if ($this->is_retryable_error($response->error)) { |
|
255 | + if ($retry) { |
|
256 | 256 | // Don't do anymore retries after this. |
257 | - if ( 5 <= $this->retry_interval ) { |
|
258 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
257 | + if (5 <= $this->retry_interval) { |
|
258 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
259 | 259 | } |
260 | 260 | |
261 | - sleep( $this->retry_interval ); |
|
261 | + sleep($this->retry_interval); |
|
262 | 262 | |
263 | 263 | $this->retry_interval++; |
264 | 264 | |
265 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
265 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
266 | 266 | } else { |
267 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
268 | - $renewal_order->add_order_note( $localized_message ); |
|
269 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
267 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
268 | + $renewal_order->add_order_note($localized_message); |
|
269 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | 273 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
274 | 274 | |
275 | - if ( 'card_error' === $response->error->type ) { |
|
276 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
275 | + if ('card_error' === $response->error->type) { |
|
276 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
277 | 277 | } else { |
278 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
278 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
279 | 279 | } |
280 | 280 | |
281 | - $renewal_order->add_order_note( $localized_message ); |
|
281 | + $renewal_order->add_order_note($localized_message); |
|
282 | 282 | |
283 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
283 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
284 | 284 | } |
285 | 285 | |
286 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
286 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
287 | 287 | |
288 | - $this->process_response( $response, $renewal_order ); |
|
289 | - } catch ( WC_Stripe_Exception $e ) { |
|
290 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
288 | + $this->process_response($response, $renewal_order); |
|
289 | + } catch (WC_Stripe_Exception $e) { |
|
290 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
291 | 291 | |
292 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
292 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
293 | 293 | |
294 | 294 | /* translators: error message */ |
295 | - $renewal_order->update_status( 'failed' ); |
|
295 | + $renewal_order->update_status('failed'); |
|
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
@@ -300,21 +300,21 @@ discard block |
||
300 | 300 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
301 | 301 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
302 | 302 | */ |
303 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
304 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
305 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
303 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
304 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
305 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
306 | 306 | // For BW compat will remove in future |
307 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
308 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
307 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
308 | + $this->delete_renewal_meta($resubscribe_order); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
312 | 312 | * Don't transfer Stripe fee/ID meta to renewal orders. |
313 | 313 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
314 | 314 | */ |
315 | - public function delete_renewal_meta( $renewal_order ) { |
|
316 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
317 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
315 | + public function delete_renewal_meta($renewal_order) { |
|
316 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
317 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
318 | 318 | |
319 | 319 | return $renewal_order; |
320 | 320 | } |
@@ -328,14 +328,14 @@ discard block |
||
328 | 328 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
329 | 329 | * @return void |
330 | 330 | */ |
331 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
332 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
333 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
334 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
331 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
332 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
333 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
334 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
335 | 335 | |
336 | 336 | } else { |
337 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
338 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
337 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
338 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | |
@@ -348,21 +348,21 @@ discard block |
||
348 | 348 | * @param WC_Subscription $subscription An instance of a subscription object |
349 | 349 | * @return array |
350 | 350 | */ |
351 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
352 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
351 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
352 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
353 | 353 | |
354 | 354 | // For BW compat will remove in future. |
355 | - if ( empty( $source_id ) ) { |
|
356 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
355 | + if (empty($source_id)) { |
|
356 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
357 | 357 | |
358 | 358 | // Take this opportunity to update the key name. |
359 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
359 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
360 | 360 | } |
361 | 361 | |
362 | - $payment_meta[ $this->id ] = array( |
|
362 | + $payment_meta[$this->id] = array( |
|
363 | 363 | 'post_meta' => array( |
364 | 364 | '_stripe_customer_id' => array( |
365 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
365 | + 'value' => get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
366 | 366 | 'label' => 'Stripe Customer ID', |
367 | 367 | ), |
368 | 368 | '_stripe_source_id' => array( |
@@ -383,22 +383,22 @@ discard block |
||
383 | 383 | * @param array $payment_meta associative array of meta data required for automatic payments |
384 | 384 | * @return array |
385 | 385 | */ |
386 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
387 | - if ( $this->id === $payment_method_id ) { |
|
386 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
387 | + if ($this->id === $payment_method_id) { |
|
388 | 388 | |
389 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
390 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
391 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
392 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
389 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
390 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
391 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
392 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | if ( |
396 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
397 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
398 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
399 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
396 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
397 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
398 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
399 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
400 | 400 | |
401 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
401 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | } |
@@ -411,67 +411,67 @@ discard block |
||
411 | 411 | * @param WC_Subscription $subscription the subscription details |
412 | 412 | * @return string the subscription payment method |
413 | 413 | */ |
414 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
415 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
414 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
415 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
416 | 416 | |
417 | 417 | // bail for other payment methods |
418 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
418 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
419 | 419 | return $payment_method_to_display; |
420 | 420 | } |
421 | 421 | |
422 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
422 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
423 | 423 | |
424 | 424 | // For BW compat will remove in future. |
425 | - if ( empty( $stripe_source_id ) ) { |
|
426 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
425 | + if (empty($stripe_source_id)) { |
|
426 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
427 | 427 | |
428 | 428 | // Take this opportunity to update the key name. |
429 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
429 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | $stripe_customer = new WC_Stripe_Customer(); |
433 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
433 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
434 | 434 | |
435 | 435 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
436 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
436 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
437 | 437 | $user_id = $customer_user; |
438 | - $stripe_customer_id = get_user_option( '_stripe_customer_id', $user_id ); |
|
439 | - $stripe_source_id = get_user_option( '_stripe_source_id', $user_id ); |
|
438 | + $stripe_customer_id = get_user_option('_stripe_customer_id', $user_id); |
|
439 | + $stripe_source_id = get_user_option('_stripe_source_id', $user_id); |
|
440 | 440 | |
441 | 441 | // For BW compat will remove in future. |
442 | - if ( empty( $stripe_source_id ) ) { |
|
443 | - $stripe_source_id = get_user_option( '_stripe_card_id', $user_id ); |
|
442 | + if (empty($stripe_source_id)) { |
|
443 | + $stripe_source_id = get_user_option('_stripe_card_id', $user_id); |
|
444 | 444 | |
445 | 445 | // Take this opportunity to update the key name. |
446 | - update_user_option( $user_id, '_stripe_source_id', $stripe_source_id, false ); |
|
446 | + update_user_option($user_id, '_stripe_source_id', $stripe_source_id, false); |
|
447 | 447 | } |
448 | 448 | } |
449 | 449 | |
450 | 450 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
451 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
452 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
453 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
451 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
452 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
453 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
454 | 454 | |
455 | 455 | // For BW compat will remove in future. |
456 | - if ( empty( $stripe_source_id ) ) { |
|
457 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
456 | + if (empty($stripe_source_id)) { |
|
457 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
458 | 458 | |
459 | 459 | // Take this opportunity to update the key name. |
460 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
460 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
464 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
464 | + $stripe_customer->set_id($stripe_customer_id); |
|
465 | 465 | |
466 | 466 | $sources = $stripe_customer->get_sources(); |
467 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
467 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
468 | 468 | |
469 | - if ( $sources ) { |
|
470 | - foreach ( $sources as $source ) { |
|
471 | - if ( $source->id === $stripe_source_id ) { |
|
472 | - if ( $source->sepa_debit ) { |
|
469 | + if ($sources) { |
|
470 | + foreach ($sources as $source) { |
|
471 | + if ($source->id === $stripe_source_id) { |
|
472 | + if ($source->sepa_debit) { |
|
473 | 473 | /* translators: 1) last 4 digits of SEPA Direct Debit */ |
474 | - $payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 ); |
|
474 | + $payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | break; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function display_admin_settings_webhook_description() { |
23 | 23 | /* translators: 1) webhook url */ |
24 | - return sprintf( __( 'You must add the following webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::get_webhook_url() ); |
|
24 | + return sprintf(__('You must add the following webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::get_webhook_url()); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | <input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
36 | 36 | <label for="wc-%1$s-new-payment-method" style="display:inline;">%2$s</label> |
37 | 37 | </p>', |
38 | - esc_attr( $this->id ), |
|
39 | - esc_html( apply_filters( 'wc_stripe_save_to_account_text', __( 'Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe' ) ) ) |
|
38 | + esc_attr($this->id), |
|
39 | + esc_html(apply_filters('wc_stripe_save_to_account_text', __('Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe'))) |
|
40 | 40 | ); |
41 | 41 | } |
42 | 42 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @since 4.0.5 |
48 | 48 | * @param array $error |
49 | 49 | */ |
50 | - public function is_retryable_error( $error ) { |
|
50 | + public function is_retryable_error($error) { |
|
51 | 51 | return ( |
52 | 52 | 'invalid_request_error' === $error->type || |
53 | 53 | 'idempotency_error' === $error->type || |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * @since 4.1.0 |
65 | 65 | * @param array $error |
66 | 66 | */ |
67 | - public function is_same_idempotency_error( $error ) { |
|
67 | + public function is_same_idempotency_error($error) { |
|
68 | 68 | return ( |
69 | 69 | $error && |
70 | 70 | 'idempotency_error' === $error->type && |
71 | - preg_match( '/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message ) |
|
71 | + preg_match('/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message) |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | * @since 4.1.0 |
80 | 80 | * @param array $error |
81 | 81 | */ |
82 | - public function is_no_such_customer_error( $error ) { |
|
82 | + public function is_no_such_customer_error($error) { |
|
83 | 83 | return ( |
84 | 84 | $error && |
85 | 85 | 'invalid_request_error' === $error->type && |
86 | - preg_match( '/No such customer/i', $error->message ) |
|
86 | + preg_match('/No such customer/i', $error->message) |
|
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | * @since 4.1.0 |
95 | 95 | * @param array $error |
96 | 96 | */ |
97 | - public function is_no_such_token_error( $error ) { |
|
97 | + public function is_no_such_token_error($error) { |
|
98 | 98 | return ( |
99 | 99 | $error && |
100 | 100 | 'invalid_request_error' === $error->type && |
101 | - preg_match( '/No such token/i', $error->message ) |
|
101 | + preg_match('/No such token/i', $error->message) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | * @since 4.1.0 |
110 | 110 | * @param array $error |
111 | 111 | */ |
112 | - public function is_no_such_source_error( $error ) { |
|
112 | + public function is_no_such_source_error($error) { |
|
113 | 113 | return ( |
114 | 114 | $error && |
115 | 115 | 'invalid_request_error' === $error->type && |
116 | - preg_match( '/No such source/i', $error->message ) |
|
116 | + preg_match('/No such source/i', $error->message) |
|
117 | 117 | ); |
118 | 118 | } |
119 | 119 | |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | * @since 4.1.0 |
125 | 125 | * @param array $error |
126 | 126 | */ |
127 | - public function is_no_linked_source_error( $error ) { |
|
127 | + public function is_no_linked_source_error($error) { |
|
128 | 128 | return ( |
129 | 129 | $error && |
130 | 130 | 'invalid_request_error' === $error->type && |
131 | - preg_match( '/does not have a linked source with ID/i', $error->message ) |
|
131 | + preg_match('/does not have a linked source with ID/i', $error->message) |
|
132 | 132 | ); |
133 | 133 | } |
134 | 134 | |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @param object $error |
142 | 142 | * @return bool |
143 | 143 | */ |
144 | - public function need_update_idempotency_key( $source_object, $error ) { |
|
144 | + public function need_update_idempotency_key($source_object, $error) { |
|
145 | 145 | return ( |
146 | 146 | $error && |
147 | 147 | 1 < $this->retry_interval && |
148 | - ! empty( $source_object ) && |
|
148 | + ! empty($source_object) && |
|
149 | 149 | 'chargeable' === $source_object->status && |
150 | - self::is_same_idempotency_error( $error ) |
|
150 | + self::is_same_idempotency_error($error) |
|
151 | 151 | ); |
152 | 152 | } |
153 | 153 | |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * @since 4.1.3 |
158 | 158 | */ |
159 | 159 | public function is_available() { |
160 | - if ( 'yes' === $this->enabled ) { |
|
161 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
160 | + if ('yes' === $this->enabled) { |
|
161 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
162 | 162 | return false; |
163 | 163 | } |
164 | 164 | return true; |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | * @param int $order_id |
176 | 176 | * @return bool |
177 | 177 | */ |
178 | - public function maybe_process_pre_orders( $order_id ) { |
|
178 | + public function maybe_process_pre_orders($order_id) { |
|
179 | 179 | return ( |
180 | 180 | WC_Stripe_Helper::is_pre_orders_exists() && |
181 | - $this->pre_orders->is_pre_order( $order_id ) && |
|
182 | - WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) && |
|
183 | - ! is_wc_endpoint_url( 'order-pay' ) |
|
181 | + $this->pre_orders->is_pre_order($order_id) && |
|
182 | + WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id) && |
|
183 | + ! is_wc_endpoint_url('order-pay') |
|
184 | 184 | ); |
185 | 185 | } |
186 | 186 | |
@@ -224,10 +224,10 @@ discard block |
||
224 | 224 | * @version 4.0.0 |
225 | 225 | * @param object $order |
226 | 226 | */ |
227 | - public function validate_minimum_order_amount( $order ) { |
|
228 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
227 | + public function validate_minimum_order_amount($order) { |
|
228 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
229 | 229 | /* translators: 1) dollar amount */ |
230 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
230 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
@@ -237,14 +237,14 @@ discard block |
||
237 | 237 | * @since 4.0.0 |
238 | 238 | * @version 4.0.0 |
239 | 239 | */ |
240 | - public function get_transaction_url( $order ) { |
|
241 | - if ( $this->testmode ) { |
|
240 | + public function get_transaction_url($order) { |
|
241 | + if ($this->testmode) { |
|
242 | 242 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
243 | 243 | } else { |
244 | 244 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
245 | 245 | } |
246 | 246 | |
247 | - return parent::get_transaction_url( $order ); |
|
247 | + return parent::get_transaction_url($order); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -253,15 +253,15 @@ discard block |
||
253 | 253 | * @since 4.0.0 |
254 | 254 | * @version 4.0.0 |
255 | 255 | */ |
256 | - public function get_stripe_customer_id( $order ) { |
|
257 | - $customer = get_user_option( '_stripe_customer_id', WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id() ); |
|
256 | + public function get_stripe_customer_id($order) { |
|
257 | + $customer = get_user_option('_stripe_customer_id', WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id()); |
|
258 | 258 | |
259 | - if ( empty( $customer ) ) { |
|
259 | + if (empty($customer)) { |
|
260 | 260 | // Try to get it via the order. |
261 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
262 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
261 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
262 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
263 | 263 | } else { |
264 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
264 | + return $order->get_meta('_stripe_customer_id', true); |
|
265 | 265 | } |
266 | 266 | } else { |
267 | 267 | return $customer; |
@@ -278,23 +278,23 @@ discard block |
||
278 | 278 | * @param object $order |
279 | 279 | * @param int $id Stripe session id. |
280 | 280 | */ |
281 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
282 | - if ( is_object( $order ) ) { |
|
283 | - if ( empty( $id ) ) { |
|
281 | + public function get_stripe_return_url($order = null, $id = null) { |
|
282 | + if (is_object($order)) { |
|
283 | + if (empty($id)) { |
|
284 | 284 | $id = uniqid(); |
285 | 285 | } |
286 | 286 | |
287 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
287 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
288 | 288 | |
289 | 289 | $args = array( |
290 | 290 | 'utm_nooverride' => '1', |
291 | 291 | 'order_id' => $order_id, |
292 | 292 | ); |
293 | 293 | |
294 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
294 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
295 | 295 | } |
296 | 296 | |
297 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
297 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | * @param int $order_id |
303 | 303 | * @return boolean |
304 | 304 | */ |
305 | - public function has_subscription( $order_id ) { |
|
306 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
305 | + public function has_subscription($order_id) { |
|
306 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -315,34 +315,33 @@ discard block |
||
315 | 315 | * @param object $prepared_source |
316 | 316 | * @return array() |
317 | 317 | */ |
318 | - public function generate_payment_request( $order, $prepared_source ) { |
|
319 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
320 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
321 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
318 | + public function generate_payment_request($order, $prepared_source) { |
|
319 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
320 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
321 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
322 | 322 | $post_data = array(); |
323 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
324 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
323 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()); |
|
324 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
325 | 325 | /* translators: 1) blog name 2) order number */ |
326 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
327 | - $billing_email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email(); |
|
328 | - $billing_first_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
329 | - $billing_last_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
326 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
327 | + $billing_email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email(); |
|
328 | + $billing_first_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
329 | + $billing_last_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
330 | 330 | |
331 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
331 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
332 | 332 | $post_data['receipt_email'] = $billing_email; |
333 | 333 | } |
334 | 334 | |
335 | - switch ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) { |
|
336 | - case 'stripe': |
|
337 | - if ( ! empty( $statement_descriptor ) ) { |
|
338 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
335 | + switch (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method()) { |
|
336 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
337 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
339 | 338 | } |
340 | 339 | |
341 | 340 | $post_data['capture'] = $capture ? 'true' : 'false'; |
342 | 341 | break; |
343 | 342 | case 'stripe_sepa': |
344 | - if ( ! empty( $statement_descriptor ) ) { |
|
345 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
343 | + if ( ! empty($statement_descriptor)) { |
|
344 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
346 | 345 | } |
347 | 346 | break; |
348 | 347 | } |
@@ -350,25 +349,25 @@ discard block |
||
350 | 349 | $post_data['expand[]'] = 'balance_transaction'; |
351 | 350 | |
352 | 351 | $metadata = array( |
353 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
354 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
352 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
353 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
355 | 354 | 'order_id' => $order->get_order_number(), |
356 | 355 | ); |
357 | 356 | |
358 | - if ( $this->has_subscription( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id() ) ) { |
|
357 | + if ($this->has_subscription(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id())) { |
|
359 | 358 | $metadata += array( |
360 | 359 | 'payment_type' => 'recurring', |
361 | - 'site_url' => esc_url( get_site_url() ), |
|
360 | + 'site_url' => esc_url(get_site_url()), |
|
362 | 361 | ); |
363 | 362 | } |
364 | 363 | |
365 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source ); |
|
364 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source); |
|
366 | 365 | |
367 | - if ( $prepared_source->customer ) { |
|
366 | + if ($prepared_source->customer) { |
|
368 | 367 | $post_data['customer'] = $prepared_source->customer; |
369 | 368 | } |
370 | 369 | |
371 | - if ( $prepared_source->source ) { |
|
370 | + if ($prepared_source->source) { |
|
372 | 371 | $post_data['source'] = $prepared_source->source; |
373 | 372 | } |
374 | 373 | |
@@ -380,72 +379,72 @@ discard block |
||
380 | 379 | * @param WC_Order $order |
381 | 380 | * @param object $source |
382 | 381 | */ |
383 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source ); |
|
382 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source); |
|
384 | 383 | } |
385 | 384 | |
386 | 385 | /** |
387 | 386 | * Store extra meta data for an order from a Stripe Response. |
388 | 387 | */ |
389 | - public function process_response( $response, $order ) { |
|
390 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
388 | + public function process_response($response, $order) { |
|
389 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
391 | 390 | |
392 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
393 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
391 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
392 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
394 | 393 | |
395 | 394 | // Store charge data. |
396 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
395 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
397 | 396 | |
398 | - if ( isset( $response->balance_transaction ) ) { |
|
399 | - $this->update_fees( $order, is_string( $response->balance_transaction ) ? $response->balance_transaction : $response->balance_transaction->id ); |
|
397 | + if (isset($response->balance_transaction)) { |
|
398 | + $this->update_fees($order, is_string($response->balance_transaction) ? $response->balance_transaction : $response->balance_transaction->id); |
|
400 | 399 | } |
401 | 400 | |
402 | - if ( 'yes' === $captured ) { |
|
401 | + if ('yes' === $captured) { |
|
403 | 402 | /** |
404 | 403 | * Charge can be captured but in a pending state. Payment methods |
405 | 404 | * that are asynchronous may take couple days to clear. Webhook will |
406 | 405 | * take care of the status changes. |
407 | 406 | */ |
408 | - if ( 'pending' === $response->status ) { |
|
409 | - $order_stock_reduced = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true ); |
|
407 | + if ('pending' === $response->status) { |
|
408 | + $order_stock_reduced = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true); |
|
410 | 409 | |
411 | - if ( ! $order_stock_reduced ) { |
|
412 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
410 | + if ( ! $order_stock_reduced) { |
|
411 | + WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
413 | 412 | } |
414 | 413 | |
415 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
414 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
416 | 415 | /* translators: transaction id */ |
417 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
416 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
418 | 417 | } |
419 | 418 | |
420 | - if ( 'succeeded' === $response->status ) { |
|
421 | - $order->payment_complete( $response->id ); |
|
419 | + if ('succeeded' === $response->status) { |
|
420 | + $order->payment_complete($response->id); |
|
422 | 421 | |
423 | 422 | /* translators: transaction id */ |
424 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
425 | - $order->add_order_note( $message ); |
|
423 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
424 | + $order->add_order_note($message); |
|
426 | 425 | } |
427 | 426 | |
428 | - if ( 'failed' === $response->status ) { |
|
429 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
430 | - $order->add_order_note( $localized_message ); |
|
431 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
427 | + if ('failed' === $response->status) { |
|
428 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
429 | + $order->add_order_note($localized_message); |
|
430 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
432 | 431 | } |
433 | 432 | } else { |
434 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
433 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
435 | 434 | |
436 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
437 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
435 | + if ($order->has_status(array('pending', 'failed'))) { |
|
436 | + WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
438 | 437 | } |
439 | 438 | |
440 | 439 | /* translators: transaction id */ |
441 | - $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 ) ); |
|
440 | + $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)); |
|
442 | 441 | } |
443 | 442 | |
444 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
443 | + if (is_callable(array($order, 'save'))) { |
|
445 | 444 | $order->save(); |
446 | 445 | } |
447 | 446 | |
448 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
447 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
449 | 448 | |
450 | 449 | return $response; |
451 | 450 | } |
@@ -458,10 +457,10 @@ discard block |
||
458 | 457 | * @param int $order_id |
459 | 458 | * @return null |
460 | 459 | */ |
461 | - public function send_failed_order_email( $order_id ) { |
|
460 | + public function send_failed_order_email($order_id) { |
|
462 | 461 | $emails = WC()->mailer()->get_emails(); |
463 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
464 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
462 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
463 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
465 | 464 | } |
466 | 465 | } |
467 | 466 | |
@@ -473,36 +472,36 @@ discard block |
||
473 | 472 | * @param object $order |
474 | 473 | * @return object $details |
475 | 474 | */ |
476 | - public function get_owner_details( $order ) { |
|
477 | - $billing_first_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
478 | - $billing_last_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
475 | + public function get_owner_details($order) { |
|
476 | + $billing_first_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
477 | + $billing_last_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
479 | 478 | |
480 | 479 | $details = array(); |
481 | 480 | |
482 | 481 | $name = $billing_first_name . ' ' . $billing_last_name; |
483 | - $email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email(); |
|
484 | - $phone = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_phone : $order->get_billing_phone(); |
|
482 | + $email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email(); |
|
483 | + $phone = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_phone : $order->get_billing_phone(); |
|
485 | 484 | |
486 | - if ( ! empty( $phone ) ) { |
|
485 | + if ( ! empty($phone)) { |
|
487 | 486 | $details['phone'] = $phone; |
488 | 487 | } |
489 | 488 | |
490 | - if ( ! empty( $name ) ) { |
|
489 | + if ( ! empty($name)) { |
|
491 | 490 | $details['name'] = $name; |
492 | 491 | } |
493 | 492 | |
494 | - if ( ! empty( $email ) ) { |
|
493 | + if ( ! empty($email)) { |
|
495 | 494 | $details['email'] = $email; |
496 | 495 | } |
497 | 496 | |
498 | - $details['address']['line1'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
499 | - $details['address']['line2'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
500 | - $details['address']['state'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_state : $order->get_billing_state(); |
|
501 | - $details['address']['city'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_city : $order->get_billing_city(); |
|
502 | - $details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_postcode : $order->get_billing_postcode(); |
|
503 | - $details['address']['country'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_country : $order->get_billing_country(); |
|
497 | + $details['address']['line1'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
498 | + $details['address']['line2'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
499 | + $details['address']['state'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_state : $order->get_billing_state(); |
|
500 | + $details['address']['city'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_city : $order->get_billing_city(); |
|
501 | + $details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_postcode : $order->get_billing_postcode(); |
|
502 | + $details['address']['country'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_country : $order->get_billing_country(); |
|
504 | 503 | |
505 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
504 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
506 | 505 | } |
507 | 506 | |
508 | 507 | /** |
@@ -511,15 +510,15 @@ discard block |
||
511 | 510 | * @since 4.0.3 |
512 | 511 | * @param string $source_id The source ID to get source object for. |
513 | 512 | */ |
514 | - public function get_source_object( $source_id = '' ) { |
|
515 | - if ( empty( $source_id ) ) { |
|
513 | + public function get_source_object($source_id = '') { |
|
514 | + if (empty($source_id)) { |
|
516 | 515 | return ''; |
517 | 516 | } |
518 | 517 | |
519 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
518 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
520 | 519 | |
521 | - if ( ! empty( $source_object->error ) ) { |
|
522 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
520 | + if ( ! empty($source_object->error)) { |
|
521 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
523 | 522 | } |
524 | 523 | |
525 | 524 | return $source_object; |
@@ -532,10 +531,10 @@ discard block |
||
532 | 531 | * @param object $source_object |
533 | 532 | * @return bool |
534 | 533 | */ |
535 | - public function is_prepaid_card( $source_object ) { |
|
534 | + public function is_prepaid_card($source_object) { |
|
536 | 535 | return ( |
537 | 536 | $source_object |
538 | - && ( 'token' === $source_object->object || 'source' === $source_object->object ) |
|
537 | + && ('token' === $source_object->object || 'source' === $source_object->object) |
|
539 | 538 | && 'prepaid' === $source_object->card->funding |
540 | 539 | ); |
541 | 540 | } |
@@ -547,8 +546,8 @@ discard block |
||
547 | 546 | * @param string $source_id |
548 | 547 | * @return bool |
549 | 548 | */ |
550 | - public function is_type_legacy_card( $source_id ) { |
|
551 | - return ( preg_match( '/^card_/', $source_id ) ); |
|
549 | + public function is_type_legacy_card($source_id) { |
|
550 | + return (preg_match('/^card_/', $source_id)); |
|
552 | 551 | } |
553 | 552 | |
554 | 553 | /** |
@@ -558,9 +557,9 @@ discard block |
||
558 | 557 | * @return bool |
559 | 558 | */ |
560 | 559 | public function is_using_saved_payment_method() { |
561 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
560 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
562 | 561 | |
563 | - return ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
562 | + return (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']); |
|
564 | 563 | } |
565 | 564 | |
566 | 565 | /** |
@@ -576,64 +575,64 @@ discard block |
||
576 | 575 | * @throws Exception When card was not added or for and invalid card. |
577 | 576 | * @return object |
578 | 577 | */ |
579 | - public function prepare_source( $user_id, $force_save_source = false, $existing_customer_id = null ) { |
|
580 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
581 | - if ( ! empty( $existing_customer_id ) ) { |
|
582 | - $customer->set_id( $existing_customer_id ); |
|
578 | + public function prepare_source($user_id, $force_save_source = false, $existing_customer_id = null) { |
|
579 | + $customer = new WC_Stripe_Customer($user_id); |
|
580 | + if ( ! empty($existing_customer_id)) { |
|
581 | + $customer->set_id($existing_customer_id); |
|
583 | 582 | } |
584 | 583 | |
585 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
584 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
586 | 585 | $source_object = ''; |
587 | 586 | $source_id = ''; |
588 | 587 | $wc_token_id = false; |
589 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
588 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
590 | 589 | $is_token = false; |
591 | 590 | |
592 | 591 | // New CC info was entered and we have a new source to process. |
593 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
594 | - $source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) ); |
|
592 | + if ( ! empty($_POST['stripe_source'])) { |
|
593 | + $source_object = self::get_source_object(wc_clean($_POST['stripe_source'])); |
|
595 | 594 | $source_id = $source_object->id; |
596 | 595 | |
597 | 596 | // This checks to see if customer opted to save the payment method to file. |
598 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
597 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
599 | 598 | |
600 | 599 | /** |
601 | 600 | * This is true if the user wants to store the card to their account. |
602 | 601 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
603 | 602 | * actually reusable. Either that or force_save_source is true. |
604 | 603 | */ |
605 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
606 | - $response = $customer->add_source( $source_object->id ); |
|
604 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
605 | + $response = $customer->add_source($source_object->id); |
|
607 | 606 | |
608 | - if ( ! empty( $response->error ) ) { |
|
609 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
607 | + if ( ! empty($response->error)) { |
|
608 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
610 | 609 | } |
611 | 610 | } |
612 | - } elseif ( $this->is_using_saved_payment_method() ) { |
|
611 | + } elseif ($this->is_using_saved_payment_method()) { |
|
613 | 612 | // Use an existing token, and then process the payment. |
614 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
615 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
613 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
614 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
616 | 615 | |
617 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
618 | - WC()->session->set( 'refresh_totals', true ); |
|
619 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
616 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
617 | + WC()->session->set('refresh_totals', true); |
|
618 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
620 | 619 | } |
621 | 620 | |
622 | 621 | $source_id = $wc_token->get_token(); |
623 | 622 | |
624 | - if ( $this->is_type_legacy_card( $source_id ) ) { |
|
623 | + if ($this->is_type_legacy_card($source_id)) { |
|
625 | 624 | $is_token = true; |
626 | 625 | } |
627 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
628 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
629 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
626 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
627 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
628 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
630 | 629 | |
631 | 630 | // This is true if the user wants to store the card to their account. |
632 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
633 | - $response = $customer->add_source( $stripe_token ); |
|
631 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
632 | + $response = $customer->add_source($stripe_token); |
|
634 | 633 | |
635 | - if ( ! empty( $response->error ) ) { |
|
636 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
634 | + if ( ! empty($response->error)) { |
|
635 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
637 | 636 | } |
638 | 637 | } else { |
639 | 638 | $source_id = $stripe_token; |
@@ -642,15 +641,15 @@ discard block |
||
642 | 641 | } |
643 | 642 | |
644 | 643 | $customer_id = $customer->get_id(); |
645 | - if ( ! $customer_id ) { |
|
646 | - $customer->set_id( $customer->create_customer() ); |
|
644 | + if ( ! $customer_id) { |
|
645 | + $customer->set_id($customer->create_customer()); |
|
647 | 646 | $customer_id = $customer->get_id(); |
648 | 647 | } else { |
649 | 648 | $customer->update_customer(); |
650 | 649 | } |
651 | 650 | |
652 | - if ( empty( $source_object ) && ! $is_token ) { |
|
653 | - $source_object = self::get_source_object( $source_id ); |
|
651 | + if (empty($source_object) && ! $is_token) { |
|
652 | + $source_object = self::get_source_object($source_id); |
|
654 | 653 | } |
655 | 654 | |
656 | 655 | return (object) array( |
@@ -674,39 +673,39 @@ discard block |
||
674 | 673 | * @param object $order |
675 | 674 | * @return object |
676 | 675 | */ |
677 | - public function prepare_order_source( $order = null ) { |
|
676 | + public function prepare_order_source($order = null) { |
|
678 | 677 | $stripe_customer = new WC_Stripe_Customer(); |
679 | 678 | $stripe_source = false; |
680 | 679 | $token_id = false; |
681 | 680 | $source_object = false; |
682 | 681 | |
683 | - if ( $order ) { |
|
684 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
682 | + if ($order) { |
|
683 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
685 | 684 | |
686 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
685 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
687 | 686 | |
688 | - if ( $stripe_customer_id ) { |
|
689 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
687 | + if ($stripe_customer_id) { |
|
688 | + $stripe_customer->set_id($stripe_customer_id); |
|
690 | 689 | } |
691 | 690 | |
692 | - $source_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
691 | + $source_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
693 | 692 | |
694 | 693 | // Since 4.0.0, we changed card to source so we need to account for that. |
695 | - if ( empty( $source_id ) ) { |
|
696 | - $source_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
694 | + if (empty($source_id)) { |
|
695 | + $source_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
697 | 696 | |
698 | 697 | // Take this opportunity to update the key name. |
699 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
698 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
700 | 699 | |
701 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
700 | + if (is_callable(array($order, 'save'))) { |
|
702 | 701 | $order->save(); |
703 | 702 | } |
704 | 703 | } |
705 | 704 | |
706 | - if ( $source_id ) { |
|
705 | + if ($source_id) { |
|
707 | 706 | $stripe_source = $source_id; |
708 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
709 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
707 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
708 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
710 | 709 | /* |
711 | 710 | * We can attempt to charge the customer's default source |
712 | 711 | * by sending empty source id. |
@@ -731,27 +730,27 @@ discard block |
||
731 | 730 | * @param WC_Order $order For to which the source applies. |
732 | 731 | * @param stdClass $source Source information. |
733 | 732 | */ |
734 | - public function save_source_to_order( $order, $source ) { |
|
735 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
733 | + public function save_source_to_order($order, $source) { |
|
734 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
736 | 735 | |
737 | 736 | // Store source in the order. |
738 | - if ( $source->customer ) { |
|
739 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
740 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
737 | + if ($source->customer) { |
|
738 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
739 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
741 | 740 | } else { |
742 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
741 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
743 | 742 | } |
744 | 743 | } |
745 | 744 | |
746 | - if ( $source->source ) { |
|
747 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
748 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
745 | + if ($source->source) { |
|
746 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
747 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
749 | 748 | } else { |
750 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
749 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
751 | 750 | } |
752 | 751 | } |
753 | 752 | |
754 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
753 | + if (is_callable(array($order, 'save'))) { |
|
755 | 754 | $order->save(); |
756 | 755 | } |
757 | 756 | } |
@@ -765,38 +764,38 @@ discard block |
||
765 | 764 | * @param object $order The order object |
766 | 765 | * @param int $balance_transaction_id |
767 | 766 | */ |
768 | - public function update_fees( $order, $balance_transaction_id ) { |
|
769 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
767 | + public function update_fees($order, $balance_transaction_id) { |
|
768 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
770 | 769 | |
771 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
770 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
772 | 771 | |
773 | - if ( empty( $balance_transaction->error ) ) { |
|
774 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
772 | + if (empty($balance_transaction->error)) { |
|
773 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
775 | 774 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
776 | 775 | // values are in the local currency of the Stripe account, not from WC. |
777 | - $fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
778 | - $net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
776 | + $fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
777 | + $net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
779 | 778 | |
780 | 779 | // Current data fee & net. |
781 | - $fee_current = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
782 | - $net_current = WC_Stripe_Helper::get_stripe_net( $order ); |
|
780 | + $fee_current = WC_Stripe_Helper::get_stripe_fee($order); |
|
781 | + $net_current = WC_Stripe_Helper::get_stripe_net($order); |
|
783 | 782 | |
784 | 783 | // Calculation. |
785 | 784 | $fee = (float) $fee_current + (float) $fee_refund; |
786 | 785 | $net = (float) $net_current + (float) $net_refund; |
787 | 786 | |
788 | - WC_Stripe_Helper::update_stripe_fee( $order, $fee ); |
|
789 | - WC_Stripe_Helper::update_stripe_net( $order, $net ); |
|
787 | + WC_Stripe_Helper::update_stripe_fee($order, $fee); |
|
788 | + WC_Stripe_Helper::update_stripe_net($order, $net); |
|
790 | 789 | |
791 | - $currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null; |
|
792 | - WC_Stripe_Helper::update_stripe_currency( $order, $currency ); |
|
790 | + $currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null; |
|
791 | + WC_Stripe_Helper::update_stripe_currency($order, $currency); |
|
793 | 792 | |
794 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
793 | + if (is_callable(array($order, 'save'))) { |
|
795 | 794 | $order->save(); |
796 | 795 | } |
797 | 796 | } |
798 | 797 | } else { |
799 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
798 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
800 | 799 | } |
801 | 800 | } |
802 | 801 | |
@@ -809,99 +808,99 @@ discard block |
||
809 | 808 | * @param float $amount |
810 | 809 | * @return bool |
811 | 810 | */ |
812 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
813 | - $order = wc_get_order( $order_id ); |
|
811 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
812 | + $order = wc_get_order($order_id); |
|
814 | 813 | |
815 | - if ( ! $order ) { |
|
814 | + if ( ! $order) { |
|
816 | 815 | return false; |
817 | 816 | } |
818 | 817 | |
819 | 818 | $request = array(); |
820 | 819 | |
821 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
822 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
823 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
824 | - $charge_id = get_post_meta( $order_id, '_transaction_id', true ); |
|
820 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
821 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
822 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
823 | + $charge_id = get_post_meta($order_id, '_transaction_id', true); |
|
825 | 824 | } else { |
826 | 825 | $order_currency = $order->get_currency(); |
827 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
826 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
828 | 827 | $charge_id = $order->get_transaction_id(); |
829 | 828 | } |
830 | 829 | |
831 | - if ( ! $charge_id ) { |
|
830 | + if ( ! $charge_id) { |
|
832 | 831 | return false; |
833 | 832 | } |
834 | 833 | |
835 | - if ( ! is_null( $amount ) ) { |
|
836 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
834 | + if ( ! is_null($amount)) { |
|
835 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
837 | 836 | } |
838 | 837 | |
839 | 838 | // If order is only authorized, don't pass amount. |
840 | - if ( 'yes' !== $captured ) { |
|
841 | - unset( $request['amount'] ); |
|
839 | + if ('yes' !== $captured) { |
|
840 | + unset($request['amount']); |
|
842 | 841 | } |
843 | 842 | |
844 | - if ( $reason ) { |
|
843 | + if ($reason) { |
|
845 | 844 | $request['metadata'] = array( |
846 | 845 | 'reason' => $reason, |
847 | 846 | ); |
848 | 847 | } |
849 | 848 | |
850 | 849 | $request['charge'] = $charge_id; |
851 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$charge_id} for the amount of {$amount}" ); |
|
850 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$charge_id} for the amount of {$amount}"); |
|
852 | 851 | |
853 | - $request = apply_filters( 'wc_stripe_refund_request', $request, $order ); |
|
852 | + $request = apply_filters('wc_stripe_refund_request', $request, $order); |
|
854 | 853 | |
855 | - $intent = $this->get_intent_from_order( $order ); |
|
854 | + $intent = $this->get_intent_from_order($order); |
|
856 | 855 | $intent_cancelled = false; |
857 | - if ( $intent ) { |
|
856 | + if ($intent) { |
|
858 | 857 | // If the order has a Payment Intent pending capture, then the Intent itself must be refunded (cancelled), not the Charge |
859 | - if ( ! empty( $intent->error ) ) { |
|
858 | + if ( ! empty($intent->error)) { |
|
860 | 859 | $response = $intent; |
861 | 860 | $intent_cancelled = true; |
862 | - } elseif ( 'requires_capture' === $intent->status ) { |
|
861 | + } elseif ('requires_capture' === $intent->status) { |
|
863 | 862 | $result = WC_Stripe_API::request( |
864 | 863 | array(), |
865 | 864 | 'payment_intents/' . $intent->id . '/cancel' |
866 | 865 | ); |
867 | 866 | $intent_cancelled = true; |
868 | 867 | |
869 | - if ( ! empty( $result->error ) ) { |
|
868 | + if ( ! empty($result->error)) { |
|
870 | 869 | $response = $result; |
871 | 870 | } else { |
872 | - $charge = end( $result->charges->data ); |
|
873 | - $response = end( $charge->refunds->data ); |
|
871 | + $charge = end($result->charges->data); |
|
872 | + $response = end($charge->refunds->data); |
|
874 | 873 | } |
875 | 874 | } |
876 | 875 | } |
877 | 876 | |
878 | - if ( ! $intent_cancelled ) { |
|
879 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
877 | + if ( ! $intent_cancelled) { |
|
878 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
880 | 879 | } |
881 | 880 | |
882 | - if ( ! empty( $response->error ) ) { |
|
883 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
881 | + if ( ! empty($response->error)) { |
|
882 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
884 | 883 | |
885 | 884 | return $response; |
886 | 885 | |
887 | - } elseif ( ! empty( $response->id ) ) { |
|
888 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
886 | + } elseif ( ! empty($response->id)) { |
|
887 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
889 | 888 | |
890 | - $amount = wc_price( $response->amount / 100 ); |
|
889 | + $amount = wc_price($response->amount / 100); |
|
891 | 890 | |
892 | - if ( in_array( strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
893 | - $amount = wc_price( $response->amount ); |
|
891 | + if (in_array(strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
892 | + $amount = wc_price($response->amount); |
|
894 | 893 | } |
895 | 894 | |
896 | - if ( isset( $response->balance_transaction ) ) { |
|
897 | - $this->update_fees( $order, $response->balance_transaction ); |
|
895 | + if (isset($response->balance_transaction)) { |
|
896 | + $this->update_fees($order, $response->balance_transaction); |
|
898 | 897 | } |
899 | 898 | |
900 | 899 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
901 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
900 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
902 | 901 | |
903 | - $order->add_order_note( $refund_message ); |
|
904 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) ); |
|
902 | + $order->add_order_note($refund_message); |
|
903 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message))); |
|
905 | 904 | |
906 | 905 | return true; |
907 | 906 | } |
@@ -916,46 +915,46 @@ discard block |
||
916 | 915 | */ |
917 | 916 | public function add_payment_method() { |
918 | 917 | $error = false; |
919 | - $error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' ); |
|
918 | + $error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe'); |
|
920 | 919 | $source_id = ''; |
921 | 920 | |
922 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
921 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
923 | 922 | $error = true; |
924 | 923 | } |
925 | 924 | |
926 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
925 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
927 | 926 | |
928 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
927 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
929 | 928 | |
930 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
929 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
931 | 930 | |
932 | - if ( isset( $source_object ) ) { |
|
933 | - if ( ! empty( $source_object->error ) ) { |
|
931 | + if (isset($source_object)) { |
|
932 | + if ( ! empty($source_object->error)) { |
|
934 | 933 | $error = true; |
935 | 934 | } |
936 | 935 | |
937 | 936 | $source_id = $source_object->id; |
938 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
939 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
937 | + } elseif (isset($_POST['stripe_token'])) { |
|
938 | + $source_id = wc_clean($_POST['stripe_token']); |
|
940 | 939 | } |
941 | 940 | |
942 | - $response = $stripe_customer->add_source( $source_id ); |
|
941 | + $response = $stripe_customer->add_source($source_id); |
|
943 | 942 | |
944 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
943 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
945 | 944 | $error = true; |
946 | 945 | } |
947 | 946 | |
948 | - if ( $error ) { |
|
949 | - wc_add_notice( $error_msg, 'error' ); |
|
950 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
947 | + if ($error) { |
|
948 | + wc_add_notice($error_msg, 'error'); |
|
949 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
951 | 950 | return; |
952 | 951 | } |
953 | 952 | |
954 | - do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object ); |
|
953 | + do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object); |
|
955 | 954 | |
956 | 955 | return array( |
957 | 956 | 'result' => 'success', |
958 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
957 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
959 | 958 | ); |
960 | 959 | } |
961 | 960 | |
@@ -972,10 +971,10 @@ discard block |
||
972 | 971 | * Stripe expects Norwegian to only be passed NO. |
973 | 972 | * But WP has different dialects. |
974 | 973 | */ |
975 | - if ( 'NO' === substr( $locale, 3, 2 ) ) { |
|
974 | + if ('NO' === substr($locale, 3, 2)) { |
|
976 | 975 | $locale = 'no'; |
977 | 976 | } else { |
978 | - $locale = substr( get_locale(), 0, 2 ); |
|
977 | + $locale = substr(get_locale(), 0, 2); |
|
979 | 978 | } |
980 | 979 | |
981 | 980 | return $locale; |
@@ -989,9 +988,9 @@ discard block |
||
989 | 988 | * @param string $idempotency_key |
990 | 989 | * @param array $request |
991 | 990 | */ |
992 | - public function change_idempotency_key( $idempotency_key, $request ) { |
|
993 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
994 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
991 | + public function change_idempotency_key($idempotency_key, $request) { |
|
992 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
993 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
995 | 994 | $count = $this->retry_interval; |
996 | 995 | |
997 | 996 | return $request['metadata']['order_id'] . '-' . $count . '-' . $source; |
@@ -1005,8 +1004,8 @@ discard block |
||
1005 | 1004 | * @since 4.0.6 |
1006 | 1005 | * @param array $headers |
1007 | 1006 | */ |
1008 | - public function is_original_request( $headers ) { |
|
1009 | - if ( $headers['original-request'] === $headers['request-id'] ) { |
|
1007 | + public function is_original_request($headers) { |
|
1008 | + if ($headers['original-request'] === $headers['request-id']) { |
|
1010 | 1009 | return true; |
1011 | 1010 | } |
1012 | 1011 | |
@@ -1020,27 +1019,27 @@ discard block |
||
1020 | 1019 | * @param object $prepared_source The source that is used for the payment. |
1021 | 1020 | * @return array The arguments for the request. |
1022 | 1021 | */ |
1023 | - public function generate_create_intent_request( $order, $prepared_source ) { |
|
1022 | + public function generate_create_intent_request($order, $prepared_source) { |
|
1024 | 1023 | // The request for a charge contains metadata for the intent. |
1025 | - $full_request = $this->generate_payment_request( $order, $prepared_source ); |
|
1024 | + $full_request = $this->generate_payment_request($order, $prepared_source); |
|
1026 | 1025 | |
1027 | 1026 | $request = array( |
1028 | 1027 | 'source' => $prepared_source->source, |
1029 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ), |
|
1030 | - 'currency' => strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ), |
|
1028 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()), |
|
1029 | + 'currency' => strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()), |
|
1031 | 1030 | 'description' => $full_request['description'], |
1032 | 1031 | 'metadata' => $full_request['metadata'], |
1033 | - 'capture_method' => ( 'true' === $full_request['capture'] ) ? 'automatic' : 'manual', |
|
1032 | + 'capture_method' => ('true' === $full_request['capture']) ? 'automatic' : 'manual', |
|
1034 | 1033 | 'payment_method_types' => array( |
1035 | 1034 | 'card', |
1036 | 1035 | ), |
1037 | 1036 | ); |
1038 | 1037 | |
1039 | - if ( $prepared_source->customer ) { |
|
1038 | + if ($prepared_source->customer) { |
|
1040 | 1039 | $request['customer'] = $prepared_source->customer; |
1041 | 1040 | } |
1042 | 1041 | |
1043 | - if ( isset( $full_request['statement_descriptor'] ) ) { |
|
1042 | + if (isset($full_request['statement_descriptor'])) { |
|
1044 | 1043 | $request['statement_descriptor'] = $full_request['statement_descriptor']; |
1045 | 1044 | } |
1046 | 1045 | |
@@ -1052,7 +1051,7 @@ discard block |
||
1052 | 1051 | * @param WC_Order $order |
1053 | 1052 | * @param object $source |
1054 | 1053 | */ |
1055 | - return apply_filters( 'wc_stripe_generate_create_intent_request', $request, $order, $prepared_source ); |
|
1054 | + return apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source); |
|
1056 | 1055 | } |
1057 | 1056 | |
1058 | 1057 | /** |
@@ -1062,20 +1061,20 @@ discard block |
||
1062 | 1061 | * @param object $prepared_source The source that is used for the payment. |
1063 | 1062 | * @return object An intent or an error. |
1064 | 1063 | */ |
1065 | - public function create_intent( $order, $prepared_source ) { |
|
1066 | - $request = $this->generate_create_intent_request( $order, $prepared_source ); |
|
1064 | + public function create_intent($order, $prepared_source) { |
|
1065 | + $request = $this->generate_create_intent_request($order, $prepared_source); |
|
1067 | 1066 | |
1068 | 1067 | // Create an intent that awaits an action. |
1069 | - $intent = WC_Stripe_API::request( $request, 'payment_intents' ); |
|
1070 | - if ( ! empty( $intent->error ) ) { |
|
1068 | + $intent = WC_Stripe_API::request($request, 'payment_intents'); |
|
1069 | + if ( ! empty($intent->error)) { |
|
1071 | 1070 | return $intent; |
1072 | 1071 | } |
1073 | 1072 | |
1074 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
1075 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id initiated for order $order_id" ); |
|
1073 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
1074 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id initiated for order $order_id"); |
|
1076 | 1075 | |
1077 | 1076 | // Save the intent ID to the order. |
1078 | - $this->save_intent_to_order( $order, $intent ); |
|
1077 | + $this->save_intent_to_order($order, $intent); |
|
1079 | 1078 | |
1080 | 1079 | return $intent; |
1081 | 1080 | } |
@@ -1088,27 +1087,27 @@ discard block |
||
1088 | 1087 | * @param object $prepared_source Currently selected source. |
1089 | 1088 | * @return object An updated intent. |
1090 | 1089 | */ |
1091 | - public function update_existing_intent( $intent, $order, $prepared_source ) { |
|
1090 | + public function update_existing_intent($intent, $order, $prepared_source) { |
|
1092 | 1091 | $request = array(); |
1093 | 1092 | |
1094 | - if ( $prepared_source->source !== $intent->source ) { |
|
1093 | + if ($prepared_source->source !== $intent->source) { |
|
1095 | 1094 | $request['source'] = $prepared_source->source; |
1096 | 1095 | } |
1097 | 1096 | |
1098 | - $new_amount = WC_Stripe_Helper::get_stripe_amount( $order->get_total() ); |
|
1099 | - if ( $intent->amount !== $new_amount ) { |
|
1097 | + $new_amount = WC_Stripe_Helper::get_stripe_amount($order->get_total()); |
|
1098 | + if ($intent->amount !== $new_amount) { |
|
1100 | 1099 | $request['amount'] = $new_amount; |
1101 | 1100 | } |
1102 | 1101 | |
1103 | - if ( $prepared_source->customer && $intent->customer !== $prepared_source->customer ) { |
|
1102 | + if ($prepared_source->customer && $intent->customer !== $prepared_source->customer) { |
|
1104 | 1103 | $request['customer'] = $prepared_source->customer; |
1105 | 1104 | } |
1106 | 1105 | |
1107 | - if ( empty( $request ) ) { |
|
1106 | + if (empty($request)) { |
|
1108 | 1107 | return $intent; |
1109 | 1108 | } |
1110 | 1109 | |
1111 | - return WC_Stripe_API::request( $request, "payment_intents/$intent->id" ); |
|
1110 | + return WC_Stripe_API::request($request, "payment_intents/$intent->id"); |
|
1112 | 1111 | } |
1113 | 1112 | |
1114 | 1113 | /** |
@@ -1120,8 +1119,8 @@ discard block |
||
1120 | 1119 | * @param object $prepared_source The source that is being charged. |
1121 | 1120 | * @return object Either an error or the updated intent. |
1122 | 1121 | */ |
1123 | - public function confirm_intent( $intent, $order, $prepared_source ) { |
|
1124 | - if ( 'requires_confirmation' !== $intent->status ) { |
|
1122 | + public function confirm_intent($intent, $order, $prepared_source) { |
|
1123 | + if ('requires_confirmation' !== $intent->status) { |
|
1125 | 1124 | return $intent; |
1126 | 1125 | } |
1127 | 1126 | |
@@ -1130,18 +1129,18 @@ discard block |
||
1130 | 1129 | 'source' => $prepared_source->source, |
1131 | 1130 | ); |
1132 | 1131 | |
1133 | - $confirmed_intent = WC_Stripe_API::request( $confirm_request, "payment_intents/$intent->id/confirm" ); |
|
1132 | + $confirmed_intent = WC_Stripe_API::request($confirm_request, "payment_intents/$intent->id/confirm"); |
|
1134 | 1133 | |
1135 | - if ( ! empty( $confirmed_intent->error ) ) { |
|
1134 | + if ( ! empty($confirmed_intent->error)) { |
|
1136 | 1135 | return $confirmed_intent; |
1137 | 1136 | } |
1138 | 1137 | |
1139 | 1138 | // Save a note about the status of the intent. |
1140 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
1141 | - if ( 'succeeded' === $confirmed_intent->status ) { |
|
1142 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" ); |
|
1143 | - } elseif ( 'requires_action' === $confirmed_intent->status ) { |
|
1144 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id requires authentication for order $order_id" ); |
|
1139 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
1140 | + if ('succeeded' === $confirmed_intent->status) { |
|
1141 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id"); |
|
1142 | + } elseif ('requires_action' === $confirmed_intent->status) { |
|
1143 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id requires authentication for order $order_id"); |
|
1145 | 1144 | } |
1146 | 1145 | |
1147 | 1146 | return $confirmed_intent; |
@@ -1154,16 +1153,16 @@ discard block |
||
1154 | 1153 | * @param WC_Order $order For to which the source applies. |
1155 | 1154 | * @param stdClass $intent Payment intent information. |
1156 | 1155 | */ |
1157 | - public function save_intent_to_order( $order, $intent ) { |
|
1158 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
1156 | + public function save_intent_to_order($order, $intent) { |
|
1157 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
1159 | 1158 | |
1160 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
1161 | - update_post_meta( $order_id, '_stripe_intent_id', $intent->id ); |
|
1159 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
1160 | + update_post_meta($order_id, '_stripe_intent_id', $intent->id); |
|
1162 | 1161 | } else { |
1163 | - $order->update_meta_data( '_stripe_intent_id', $intent->id ); |
|
1162 | + $order->update_meta_data('_stripe_intent_id', $intent->id); |
|
1164 | 1163 | } |
1165 | 1164 | |
1166 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
1165 | + if (is_callable(array($order, 'save'))) { |
|
1167 | 1166 | $order->save(); |
1168 | 1167 | } |
1169 | 1168 | } |
@@ -1175,28 +1174,28 @@ discard block |
||
1175 | 1174 | * @param WC_Order $order The order to retrieve an intent for. |
1176 | 1175 | * @return obect|bool Either the intent object or `false`. |
1177 | 1176 | */ |
1178 | - public function get_intent_from_order( $order ) { |
|
1179 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
1177 | + public function get_intent_from_order($order) { |
|
1178 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
1180 | 1179 | |
1181 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
1182 | - $intent_id = get_post_meta( $order_id, '_stripe_intent_id', true ); |
|
1180 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
1181 | + $intent_id = get_post_meta($order_id, '_stripe_intent_id', true); |
|
1183 | 1182 | } else { |
1184 | - $intent_id = $order->get_meta( '_stripe_intent_id' ); |
|
1183 | + $intent_id = $order->get_meta('_stripe_intent_id'); |
|
1185 | 1184 | } |
1186 | 1185 | |
1187 | - if ( $intent_id ) { |
|
1188 | - return WC_Stripe_API::request( array(), "payment_intents/$intent_id", 'GET' ); |
|
1186 | + if ($intent_id) { |
|
1187 | + return WC_Stripe_API::request(array(), "payment_intents/$intent_id", 'GET'); |
|
1189 | 1188 | } |
1190 | 1189 | |
1191 | 1190 | // The order doesn't have a payment intent, but it may have a setup intent. |
1192 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
1193 | - $intent_id = get_post_meta( $order_id, '_stripe_setup_intent', true ); |
|
1191 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
1192 | + $intent_id = get_post_meta($order_id, '_stripe_setup_intent', true); |
|
1194 | 1193 | } else { |
1195 | - $intent_id = $order->get_meta( '_stripe_setup_intent' ); |
|
1194 | + $intent_id = $order->get_meta('_stripe_setup_intent'); |
|
1196 | 1195 | } |
1197 | 1196 | |
1198 | - if ( $intent_id ) { |
|
1199 | - return WC_Stripe_API::request( array(), "setup_intents/$intent_id", 'GET' ); |
|
1197 | + if ($intent_id) { |
|
1198 | + return WC_Stripe_API::request(array(), "setup_intents/$intent_id", 'GET'); |
|
1200 | 1199 | } |
1201 | 1200 | |
1202 | 1201 | return false; |
@@ -1210,18 +1209,18 @@ discard block |
||
1210 | 1209 | * @param stdClass $intent The intent that is being processed. |
1211 | 1210 | * @return bool A flag that indicates whether the order is already locked. |
1212 | 1211 | */ |
1213 | - public function lock_order_payment( $order, $intent = null ) { |
|
1214 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
1212 | + public function lock_order_payment($order, $intent = null) { |
|
1213 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
1215 | 1214 | $transient_name = 'wc_stripe_processing_intent_' . $order_id; |
1216 | - $processing = get_transient( $transient_name ); |
|
1215 | + $processing = get_transient($transient_name); |
|
1217 | 1216 | |
1218 | 1217 | // Block the process if the same intent is already being handled. |
1219 | - if ( "-1" === $processing || ( isset( $intent->id ) && $processing === $intent->id ) ) { |
|
1218 | + if ("-1" === $processing || (isset($intent->id) && $processing === $intent->id)) { |
|
1220 | 1219 | return true; |
1221 | 1220 | } |
1222 | 1221 | |
1223 | 1222 | // Save the new intent as a transient, eventually overwriting another one. |
1224 | - set_transient( $transient_name, empty( $intent ) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS ); |
|
1223 | + set_transient($transient_name, empty($intent) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS); |
|
1225 | 1224 | |
1226 | 1225 | return false; |
1227 | 1226 | } |
@@ -1232,9 +1231,9 @@ discard block |
||
1232 | 1231 | * @since 4.2 |
1233 | 1232 | * @param WC_Order $order The order that is being unlocked. |
1234 | 1233 | */ |
1235 | - public function unlock_order_payment( $order ) { |
|
1236 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
1237 | - delete_transient( 'wc_stripe_processing_intent_' . $order_id ); |
|
1234 | + public function unlock_order_payment($order) { |
|
1235 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
1236 | + delete_transient('wc_stripe_processing_intent_' . $order_id); |
|
1238 | 1237 | } |
1239 | 1238 | |
1240 | 1239 | /** |
@@ -1244,9 +1243,9 @@ discard block |
||
1244 | 1243 | * @param object $response The response from Stripe. |
1245 | 1244 | * @return boolean Whether or not it's a 'authentication_required' error |
1246 | 1245 | */ |
1247 | - public function is_authentication_required_for_payment( $response ) { |
|
1248 | - return ( ! empty( $response->error ) && 'authentication_required' === $response->error->code ) |
|
1249 | - || ( ! empty( $response->last_payment_error ) && 'authentication_required' === $response->last_payment_error->code ); |
|
1246 | + public function is_authentication_required_for_payment($response) { |
|
1247 | + return ( ! empty($response->error) && 'authentication_required' === $response->error->code) |
|
1248 | + || ( ! empty($response->last_payment_error) && 'authentication_required' === $response->last_payment_error->code); |
|
1250 | 1249 | } |
1251 | 1250 | |
1252 | 1251 | /** |
@@ -1256,21 +1255,21 @@ discard block |
||
1256 | 1255 | * @param object $prepared_source The source, entered/chosen by the customer. |
1257 | 1256 | * @return string The client secret of the intent, used for confirmation in JS. |
1258 | 1257 | */ |
1259 | - public function setup_intent( $order, $prepared_source ) { |
|
1260 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
1261 | - $setup_intent = WC_Stripe_API::request( array( |
|
1258 | + public function setup_intent($order, $prepared_source) { |
|
1259 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
1260 | + $setup_intent = WC_Stripe_API::request(array( |
|
1262 | 1261 | 'payment_method' => $prepared_source->source, |
1263 | 1262 | 'customer' => $prepared_source->customer, |
1264 | 1263 | 'confirm' => 'true', |
1265 | - ), 'setup_intents' ); |
|
1264 | + ), 'setup_intents'); |
|
1266 | 1265 | |
1267 | - if ( is_wp_error( $setup_intent ) ) { |
|
1268 | - WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) ); |
|
1269 | - } elseif ( 'requires_action' === $setup_intent->status ) { |
|
1270 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
1271 | - update_post_meta( $order_id, '_stripe_setup_intent', $setup_intent->id ); |
|
1266 | + if (is_wp_error($setup_intent)) { |
|
1267 | + WC_Stripe_Logger::log("Unable to create SetupIntent for Order #$order_id: " . print_r($setup_intent, true)); |
|
1268 | + } elseif ('requires_action' === $setup_intent->status) { |
|
1269 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
1270 | + update_post_meta($order_id, '_stripe_setup_intent', $setup_intent->id); |
|
1272 | 1271 | } else { |
1273 | - $order->update_meta_data( '_stripe_setup_intent', $setup_intent->id ); |
|
1272 | + $order->update_meta_data('_stripe_setup_intent', $setup_intent->id); |
|
1274 | 1273 | $order->save(); |
1275 | 1274 | } |
1276 | 1275 | |
@@ -1286,12 +1285,12 @@ discard block |
||
1286 | 1285 | * @param float $amount The amount to charge. If not specified, it will be read from the order. |
1287 | 1286 | * @return object An intent or an error. |
1288 | 1287 | */ |
1289 | - public function create_and_confirm_intent_for_off_session( $order, $prepared_source, $amount = NULL ) { |
|
1288 | + public function create_and_confirm_intent_for_off_session($order, $prepared_source, $amount = NULL) { |
|
1290 | 1289 | // The request for a charge contains metadata for the intent. |
1291 | - $full_request = $this->generate_payment_request( $order, $prepared_source ); |
|
1290 | + $full_request = $this->generate_payment_request($order, $prepared_source); |
|
1292 | 1291 | |
1293 | 1292 | $request = array( |
1294 | - 'amount' => $amount ? WC_Stripe_Helper::get_stripe_amount( $amount, $full_request['currency'] ) : $full_request['amount'], |
|
1293 | + 'amount' => $amount ? WC_Stripe_Helper::get_stripe_amount($amount, $full_request['currency']) : $full_request['amount'], |
|
1295 | 1294 | 'currency' => $full_request['currency'], |
1296 | 1295 | 'description' => $full_request['description'], |
1297 | 1296 | 'metadata' => $full_request['metadata'], |
@@ -1303,38 +1302,38 @@ discard block |
||
1303 | 1302 | 'confirmation_method' => 'automatic', |
1304 | 1303 | ); |
1305 | 1304 | |
1306 | - if ( isset( $full_request['statement_descriptor'] ) ) { |
|
1305 | + if (isset($full_request['statement_descriptor'])) { |
|
1307 | 1306 | $request['statement_descriptor'] = $full_request['statement_descriptor']; |
1308 | 1307 | } |
1309 | 1308 | |
1310 | - if ( isset( $full_request['customer'] ) ) { |
|
1309 | + if (isset($full_request['customer'])) { |
|
1311 | 1310 | $request['customer'] = $full_request['customer']; |
1312 | 1311 | } |
1313 | 1312 | |
1314 | - if ( isset( $full_request['source'] ) ) { |
|
1313 | + if (isset($full_request['source'])) { |
|
1315 | 1314 | $request['source'] = $full_request['source']; |
1316 | 1315 | } |
1317 | 1316 | |
1318 | - $intent = WC_Stripe_API::request( $request, 'payment_intents' ); |
|
1319 | - $is_authentication_required = $this->is_authentication_required_for_payment( $intent ); |
|
1317 | + $intent = WC_Stripe_API::request($request, 'payment_intents'); |
|
1318 | + $is_authentication_required = $this->is_authentication_required_for_payment($intent); |
|
1320 | 1319 | |
1321 | - if ( ! empty( $intent->error ) && ! $is_authentication_required ) { |
|
1320 | + if ( ! empty($intent->error) && ! $is_authentication_required) { |
|
1322 | 1321 | return $intent; |
1323 | 1322 | } |
1324 | 1323 | |
1325 | - $intent_id = ( ! empty( $intent->error ) |
|
1324 | + $intent_id = ( ! empty($intent->error) |
|
1326 | 1325 | ? $intent->error->payment_intent->id |
1327 | 1326 | : $intent->id |
1328 | 1327 | ); |
1329 | - $payment_intent = ( ! empty( $intent->error ) |
|
1328 | + $payment_intent = ( ! empty($intent->error) |
|
1330 | 1329 | ? $intent->error->payment_intent |
1331 | 1330 | : $intent |
1332 | 1331 | ); |
1333 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
1334 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent_id initiated for order $order_id" ); |
|
1332 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
1333 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent_id initiated for order $order_id"); |
|
1335 | 1334 | |
1336 | 1335 | // Save the intent ID to the order. |
1337 | - $this->save_intent_to_order( $order, $payment_intent ); |
|
1336 | + $this->save_intent_to_order($order, $payment_intent); |
|
1338 | 1337 | |
1339 | 1338 | return $intent; |
1340 | 1339 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | |
24 | 24 | $this->retry_interval = 1; |
25 | 25 | |
26 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
27 | - add_action( 'woocommerce_order_status_processing', array( $this, 'capture_payment' ) ); |
|
28 | - add_action( 'woocommerce_order_status_completed', array( $this, 'capture_payment' ) ); |
|
29 | - add_action( 'woocommerce_order_status_cancelled', array( $this, 'cancel_payment' ) ); |
|
30 | - add_action( 'woocommerce_order_status_refunded', array( $this, 'cancel_payment' ) ); |
|
26 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
27 | + add_action('woocommerce_order_status_processing', array($this, 'capture_payment')); |
|
28 | + add_action('woocommerce_order_status_completed', array($this, 'capture_payment')); |
|
29 | + add_action('woocommerce_order_status_cancelled', array($this, 'cancel_payment')); |
|
30 | + add_action('woocommerce_order_status_refunded', array($this, 'cancel_payment')); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -51,25 +51,25 @@ discard block |
||
51 | 51 | * @param bool $retry |
52 | 52 | * @param mix $previous_error Any error message from previous request. |
53 | 53 | */ |
54 | - public function process_redirect_payment( $order_id, $retry = true, $previous_error = false ) { |
|
54 | + public function process_redirect_payment($order_id, $retry = true, $previous_error = false) { |
|
55 | 55 | try { |
56 | - $source = wc_clean( $_GET['source'] ); |
|
56 | + $source = wc_clean($_GET['source']); |
|
57 | 57 | |
58 | - if ( empty( $source ) ) { |
|
58 | + if (empty($source)) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
62 | - if ( empty( $order_id ) ) { |
|
62 | + if (empty($order_id)) { |
|
63 | 63 | return; |
64 | 64 | } |
65 | 65 | |
66 | - $order = wc_get_order( $order_id ); |
|
66 | + $order = wc_get_order($order_id); |
|
67 | 67 | |
68 | - if ( ! is_object( $order ) ) { |
|
68 | + if ( ! is_object($order)) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | - if ( $order->has_status( array( 'processing', 'completed', 'on-hold' ) ) ) { |
|
72 | + if ($order->has_status(array('processing', 'completed', 'on-hold'))) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
@@ -77,124 +77,124 @@ discard block |
||
77 | 77 | $response = null; |
78 | 78 | |
79 | 79 | // This will throw exception if not valid. |
80 | - $this->validate_minimum_order_amount( $order ); |
|
80 | + $this->validate_minimum_order_amount($order); |
|
81 | 81 | |
82 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
82 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * First check if the source is chargeable at this time. If not, |
86 | 86 | * webhook will take care of it later. |
87 | 87 | */ |
88 | - $source_info = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
88 | + $source_info = WC_Stripe_API::retrieve('sources/' . $source); |
|
89 | 89 | |
90 | - if ( ! empty( $source_info->error ) ) { |
|
91 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message ); |
|
90 | + if ( ! empty($source_info->error)) { |
|
91 | + throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message); |
|
92 | 92 | } |
93 | 93 | |
94 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
95 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) ); |
|
94 | + if ('failed' === $source_info->status || 'canceled' === $source_info->status) { |
|
95 | + throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe')); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // If already consumed, then ignore request. |
99 | - if ( 'consumed' === $source_info->status ) { |
|
99 | + if ('consumed' === $source_info->status) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | 103 | // If not chargeable, then ignore request. |
104 | - if ( 'chargeable' !== $source_info->status ) { |
|
104 | + if ('chargeable' !== $source_info->status) { |
|
105 | 105 | return; |
106 | 106 | } |
107 | 107 | |
108 | 108 | // Prep source object. |
109 | 109 | $source_object = new stdClass(); |
110 | 110 | $source_object->token_id = ''; |
111 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
111 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
112 | 112 | $source_object->source = $source_info->id; |
113 | 113 | $source_object->status = 'chargeable'; |
114 | 114 | |
115 | 115 | /* If we're doing a retry and source is chargeable, we need to pass |
116 | 116 | * a different idempotency key and retry for success. |
117 | 117 | */ |
118 | - if ( $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
119 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
118 | + if ($this->need_update_idempotency_key($source_object, $previous_error)) { |
|
119 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | // Make the request. |
123 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true ); |
|
123 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true); |
|
124 | 124 | $headers = $response['headers']; |
125 | 125 | $response = $response['body']; |
126 | 126 | |
127 | - if ( ! empty( $response->error ) ) { |
|
127 | + if ( ! empty($response->error)) { |
|
128 | 128 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
129 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
130 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
131 | - delete_user_option( $order->customer_user, '_stripe_customer_id' ); |
|
132 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
129 | + if ($this->is_no_such_customer_error($response->error)) { |
|
130 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
131 | + delete_user_option($order->customer_user, '_stripe_customer_id'); |
|
132 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
133 | 133 | } else { |
134 | - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); |
|
135 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
134 | + delete_user_option($order->get_customer_id(), '_stripe_customer_id'); |
|
135 | + $order->delete_meta_data('_stripe_customer_id'); |
|
136 | 136 | $order->save(); |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
140 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
141 | 141 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
142 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
142 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
143 | 143 | $wc_token->delete(); |
144 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
145 | - $order->add_order_note( $localized_message ); |
|
146 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
144 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
145 | + $order->add_order_note($localized_message); |
|
146 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // We want to retry. |
150 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
151 | - if ( $retry ) { |
|
150 | + if ($this->is_retryable_error($response->error)) { |
|
151 | + if ($retry) { |
|
152 | 152 | // Don't do anymore retries after this. |
153 | - if ( 5 <= $this->retry_interval ) { |
|
154 | - return $this->process_redirect_payment( $order_id, false, $response->error ); |
|
153 | + if (5 <= $this->retry_interval) { |
|
154 | + return $this->process_redirect_payment($order_id, false, $response->error); |
|
155 | 155 | } |
156 | 156 | |
157 | - sleep( $this->retry_interval ); |
|
157 | + sleep($this->retry_interval); |
|
158 | 158 | |
159 | 159 | $this->retry_interval++; |
160 | - return $this->process_redirect_payment( $order_id, true, $response->error ); |
|
160 | + return $this->process_redirect_payment($order_id, true, $response->error); |
|
161 | 161 | } else { |
162 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
163 | - $order->add_order_note( $localized_message ); |
|
164 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
162 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
163 | + $order->add_order_note($localized_message); |
|
164 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
169 | 169 | |
170 | - if ( 'card_error' === $response->error->type ) { |
|
171 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
170 | + if ('card_error' === $response->error->type) { |
|
171 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
172 | 172 | } else { |
173 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
173 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
174 | 174 | } |
175 | 175 | |
176 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
176 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | // To prevent double processing the order on WC side. |
180 | - if ( ! $this->is_original_request( $headers ) ) { |
|
180 | + if ( ! $this->is_original_request($headers)) { |
|
181 | 181 | return; |
182 | 182 | } |
183 | 183 | |
184 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
184 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
185 | 185 | |
186 | - $this->process_response( $response, $order ); |
|
186 | + $this->process_response($response, $order); |
|
187 | 187 | |
188 | - } catch ( WC_Stripe_Exception $e ) { |
|
189 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
188 | + } catch (WC_Stripe_Exception $e) { |
|
189 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
190 | 190 | |
191 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
191 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
192 | 192 | |
193 | 193 | /* translators: error message */ |
194 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) ); |
|
194 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage())); |
|
195 | 195 | |
196 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
197 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
196 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
197 | + wp_safe_redirect(wc_get_checkout_url()); |
|
198 | 198 | exit; |
199 | 199 | } |
200 | 200 | } |
@@ -206,13 +206,13 @@ discard block |
||
206 | 206 | * @version 4.0.0 |
207 | 207 | */ |
208 | 208 | public function maybe_process_redirect_order() { |
209 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
209 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | 212 | |
213 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
213 | + $order_id = wc_clean($_GET['order_id']); |
|
214 | 214 | |
215 | - $this->process_redirect_payment( $order_id ); |
|
215 | + $this->process_redirect_payment($order_id); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -222,92 +222,92 @@ discard block |
||
222 | 222 | * @version 4.0.0 |
223 | 223 | * @param int $order_id |
224 | 224 | */ |
225 | - public function capture_payment( $order_id ) { |
|
226 | - $order = wc_get_order( $order_id ); |
|
225 | + public function capture_payment($order_id) { |
|
226 | + $order = wc_get_order($order_id); |
|
227 | 227 | |
228 | - if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
229 | - $charge = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
230 | - $captured = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
228 | + if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) { |
|
229 | + $charge = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
230 | + $captured = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
231 | 231 | $is_stripe_captured = false; |
232 | 232 | |
233 | - if ( $charge && 'no' === $captured ) { |
|
233 | + if ($charge && 'no' === $captured) { |
|
234 | 234 | $order_total = $order->get_total(); |
235 | 235 | |
236 | - if ( 0 < $order->get_total_refunded() ) { |
|
236 | + if (0 < $order->get_total_refunded()) { |
|
237 | 237 | $order_total = $order_total - $order->get_total_refunded(); |
238 | 238 | } |
239 | 239 | |
240 | - $intent = $this->get_intent_from_order( $order ); |
|
241 | - if ( $intent ) { |
|
240 | + $intent = $this->get_intent_from_order($order); |
|
241 | + if ($intent) { |
|
242 | 242 | // If the order has a Payment Intent, then the Intent itself must be captured, not the Charge |
243 | - if ( ! empty( $intent->error ) ) { |
|
243 | + if ( ! empty($intent->error)) { |
|
244 | 244 | /* translators: error message */ |
245 | - $order->add_order_note( sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $intent->error->message ) ); |
|
246 | - } elseif ( 'requires_capture' === $intent->status ) { |
|
245 | + $order->add_order_note(sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $intent->error->message)); |
|
246 | + } elseif ('requires_capture' === $intent->status) { |
|
247 | 247 | $result = WC_Stripe_API::request( |
248 | 248 | array( |
249 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
249 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
250 | 250 | 'expand[]' => 'charges.data.balance_transaction', |
251 | 251 | ), |
252 | 252 | 'payment_intents/' . $intent->id . '/capture' |
253 | 253 | ); |
254 | 254 | |
255 | - if ( ! empty( $result->error ) ) { |
|
255 | + if ( ! empty($result->error)) { |
|
256 | 256 | /* translators: error message */ |
257 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
257 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
258 | 258 | } else { |
259 | 259 | $is_stripe_captured = true; |
260 | - $result = end( $result->charges->data ); |
|
260 | + $result = end($result->charges->data); |
|
261 | 261 | } |
262 | - } elseif ( 'succeeded' === $intent->status ) { |
|
262 | + } elseif ('succeeded' === $intent->status) { |
|
263 | 263 | $is_stripe_captured = true; |
264 | 264 | } |
265 | 265 | } else { |
266 | 266 | // The order doesn't have a Payment Intent, fall back to capturing the Charge directly |
267 | 267 | |
268 | 268 | // First retrieve charge to see if it has been captured. |
269 | - $result = WC_Stripe_API::retrieve( 'charges/' . $charge ); |
|
269 | + $result = WC_Stripe_API::retrieve('charges/' . $charge); |
|
270 | 270 | |
271 | - if ( ! empty( $result->error ) ) { |
|
271 | + if ( ! empty($result->error)) { |
|
272 | 272 | /* translators: error message */ |
273 | - $order->add_order_note( sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
274 | - } elseif ( false === $result->captured ) { |
|
273 | + $order->add_order_note(sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
274 | + } elseif (false === $result->captured) { |
|
275 | 275 | $result = WC_Stripe_API::request( |
276 | 276 | array( |
277 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
277 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
278 | 278 | 'expand[]' => 'balance_transaction', |
279 | 279 | ), |
280 | 280 | 'charges/' . $charge . '/capture' |
281 | 281 | ); |
282 | 282 | |
283 | - if ( ! empty( $result->error ) ) { |
|
283 | + if ( ! empty($result->error)) { |
|
284 | 284 | /* translators: error message */ |
285 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
285 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
286 | 286 | } else { |
287 | 287 | $is_stripe_captured = true; |
288 | 288 | } |
289 | - } elseif ( true === $result->captured ) { |
|
289 | + } elseif (true === $result->captured) { |
|
290 | 290 | $is_stripe_captured = true; |
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
294 | - if ( $is_stripe_captured ) { |
|
294 | + if ($is_stripe_captured) { |
|
295 | 295 | /* translators: transaction id */ |
296 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
297 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
296 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
297 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
298 | 298 | |
299 | 299 | // Store other data such as fees |
300 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
300 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
301 | 301 | |
302 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
302 | + if (is_callable(array($order, 'save'))) { |
|
303 | 303 | $order->save(); |
304 | 304 | } |
305 | 305 | |
306 | - $this->update_fees( $order, $result->balance_transaction->id ); |
|
306 | + $this->update_fees($order, $result->balance_transaction->id); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | // This hook fires when admin manually changes order status to processing or completed. |
310 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
310 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
311 | 311 | } |
312 | 312 | } |
313 | 313 | } |
@@ -319,19 +319,19 @@ discard block |
||
319 | 319 | * @version 4.2.2 |
320 | 320 | * @param int $order_id |
321 | 321 | */ |
322 | - public function cancel_payment( $order_id ) { |
|
323 | - $order = wc_get_order( $order_id ); |
|
324 | - |
|
325 | - if ( 'stripe' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
326 | - $captured = WC_Stripe_Helper::is_wc_lt( '3.0' ) |
|
327 | - ? get_post_meta( $order_id, '_stripe_charge_captured', true ) |
|
328 | - : $order->get_meta( '_stripe_charge_captured', true ); |
|
329 | - if ( 'no' === $captured ) { |
|
330 | - $this->process_refund( $order_id ); |
|
322 | + public function cancel_payment($order_id) { |
|
323 | + $order = wc_get_order($order_id); |
|
324 | + |
|
325 | + if ('stripe' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method())) { |
|
326 | + $captured = WC_Stripe_Helper::is_wc_lt('3.0') |
|
327 | + ? get_post_meta($order_id, '_stripe_charge_captured', true) |
|
328 | + : $order->get_meta('_stripe_charge_captured', true); |
|
329 | + if ('no' === $captured) { |
|
330 | + $this->process_refund($order_id); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | // This hook fires when admin manually changes order status to cancel. |
334 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order ); |
|
334 | + do_action('woocommerce_stripe_process_manual_cancel', $order); |
|
335 | 335 | } |
336 | 336 | } |
337 | 337 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | * @since 4.1.0 |
22 | 22 | */ |
23 | 23 | public function __construct() { |
24 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
25 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
26 | - add_action( 'woocommerce_stripe_updated', array( $this, 'stripe_updated' ) ); |
|
24 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
25 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
26 | + add_action('woocommerce_stripe_updated', array($this, 'stripe_updated')); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | * @since 1.0.0 |
33 | 33 | * @version 4.0.0 |
34 | 34 | */ |
35 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
36 | - $this->notices[ $slug ] = array( |
|
35 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
36 | + $this->notices[$slug] = array( |
|
37 | 37 | 'class' => $class, |
38 | 38 | 'message' => $message, |
39 | 39 | 'dismissible' => $dismissible, |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @version 4.0.0 |
48 | 48 | */ |
49 | 49 | public function admin_notices() { |
50 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
50 | + if ( ! current_user_can('manage_woocommerce')) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
@@ -57,17 +57,17 @@ discard block |
||
57 | 57 | // All other payment methods. |
58 | 58 | $this->payment_methods_check_environment(); |
59 | 59 | |
60 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
61 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
60 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
61 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
62 | 62 | |
63 | - if ( $notice['dismissible'] ) { |
|
63 | + if ($notice['dismissible']) { |
|
64 | 64 | ?> |
65 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:relative;float:right;padding:9px 0px 9px 9px 9px;text-decoration:none;"></a> |
|
65 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:relative;float:right;padding:9px 0px 9px 9px 9px;text-decoration:none;"></a> |
|
66 | 66 | <?php |
67 | 67 | } |
68 | 68 | |
69 | 69 | echo '<p>'; |
70 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array(), 'target' => array() ) ) ); |
|
70 | + echo wp_kses($notice['message'], array('a' => array('href' => array(), 'target' => array()))); |
|
71 | 71 | echo '</p></div>'; |
72 | 72 | } |
73 | 73 | } |
@@ -100,116 +100,116 @@ discard block |
||
100 | 100 | * @version 4.0.0 |
101 | 101 | */ |
102 | 102 | public function stripe_check_environment() { |
103 | - $show_style_notice = get_option( 'wc_stripe_show_style_notice' ); |
|
104 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
105 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
106 | - $show_3ds_notice = get_option( 'wc_stripe_show_3ds_notice' ); |
|
107 | - $show_phpver_notice = get_option( 'wc_stripe_show_phpver_notice' ); |
|
108 | - $show_wcver_notice = get_option( 'wc_stripe_show_wcver_notice' ); |
|
109 | - $show_curl_notice = get_option( 'wc_stripe_show_curl_notice' ); |
|
110 | - $show_sca_notice = get_option( 'wc_stripe_show_sca_notice' ); |
|
111 | - $changed_keys_notice = get_option( 'wc_stripe_show_changed_keys_notice' ); |
|
112 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
113 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
114 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
115 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
116 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
117 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
118 | - $three_d_secure = isset( $options['three_d_secure'] ) && 'yes' === $options['three_d_secure']; |
|
119 | - |
|
120 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
121 | - if ( empty( $show_3ds_notice ) && $three_d_secure ) { |
|
103 | + $show_style_notice = get_option('wc_stripe_show_style_notice'); |
|
104 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
105 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
106 | + $show_3ds_notice = get_option('wc_stripe_show_3ds_notice'); |
|
107 | + $show_phpver_notice = get_option('wc_stripe_show_phpver_notice'); |
|
108 | + $show_wcver_notice = get_option('wc_stripe_show_wcver_notice'); |
|
109 | + $show_curl_notice = get_option('wc_stripe_show_curl_notice'); |
|
110 | + $show_sca_notice = get_option('wc_stripe_show_sca_notice'); |
|
111 | + $changed_keys_notice = get_option('wc_stripe_show_changed_keys_notice'); |
|
112 | + $options = get_option('woocommerce_stripe_settings'); |
|
113 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
114 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
115 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
116 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
117 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
118 | + $three_d_secure = isset($options['three_d_secure']) && 'yes' === $options['three_d_secure']; |
|
119 | + |
|
120 | + if (isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
121 | + if (empty($show_3ds_notice) && $three_d_secure) { |
|
122 | 122 | $url = 'https://stripe.com/docs/payments/3d-secure#three-ds-radar'; |
123 | 123 | |
124 | 124 | /* translators: 1) A URL that explains Stripe Radar. */ |
125 | - $message = __( 'WooCommerce Stripe - We see that you had the "Require 3D secure when applicable" setting turned on. This setting is not available here anymore, because it is now replaced by Stripe Radar. You can learn more about it <a href="%s" target="_blank">here</a>.', 'woocommerce-gateway-stripe' ); |
|
125 | + $message = __('WooCommerce Stripe - We see that you had the "Require 3D secure when applicable" setting turned on. This setting is not available here anymore, because it is now replaced by Stripe Radar. You can learn more about it <a href="%s" target="_blank">here</a>.', 'woocommerce-gateway-stripe'); |
|
126 | 126 | |
127 | - $this->add_admin_notice( '3ds', 'notice notice-warning', sprintf( $message, $url ), true ); |
|
127 | + $this->add_admin_notice('3ds', 'notice notice-warning', sprintf($message, $url), true); |
|
128 | 128 | } |
129 | 129 | |
130 | - if ( empty( $show_style_notice ) ) { |
|
130 | + if (empty($show_style_notice)) { |
|
131 | 131 | /* translators: 1) int version 2) int version */ |
132 | - $message = __( 'WooCommerce Stripe - We recently made changes to Stripe that may impact the appearance of your checkout. If your checkout has changed unexpectedly, please follow these <a href="https://docs.woocommerce.com/document/stripe/#styling" target="_blank">instructions</a> to fix.', 'woocommerce-gateway-stripe' ); |
|
132 | + $message = __('WooCommerce Stripe - We recently made changes to Stripe that may impact the appearance of your checkout. If your checkout has changed unexpectedly, please follow these <a href="https://docs.woocommerce.com/document/stripe/#styling" target="_blank">instructions</a> to fix.', 'woocommerce-gateway-stripe'); |
|
133 | 133 | |
134 | - $this->add_admin_notice( 'style', 'notice notice-warning', $message, true ); |
|
134 | + $this->add_admin_notice('style', 'notice notice-warning', $message, true); |
|
135 | 135 | |
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | - if ( empty( $show_phpver_notice ) ) { |
|
140 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
139 | + if (empty($show_phpver_notice)) { |
|
140 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
141 | 141 | /* translators: 1) int version 2) int version */ |
142 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
142 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
143 | 143 | |
144 | - $this->add_admin_notice( 'phpver', 'error', sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ), true ); |
|
144 | + $this->add_admin_notice('phpver', 'error', sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()), true); |
|
145 | 145 | |
146 | 146 | return; |
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | - if ( empty( $show_wcver_notice ) ) { |
|
151 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
150 | + if (empty($show_wcver_notice)) { |
|
151 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
152 | 152 | /* translators: 1) int version 2) int version */ |
153 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
153 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
154 | 154 | |
155 | - $this->add_admin_notice( 'wcver', 'notice notice-warning', sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ), true ); |
|
155 | + $this->add_admin_notice('wcver', 'notice notice-warning', sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION), true); |
|
156 | 156 | |
157 | 157 | return; |
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | - if ( empty( $show_curl_notice ) ) { |
|
162 | - if ( ! function_exists( 'curl_init' ) ) { |
|
163 | - $this->add_admin_notice( 'curl', 'notice notice-warning', __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ), true ); |
|
161 | + if (empty($show_curl_notice)) { |
|
162 | + if ( ! function_exists('curl_init')) { |
|
163 | + $this->add_admin_notice('curl', 'notice notice-warning', __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'), true); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | - if ( empty( $show_keys_notice ) ) { |
|
167 | + if (empty($show_keys_notice)) { |
|
168 | 168 | $secret = WC_Stripe_API::get_secret_key(); |
169 | 169 | |
170 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
170 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
171 | 171 | $setting_link = $this->get_setting_link(); |
172 | 172 | /* translators: 1) link */ |
173 | - $this->add_admin_notice( 'keys', '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 ), true ); |
|
173 | + $this->add_admin_notice('keys', '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), true); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | // Check if keys are entered properly per live/test mode. |
177 | - if ( $testmode ) { |
|
177 | + if ($testmode) { |
|
178 | 178 | if ( |
179 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
180 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
181 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) { |
|
179 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
180 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
181 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) { |
|
182 | 182 | $setting_link = $this->get_setting_link(); |
183 | 183 | /* translators: 1) link */ |
184 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
184 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
185 | 185 | } |
186 | 186 | } else { |
187 | 187 | if ( |
188 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
189 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
190 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) { |
|
188 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
189 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
190 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) { |
|
191 | 191 | $setting_link = $this->get_setting_link(); |
192 | 192 | /* translators: 1) link */ |
193 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
193 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
198 | - if ( empty( $show_ssl_notice ) ) { |
|
198 | + if (empty($show_ssl_notice)) { |
|
199 | 199 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
200 | - if ( ! wc_checkout_is_https() ) { |
|
200 | + if ( ! wc_checkout_is_https()) { |
|
201 | 201 | /* translators: 1) link */ |
202 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but a SSL certificate is not detected. Your checkout may not be secure! Please ensure your server has a valid <a href="%1$s" target="_blank">SSL certificate</a>', 'woocommerce-gateway-stripe' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
202 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but a SSL certificate is not detected. Your checkout may not be secure! Please ensure your server has a valid <a href="%1$s" target="_blank">SSL certificate</a>', 'woocommerce-gateway-stripe'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - if ( empty( $show_sca_notice ) ) { |
|
207 | - $this->add_admin_notice( 'sca', 'notice notice-success', sprintf( __( 'Stripe is now ready for Strong Customer Authentication (SCA) and 3D Secure 2! <a href="%1$s" target="_blank">Read about SCA</a>', 'woocommerce-gateway-stripe' ), 'https://woocommerce.com/posts/introducing-strong-customer-authentication-sca/' ), true ); |
|
206 | + if (empty($show_sca_notice)) { |
|
207 | + $this->add_admin_notice('sca', 'notice notice-success', sprintf(__('Stripe is now ready for Strong Customer Authentication (SCA) and 3D Secure 2! <a href="%1$s" target="_blank">Read about SCA</a>', 'woocommerce-gateway-stripe'), 'https://woocommerce.com/posts/introducing-strong-customer-authentication-sca/'), true); |
|
208 | 208 | } |
209 | 209 | |
210 | - if ( 'yes' === $changed_keys_notice ) { |
|
210 | + if ('yes' === $changed_keys_notice) { |
|
211 | 211 | // translators: %s is a the URL for the link. |
212 | - $this->add_admin_notice( 'changed_keys', 'notice notice-warning', sprintf( __( 'The public and/or secret keys for the Stripe gateway have been changed. This might cause errors for existing customers and saved payment methods. <a href="%s" target="_blank">Click here to learn more</a>.', 'woocommerce-gateway-stripe' ), 'https://docs.woocommerce.com/document/stripe-fixing-customer-errors/' ), true ); |
|
212 | + $this->add_admin_notice('changed_keys', 'notice notice-warning', sprintf(__('The public and/or secret keys for the Stripe gateway have been changed. This might cause errors for existing customers and saved payment methods. <a href="%s" target="_blank">Click here to learn more</a>.', 'woocommerce-gateway-stripe'), 'https://docs.woocommerce.com/document/stripe-fixing-customer-errors/'), true); |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | } |
@@ -222,17 +222,17 @@ discard block |
||
222 | 222 | public function payment_methods_check_environment() { |
223 | 223 | $payment_methods = $this->get_payment_methods(); |
224 | 224 | |
225 | - foreach ( $payment_methods as $method => $class ) { |
|
226 | - $show_notice = get_option( 'wc_stripe_show_' . strtolower( $method ) . '_notice' ); |
|
225 | + foreach ($payment_methods as $method => $class) { |
|
226 | + $show_notice = get_option('wc_stripe_show_' . strtolower($method) . '_notice'); |
|
227 | 227 | $gateway = new $class(); |
228 | 228 | |
229 | - if ( 'yes' !== $gateway->enabled || 'no' === $show_notice ) { |
|
229 | + if ('yes' !== $gateway->enabled || 'no' === $show_notice) { |
|
230 | 230 | continue; |
231 | 231 | } |
232 | 232 | |
233 | - if ( ! in_array( get_woocommerce_currency(), $gateway->get_supported_currency() ) ) { |
|
233 | + if ( ! in_array(get_woocommerce_currency(), $gateway->get_supported_currency())) { |
|
234 | 234 | /* translators: %1$s Payment method, %2$s List of supported currencies */ |
235 | - $this->add_admin_notice( $method, 'notice notice-error', sprintf( __( '%1$s is enabled - it requires store currency to be set to %2$s', 'woocommerce-gateway-stripe' ), $method, implode( ', ', $gateway->get_supported_currency() ) ), true ); |
|
235 | + $this->add_admin_notice($method, 'notice notice-error', sprintf(__('%1$s is enabled - it requires store currency to be set to %2$s', 'woocommerce-gateway-stripe'), $method, implode(', ', $gateway->get_supported_currency())), true); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | } |
@@ -244,71 +244,71 @@ discard block |
||
244 | 244 | * @version 4.0.0 |
245 | 245 | */ |
246 | 246 | public function hide_notices() { |
247 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
248 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
249 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
247 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
248 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
249 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
250 | 250 | } |
251 | 251 | |
252 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
253 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
252 | + if ( ! current_user_can('manage_woocommerce')) { |
|
253 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
254 | 254 | } |
255 | 255 | |
256 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
256 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
257 | 257 | |
258 | - switch ( $notice ) { |
|
258 | + switch ($notice) { |
|
259 | 259 | case 'style': |
260 | - update_option( 'wc_stripe_show_style_notice', 'no' ); |
|
260 | + update_option('wc_stripe_show_style_notice', 'no'); |
|
261 | 261 | break; |
262 | 262 | case 'phpver': |
263 | - update_option( 'wc_stripe_show_phpver_notice', 'no' ); |
|
263 | + update_option('wc_stripe_show_phpver_notice', 'no'); |
|
264 | 264 | break; |
265 | 265 | case 'wcver': |
266 | - update_option( 'wc_stripe_show_wcver_notice', 'no' ); |
|
266 | + update_option('wc_stripe_show_wcver_notice', 'no'); |
|
267 | 267 | break; |
268 | 268 | case 'curl': |
269 | - update_option( 'wc_stripe_show_curl_notice', 'no' ); |
|
269 | + update_option('wc_stripe_show_curl_notice', 'no'); |
|
270 | 270 | break; |
271 | 271 | case 'ssl': |
272 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
272 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
273 | 273 | break; |
274 | 274 | case 'keys': |
275 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
275 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
276 | 276 | break; |
277 | 277 | case '3ds': |
278 | - update_option( 'wc_stripe_show_3ds_notice', 'no' ); |
|
278 | + update_option('wc_stripe_show_3ds_notice', 'no'); |
|
279 | 279 | break; |
280 | 280 | case 'Alipay': |
281 | - update_option( 'wc_stripe_show_alipay_notice', 'no' ); |
|
281 | + update_option('wc_stripe_show_alipay_notice', 'no'); |
|
282 | 282 | break; |
283 | 283 | case 'Bancontact': |
284 | - update_option( 'wc_stripe_show_bancontact_notice', 'no' ); |
|
284 | + update_option('wc_stripe_show_bancontact_notice', 'no'); |
|
285 | 285 | break; |
286 | 286 | case 'EPS': |
287 | - update_option( 'wc_stripe_show_eps_notice', 'no' ); |
|
287 | + update_option('wc_stripe_show_eps_notice', 'no'); |
|
288 | 288 | break; |
289 | 289 | case 'Giropay': |
290 | - update_option( 'wc_stripe_show_giropay_notice', 'no' ); |
|
290 | + update_option('wc_stripe_show_giropay_notice', 'no'); |
|
291 | 291 | break; |
292 | 292 | case 'iDeal': |
293 | - update_option( 'wc_stripe_show_ideal_notice', 'no' ); |
|
293 | + update_option('wc_stripe_show_ideal_notice', 'no'); |
|
294 | 294 | break; |
295 | 295 | case 'Multibanco': |
296 | - update_option( 'wc_stripe_show_multibanco_notice', 'no' ); |
|
296 | + update_option('wc_stripe_show_multibanco_notice', 'no'); |
|
297 | 297 | break; |
298 | 298 | case 'P24': |
299 | - update_option( 'wc_stripe_show_p24_notice', 'no' ); |
|
299 | + update_option('wc_stripe_show_p24_notice', 'no'); |
|
300 | 300 | break; |
301 | 301 | case 'SEPA': |
302 | - update_option( 'wc_stripe_show_sepa_notice', 'no' ); |
|
302 | + update_option('wc_stripe_show_sepa_notice', 'no'); |
|
303 | 303 | break; |
304 | 304 | case 'SOFORT': |
305 | - update_option( 'wc_stripe_show_sofort_notice', 'no' ); |
|
305 | + update_option('wc_stripe_show_sofort_notice', 'no'); |
|
306 | 306 | break; |
307 | 307 | case 'sca': |
308 | - update_option( 'wc_stripe_show_sca_notice', 'no' ); |
|
308 | + update_option('wc_stripe_show_sca_notice', 'no'); |
|
309 | 309 | break; |
310 | 310 | case 'changed_keys': |
311 | - update_option( 'wc_stripe_show_changed_keys_notice', 'no' ); |
|
311 | + update_option('wc_stripe_show_changed_keys_notice', 'no'); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
@@ -321,11 +321,11 @@ discard block |
||
321 | 321 | * @return string Setting link |
322 | 322 | */ |
323 | 323 | public function get_setting_link() { |
324 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
324 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
325 | 325 | |
326 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
326 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
327 | 327 | |
328 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
328 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -334,16 +334,16 @@ discard block |
||
334 | 334 | * @since 4.3.0 |
335 | 335 | */ |
336 | 336 | public function stripe_updated() { |
337 | - $previous_version = get_option( 'wc_stripe_version' ); |
|
337 | + $previous_version = get_option('wc_stripe_version'); |
|
338 | 338 | |
339 | 339 | // Only show the style notice if the plugin was installed and older than 4.1.4. |
340 | - if ( empty( $previous_version ) || version_compare( $previous_version, '4.1.4', 'ge' ) ) { |
|
341 | - update_option( 'wc_stripe_show_style_notice', 'no' ); |
|
340 | + if (empty($previous_version) || version_compare($previous_version, '4.1.4', 'ge')) { |
|
341 | + update_option('wc_stripe_show_style_notice', 'no'); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | // Only show the SCA notice on pre-4.3.0 installs. |
345 | - if ( empty( $previous_version ) || version_compare( $previous_version, '4.3.0', 'ge' ) ) { |
|
346 | - update_option( 'wc_stripe_show_sca_notice', 'no' ); |
|
345 | + if (empty($previous_version) || version_compare($previous_version, '4.3.0', 'ge')) { |
|
346 | + update_option('wc_stripe_show_sca_notice', 'no'); |
|
347 | 347 | } |
348 | 348 | } |
349 | 349 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! class_exists( 'WC_Abstract_Privacy' ) ) { |
|
2 | +if ( ! class_exists('WC_Abstract_Privacy')) { |
|
3 | 3 | return; |
4 | 4 | } |
5 | 5 | |
@@ -9,20 +9,20 @@ discard block |
||
9 | 9 | * |
10 | 10 | */ |
11 | 11 | public function __construct() { |
12 | - parent::__construct( __( 'Stripe', 'woocommerce-gateway-stripe' ) ); |
|
12 | + parent::__construct(__('Stripe', 'woocommerce-gateway-stripe')); |
|
13 | 13 | |
14 | - $this->add_exporter( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe' ), array( $this, 'order_data_exporter' ) ); |
|
14 | + $this->add_exporter('woocommerce-gateway-stripe-order-data', __('WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe'), array($this, 'order_data_exporter')); |
|
15 | 15 | |
16 | - if ( function_exists( 'wcs_get_subscriptions' ) ) { |
|
17 | - $this->add_exporter( 'woocommerce-gateway-stripe-subscriptions-data', __( 'WooCommerce Stripe Subscriptions Data', 'woocommerce-gateway-stripe' ), array( $this, 'subscriptions_data_exporter' ) ); |
|
16 | + if (function_exists('wcs_get_subscriptions')) { |
|
17 | + $this->add_exporter('woocommerce-gateway-stripe-subscriptions-data', __('WooCommerce Stripe Subscriptions Data', 'woocommerce-gateway-stripe'), array($this, 'subscriptions_data_exporter')); |
|
18 | 18 | } |
19 | 19 | |
20 | - $this->add_exporter( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), array( $this, 'customer_data_exporter' ) ); |
|
20 | + $this->add_exporter('woocommerce-gateway-stripe-customer-data', __('WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe'), array($this, 'customer_data_exporter')); |
|
21 | 21 | |
22 | - $this->add_eraser( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), array( $this, 'customer_data_eraser' ) ); |
|
23 | - $this->add_eraser( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Data', 'woocommerce-gateway-stripe' ), array( $this, 'order_data_eraser' ) ); |
|
22 | + $this->add_eraser('woocommerce-gateway-stripe-customer-data', __('WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe'), array($this, 'customer_data_eraser')); |
|
23 | + $this->add_eraser('woocommerce-gateway-stripe-order-data', __('WooCommerce Stripe Data', 'woocommerce-gateway-stripe'), array($this, 'order_data_eraser')); |
|
24 | 24 | |
25 | - add_filter( 'woocommerce_get_settings_account', array( $this, 'account_settings' ) ); |
|
25 | + add_filter('woocommerce_get_settings_account', array($this, 'account_settings')); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | * @param array $settings |
32 | 32 | * @return array $settings Updated |
33 | 33 | */ |
34 | - public function account_settings( $settings ) { |
|
34 | + public function account_settings($settings) { |
|
35 | 35 | $insert_setting = array( |
36 | 36 | array( |
37 | - 'title' => __( 'Retain Stripe Data', 'woocommerce-gateway-stripe' ), |
|
38 | - 'desc_tip' => __( 'Retains any Stripe data such as Stripe customer ID, source ID.', 'woocommerce-gateway-stripe' ), |
|
37 | + 'title' => __('Retain Stripe Data', 'woocommerce-gateway-stripe'), |
|
38 | + 'desc_tip' => __('Retains any Stripe data such as Stripe customer ID, source ID.', 'woocommerce-gateway-stripe'), |
|
39 | 39 | 'id' => 'woocommerce_gateway_stripe_retention', |
40 | 40 | 'type' => 'relative_date_selector', |
41 | - 'placeholder' => __( 'N/A', 'woocommerce-gateway-stripe' ), |
|
41 | + 'placeholder' => __('N/A', 'woocommerce-gateway-stripe'), |
|
42 | 42 | 'default' => '', |
43 | 43 | 'autoload' => false, |
44 | 44 | ), |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | |
47 | 47 | $index = null; |
48 | 48 | |
49 | - foreach ( $settings as $key => $value) { |
|
50 | - if ( 'sectionend' === $value[ 'type' ] && 'personal_data_retention' === $value[ 'id' ] ) { |
|
49 | + foreach ($settings as $key => $value) { |
|
50 | + if ('sectionend' === $value['type'] && 'personal_data_retention' === $value['id']) { |
|
51 | 51 | $index = $key; |
52 | 52 | break; |
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | - if ( ! is_null( $index ) ) { |
|
57 | - array_splice( $settings, $index, 0, $insert_setting ); |
|
56 | + if ( ! is_null($index)) { |
|
57 | + array_splice($settings, $index, 0, $insert_setting); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return $settings; |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return array WP_Post |
70 | 70 | */ |
71 | - protected function get_stripe_orders( $email_address, $page ) { |
|
72 | - $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
|
71 | + protected function get_stripe_orders($email_address, $page) { |
|
72 | + $user = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data. |
|
73 | 73 | |
74 | 74 | $order_query = array( |
75 | - 'payment_method' => array( 'stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort' ), |
|
75 | + 'payment_method' => array('stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort'), |
|
76 | 76 | 'limit' => 10, |
77 | 77 | 'page' => $page, |
78 | 78 | ); |
79 | 79 | |
80 | - if ( $user instanceof WP_User ) { |
|
80 | + if ($user instanceof WP_User) { |
|
81 | 81 | $order_query['customer_id'] = (int) $user->ID; |
82 | 82 | } else { |
83 | 83 | $order_query['billing_email'] = $email_address; |
84 | 84 | } |
85 | 85 | |
86 | - return wc_get_orders( $order_query ); |
|
86 | + return wc_get_orders($order_query); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function get_privacy_message() { |
94 | 94 | /* translators: %s URL to docs */ |
95 | - return wpautop( sprintf( __( 'By using this extension, you may be storing personal data or sharing data with an external service. <a href="%s" target="_blank">Learn more about how this works, including what you may want to include in your privacy policy.</a>', 'woocommerce-gateway-stripe' ), 'https://docs.woocommerce.com/document/privacy-payments/#woocommerce-gateway-stripe' ) ); |
|
95 | + return wpautop(sprintf(__('By using this extension, you may be storing personal data or sharing data with an external service. <a href="%s" target="_blank">Learn more about how this works, including what you may want to include in your privacy policy.</a>', 'woocommerce-gateway-stripe'), 'https://docs.woocommerce.com/document/privacy-payments/#woocommerce-gateway-stripe')); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -103,34 +103,34 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return array |
105 | 105 | */ |
106 | - public function order_data_exporter( $email_address, $page = 1 ) { |
|
106 | + public function order_data_exporter($email_address, $page = 1) { |
|
107 | 107 | $done = false; |
108 | 108 | $data_to_export = array(); |
109 | 109 | |
110 | - $orders = $this->get_stripe_orders( $email_address, (int) $page ); |
|
110 | + $orders = $this->get_stripe_orders($email_address, (int) $page); |
|
111 | 111 | |
112 | 112 | $done = true; |
113 | 113 | |
114 | - if ( 0 < count( $orders ) ) { |
|
115 | - foreach ( $orders as $order ) { |
|
114 | + if (0 < count($orders)) { |
|
115 | + foreach ($orders as $order) { |
|
116 | 116 | $data_to_export[] = array( |
117 | 117 | 'group_id' => 'woocommerce_orders', |
118 | - 'group_label' => __( 'Orders', 'woocommerce-gateway-stripe' ), |
|
118 | + 'group_label' => __('Orders', 'woocommerce-gateway-stripe'), |
|
119 | 119 | 'item_id' => 'order-' . $order->get_id(), |
120 | 120 | 'data' => array( |
121 | 121 | array( |
122 | - 'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ), |
|
123 | - 'value' => get_post_meta( $order->get_id(), '_stripe_source_id', true ), |
|
122 | + 'name' => __('Stripe payment id', 'woocommerce-gateway-stripe'), |
|
123 | + 'value' => get_post_meta($order->get_id(), '_stripe_source_id', true), |
|
124 | 124 | ), |
125 | 125 | array( |
126 | - 'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ), |
|
127 | - 'value' => get_post_meta( $order->get_id(), '_stripe_customer_id', true ), |
|
126 | + 'name' => __('Stripe customer id', 'woocommerce-gateway-stripe'), |
|
127 | + 'value' => get_post_meta($order->get_id(), '_stripe_customer_id', true), |
|
128 | 128 | ), |
129 | 129 | ), |
130 | 130 | ); |
131 | 131 | } |
132 | 132 | |
133 | - $done = 10 > count( $orders ); |
|
133 | + $done = 10 > count($orders); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | return array( |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @return array |
149 | 149 | */ |
150 | - public function subscriptions_data_exporter( $email_address, $page = 1 ) { |
|
150 | + public function subscriptions_data_exporter($email_address, $page = 1) { |
|
151 | 151 | $done = false; |
152 | 152 | $page = (int) $page; |
153 | 153 | $data_to_export = array(); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | 'relation' => 'AND', |
157 | 157 | array( |
158 | 158 | 'key' => '_payment_method', |
159 | - 'value' => array( 'stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort' ), |
|
159 | + 'value' => array('stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort'), |
|
160 | 160 | 'compare' => 'IN', |
161 | 161 | ), |
162 | 162 | array( |
@@ -172,30 +172,30 @@ discard block |
||
172 | 172 | 'meta_query' => $meta_query, |
173 | 173 | ); |
174 | 174 | |
175 | - $subscriptions = wcs_get_subscriptions( $subscription_query ); |
|
175 | + $subscriptions = wcs_get_subscriptions($subscription_query); |
|
176 | 176 | |
177 | 177 | $done = true; |
178 | 178 | |
179 | - if ( 0 < count( $subscriptions ) ) { |
|
180 | - foreach ( $subscriptions as $subscription ) { |
|
179 | + if (0 < count($subscriptions)) { |
|
180 | + foreach ($subscriptions as $subscription) { |
|
181 | 181 | $data_to_export[] = array( |
182 | 182 | 'group_id' => 'woocommerce_subscriptions', |
183 | - 'group_label' => __( 'Subscriptions', 'woocommerce-gateway-stripe' ), |
|
183 | + 'group_label' => __('Subscriptions', 'woocommerce-gateway-stripe'), |
|
184 | 184 | 'item_id' => 'subscription-' . $subscription->get_id(), |
185 | 185 | 'data' => array( |
186 | 186 | array( |
187 | - 'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ), |
|
188 | - 'value' => get_post_meta( $subscription->get_id(), '_stripe_source_id', true ), |
|
187 | + 'name' => __('Stripe payment id', 'woocommerce-gateway-stripe'), |
|
188 | + 'value' => get_post_meta($subscription->get_id(), '_stripe_source_id', true), |
|
189 | 189 | ), |
190 | 190 | array( |
191 | - 'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ), |
|
192 | - 'value' => get_post_meta( $subscription->get_id(), '_stripe_customer_id', true ), |
|
191 | + 'name' => __('Stripe customer id', 'woocommerce-gateway-stripe'), |
|
192 | + 'value' => get_post_meta($subscription->get_id(), '_stripe_customer_id', true), |
|
193 | 193 | ), |
194 | 194 | ), |
195 | 195 | ); |
196 | 196 | } |
197 | 197 | |
198 | - $done = 10 > count( $subscriptions ); |
|
198 | + $done = 10 > count($subscriptions); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | return array( |
@@ -211,24 +211,24 @@ discard block |
||
211 | 211 | * @param int $page Page. |
212 | 212 | * @return array An array of personal data in name value pairs |
213 | 213 | */ |
214 | - public function customer_data_exporter( $email_address, $page ) { |
|
215 | - $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
|
214 | + public function customer_data_exporter($email_address, $page) { |
|
215 | + $user = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data. |
|
216 | 216 | $data_to_export = array(); |
217 | 217 | |
218 | - if ( $user instanceof WP_User ) { |
|
219 | - $stripe_user = new WC_Stripe_Customer( $user->ID ); |
|
218 | + if ($user instanceof WP_User) { |
|
219 | + $stripe_user = new WC_Stripe_Customer($user->ID); |
|
220 | 220 | |
221 | 221 | $data_to_export[] = array( |
222 | 222 | 'group_id' => 'woocommerce_customer', |
223 | - 'group_label' => __( 'Customer Data', 'woocommerce-gateway-stripe' ), |
|
223 | + 'group_label' => __('Customer Data', 'woocommerce-gateway-stripe'), |
|
224 | 224 | 'item_id' => 'user', |
225 | 225 | 'data' => array( |
226 | 226 | array( |
227 | - 'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ), |
|
228 | - 'value' => get_user_option( '_stripe_source_id', $user->ID ), |
|
227 | + 'name' => __('Stripe payment id', 'woocommerce-gateway-stripe'), |
|
228 | + 'value' => get_user_option('_stripe_source_id', $user->ID), |
|
229 | 229 | ), |
230 | 230 | array( |
231 | - 'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ), |
|
231 | + 'name' => __('Stripe customer id', 'woocommerce-gateway-stripe'), |
|
232 | 232 | 'value' => $stripe_user->get_id(), |
233 | 233 | ), |
234 | 234 | ), |
@@ -248,25 +248,25 @@ discard block |
||
248 | 248 | * @param int $page Page. |
249 | 249 | * @return array An array of personal data in name value pairs |
250 | 250 | */ |
251 | - public function customer_data_eraser( $email_address, $page ) { |
|
251 | + public function customer_data_eraser($email_address, $page) { |
|
252 | 252 | $page = (int) $page; |
253 | - $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
|
253 | + $user = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data. |
|
254 | 254 | $stripe_customer_id = ''; |
255 | 255 | $stripe_source_id = ''; |
256 | 256 | |
257 | - if ( $user instanceof WP_User ) { |
|
258 | - $stripe_customer_id = get_user_option( '_stripe_customer_id', $user->ID ); |
|
259 | - $stripe_source_id = get_user_option( '_stripe_source_id', $user->ID ); |
|
257 | + if ($user instanceof WP_User) { |
|
258 | + $stripe_customer_id = get_user_option('_stripe_customer_id', $user->ID); |
|
259 | + $stripe_source_id = get_user_option('_stripe_source_id', $user->ID); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | $items_removed = false; |
263 | 263 | $messages = array(); |
264 | 264 | |
265 | - if ( ! empty( $stripe_customer_id ) || ! empty( $stripe_source_id ) ) { |
|
265 | + if ( ! empty($stripe_customer_id) || ! empty($stripe_source_id)) { |
|
266 | 266 | $items_removed = true; |
267 | - delete_user_option( $user->ID, '_stripe_customer_id' ); |
|
268 | - delete_user_option( $user->ID, '_stripe_source_id' ); |
|
269 | - $messages[] = __( 'Stripe User Data Erased.', 'woocommerce-gateway-stripe' ); |
|
267 | + delete_user_option($user->ID, '_stripe_customer_id'); |
|
268 | + delete_user_option($user->ID, '_stripe_source_id'); |
|
269 | + $messages[] = __('Stripe User Data Erased.', 'woocommerce-gateway-stripe'); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | return array( |
@@ -284,29 +284,29 @@ discard block |
||
284 | 284 | * @param int $page Page. |
285 | 285 | * @return array An array of personal data in name value pairs |
286 | 286 | */ |
287 | - public function order_data_eraser( $email_address, $page ) { |
|
288 | - $orders = $this->get_stripe_orders( $email_address, (int) $page ); |
|
287 | + public function order_data_eraser($email_address, $page) { |
|
288 | + $orders = $this->get_stripe_orders($email_address, (int) $page); |
|
289 | 289 | |
290 | 290 | $items_removed = false; |
291 | 291 | $items_retained = false; |
292 | 292 | $messages = array(); |
293 | 293 | |
294 | - foreach ( (array) $orders as $order ) { |
|
295 | - $order = wc_get_order( $order->get_id() ); |
|
294 | + foreach ((array) $orders as $order) { |
|
295 | + $order = wc_get_order($order->get_id()); |
|
296 | 296 | |
297 | - list( $removed, $retained, $msgs ) = $this->maybe_handle_order( $order ); |
|
297 | + list($removed, $retained, $msgs) = $this->maybe_handle_order($order); |
|
298 | 298 | $items_removed |= $removed; |
299 | 299 | $items_retained |= $retained; |
300 | - $messages = array_merge( $messages, $msgs ); |
|
300 | + $messages = array_merge($messages, $msgs); |
|
301 | 301 | |
302 | - list( $removed, $retained, $msgs ) = $this->maybe_handle_subscription( $order ); |
|
302 | + list($removed, $retained, $msgs) = $this->maybe_handle_subscription($order); |
|
303 | 303 | $items_removed |= $removed; |
304 | 304 | $items_retained |= $retained; |
305 | - $messages = array_merge( $messages, $msgs ); |
|
305 | + $messages = array_merge($messages, $msgs); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | // Tell core if we have more orders to work on still |
309 | - $done = count( $orders ) < 10; |
|
309 | + $done = count($orders) < 10; |
|
310 | 310 | |
311 | 311 | return array( |
312 | 312 | 'items_removed' => $items_removed, |
@@ -322,47 +322,47 @@ discard block |
||
322 | 322 | * @param WC_Order $order |
323 | 323 | * @return array |
324 | 324 | */ |
325 | - protected function maybe_handle_subscription( $order ) { |
|
326 | - if ( ! class_exists( 'WC_Subscriptions' ) ) { |
|
327 | - return array( false, false, array() ); |
|
325 | + protected function maybe_handle_subscription($order) { |
|
326 | + if ( ! class_exists('WC_Subscriptions')) { |
|
327 | + return array(false, false, array()); |
|
328 | 328 | } |
329 | 329 | |
330 | - if ( ! wcs_order_contains_subscription( $order ) ) { |
|
331 | - return array( false, false, array() ); |
|
330 | + if ( ! wcs_order_contains_subscription($order)) { |
|
331 | + return array(false, false, array()); |
|
332 | 332 | } |
333 | 333 | |
334 | - $subscription = current( wcs_get_subscriptions_for_order( $order->get_id() ) ); |
|
334 | + $subscription = current(wcs_get_subscriptions_for_order($order->get_id())); |
|
335 | 335 | $subscription_id = $subscription->get_id(); |
336 | 336 | |
337 | - $stripe_source_id = get_post_meta( $subscription_id, '_stripe_source_id', true ); |
|
337 | + $stripe_source_id = get_post_meta($subscription_id, '_stripe_source_id', true); |
|
338 | 338 | |
339 | - if ( empty( $stripe_source_id ) ) { |
|
340 | - return array( false, false, array() ); |
|
339 | + if (empty($stripe_source_id)) { |
|
340 | + return array(false, false, array()); |
|
341 | 341 | } |
342 | 342 | |
343 | - if ( ! $this->is_retention_expired( $order->get_date_created()->getTimestamp() ) ) { |
|
343 | + if ( ! $this->is_retention_expired($order->get_date_created()->getTimestamp())) { |
|
344 | 344 | /* translators: %d Order ID */ |
345 | - return array( false, true, array( sprintf( __( 'Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe' ), $order->get_id() ) ) ); |
|
345 | + return array(false, true, array(sprintf(__('Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe'), $order->get_id()))); |
|
346 | 346 | } |
347 | 347 | |
348 | - if ( $subscription->has_status( apply_filters( 'wc_stripe_privacy_eraser_subs_statuses', array( 'on-hold', 'active' ) ) ) ) { |
|
348 | + if ($subscription->has_status(apply_filters('wc_stripe_privacy_eraser_subs_statuses', array('on-hold', 'active')))) { |
|
349 | 349 | /* translators: %d Order ID */ |
350 | - return array( false, true, array( sprintf( __( 'Order ID %d contains an active Subscription. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe' ), $order->get_id() ) ) ); |
|
350 | + return array(false, true, array(sprintf(__('Order ID %d contains an active Subscription. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe'), $order->get_id()))); |
|
351 | 351 | } |
352 | 352 | |
353 | - $renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders( $order->get_id() ); |
|
353 | + $renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders($order->get_id()); |
|
354 | 354 | |
355 | - foreach ( $renewal_orders as $renewal_order_id ) { |
|
356 | - delete_post_meta( $renewal_order_id, '_stripe_source_id' ); |
|
357 | - delete_post_meta( $renewal_order_id, '_stripe_refund_id' ); |
|
358 | - delete_post_meta( $renewal_order_id, '_stripe_customer_id' ); |
|
355 | + foreach ($renewal_orders as $renewal_order_id) { |
|
356 | + delete_post_meta($renewal_order_id, '_stripe_source_id'); |
|
357 | + delete_post_meta($renewal_order_id, '_stripe_refund_id'); |
|
358 | + delete_post_meta($renewal_order_id, '_stripe_customer_id'); |
|
359 | 359 | } |
360 | 360 | |
361 | - delete_post_meta( $subscription_id, '_stripe_source_id' ); |
|
362 | - delete_post_meta( $subscription_id, '_stripe_refund_id' ); |
|
363 | - delete_post_meta( $subscription_id, '_stripe_customer_id' ); |
|
361 | + delete_post_meta($subscription_id, '_stripe_source_id'); |
|
362 | + delete_post_meta($subscription_id, '_stripe_refund_id'); |
|
363 | + delete_post_meta($subscription_id, '_stripe_customer_id'); |
|
364 | 364 | |
365 | - return array( true, false, array( __( 'Stripe Subscription Data Erased.', 'woocommerce-gateway-stripe' ) ) ); |
|
365 | + return array(true, false, array(__('Stripe Subscription Data Erased.', 'woocommerce-gateway-stripe'))); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -371,61 +371,61 @@ discard block |
||
371 | 371 | * @param WC_Order $order |
372 | 372 | * @return array |
373 | 373 | */ |
374 | - protected function maybe_handle_order( $order ) { |
|
374 | + protected function maybe_handle_order($order) { |
|
375 | 375 | $order_id = $order->get_id(); |
376 | - $stripe_source_id = get_post_meta( $order_id, '_stripe_source_id', true ); |
|
377 | - $stripe_refund_id = get_post_meta( $order_id, '_stripe_refund_id', true ); |
|
378 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
376 | + $stripe_source_id = get_post_meta($order_id, '_stripe_source_id', true); |
|
377 | + $stripe_refund_id = get_post_meta($order_id, '_stripe_refund_id', true); |
|
378 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
379 | 379 | |
380 | - if ( ! $this->is_retention_expired( $order->get_date_created()->getTimestamp() ) ) { |
|
380 | + if ( ! $this->is_retention_expired($order->get_date_created()->getTimestamp())) { |
|
381 | 381 | /* translators: %d Order ID */ |
382 | - return array( false, true, array( sprintf( __( 'Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe' ), $order->get_id() ) ) ); |
|
382 | + return array(false, true, array(sprintf(__('Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe'), $order->get_id()))); |
|
383 | 383 | } |
384 | 384 | |
385 | - if ( empty( $stripe_source_id ) && empty( $stripe_refund_id ) && empty( $stripe_customer_id ) ) { |
|
386 | - return array( false, false, array() ); |
|
385 | + if (empty($stripe_source_id) && empty($stripe_refund_id) && empty($stripe_customer_id)) { |
|
386 | + return array(false, false, array()); |
|
387 | 387 | } |
388 | 388 | |
389 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
390 | - delete_post_meta( $order_id, '_stripe_refund_id' ); |
|
391 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
389 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
390 | + delete_post_meta($order_id, '_stripe_refund_id'); |
|
391 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
392 | 392 | |
393 | - return array( true, false, array( __( 'Stripe personal data erased.', 'woocommerce-gateway-stripe' ) ) ); |
|
393 | + return array(true, false, array(__('Stripe personal data erased.', 'woocommerce-gateway-stripe'))); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
397 | 397 | * Checks if create date is passed retention duration. |
398 | 398 | * |
399 | 399 | */ |
400 | - public function is_retention_expired( $created_date ) { |
|
401 | - $retention = wc_parse_relative_date_option( get_option( 'woocommerce_gateway_stripe_retention' ) ); |
|
400 | + public function is_retention_expired($created_date) { |
|
401 | + $retention = wc_parse_relative_date_option(get_option('woocommerce_gateway_stripe_retention')); |
|
402 | 402 | $is_expired = false; |
403 | - $time_span = time() - strtotime( $created_date ); |
|
404 | - if ( empty( $retention ) || empty( $created_date ) ) { |
|
403 | + $time_span = time() - strtotime($created_date); |
|
404 | + if (empty($retention) || empty($created_date)) { |
|
405 | 405 | return false; |
406 | 406 | } |
407 | - switch ( $retention['unit'] ) { |
|
407 | + switch ($retention['unit']) { |
|
408 | 408 | case 'days': |
409 | 409 | $retention = $retention['number'] * DAY_IN_SECONDS; |
410 | - if ( $time_span > $retention ) { |
|
410 | + if ($time_span > $retention) { |
|
411 | 411 | $is_expired = true; |
412 | 412 | } |
413 | 413 | break; |
414 | 414 | case 'weeks': |
415 | 415 | $retention = $retention['number'] * WEEK_IN_SECONDS; |
416 | - if ( $time_span > $retention ) { |
|
416 | + if ($time_span > $retention) { |
|
417 | 417 | $is_expired = true; |
418 | 418 | } |
419 | 419 | break; |
420 | 420 | case 'months': |
421 | 421 | $retention = $retention['number'] * MONTH_IN_SECONDS; |
422 | - if ( $time_span > $retention ) { |
|
422 | + if ($time_span > $retention) { |
|
423 | 423 | $is_expired = true; |
424 | 424 | } |
425 | 425 | break; |
426 | 426 | case 'years': |
427 | 427 | $retention = $retention['number'] * YEAR_IN_SECONDS; |
428 | - if ( $time_span > $retention ) { |
|
428 | + if ($time_span > $retention) { |
|
429 | 429 | $is_expired = true; |
430 | 430 | } |
431 | 431 | break; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | public function __construct() { |
73 | 73 | $this->retry_interval = 1; |
74 | 74 | $this->id = 'stripe_sepa'; |
75 | - $this->method_title = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
75 | + $this->method_title = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
76 | 76 | /* translators: link */ |
77 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
77 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
78 | 78 | $this->has_fields = true; |
79 | 79 | $this->supports = array( |
80 | 80 | 'products', |
@@ -100,28 +100,28 @@ discard block |
||
100 | 100 | // Load the settings. |
101 | 101 | $this->init_settings(); |
102 | 102 | |
103 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
104 | - $this->title = $this->get_option( 'title' ); |
|
105 | - $this->description = $this->get_option( 'description' ); |
|
106 | - $this->enabled = $this->get_option( 'enabled' ); |
|
107 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
108 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
109 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
110 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
111 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
112 | - |
|
113 | - if ( $this->testmode ) { |
|
114 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
115 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
103 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
104 | + $this->title = $this->get_option('title'); |
|
105 | + $this->description = $this->get_option('description'); |
|
106 | + $this->enabled = $this->get_option('enabled'); |
|
107 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
108 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
109 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
110 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
111 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
112 | + |
|
113 | + if ($this->testmode) { |
|
114 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
115 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
116 | 116 | } |
117 | 117 | |
118 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
119 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
118 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
119 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
120 | 120 | |
121 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
121 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
122 | 122 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
123 | 123 | |
124 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
124 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | * @return bool |
150 | 150 | */ |
151 | 151 | public function is_available() { |
152 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
152 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
156 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
157 | 157 | return false; |
158 | 158 | } |
159 | 159 | |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | |
173 | 173 | $icons_str = ''; |
174 | 174 | |
175 | - $icons_str .= isset( $icons['sepa'] ) ? $icons['sepa'] : ''; |
|
175 | + $icons_str .= isset($icons['sepa']) ? $icons['sepa'] : ''; |
|
176 | 176 | |
177 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
177 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -185,19 +185,19 @@ discard block |
||
185 | 185 | * @access public |
186 | 186 | */ |
187 | 187 | public function payment_scripts() { |
188 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
188 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
189 | 189 | return; |
190 | 190 | } |
191 | 191 | |
192 | - wp_enqueue_style( 'stripe_styles' ); |
|
193 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
192 | + wp_enqueue_style('stripe_styles'); |
|
193 | + wp_enqueue_script('woocommerce_stripe'); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * Initialize Gateway Settings Form Fields. |
198 | 198 | */ |
199 | 199 | public function init_form_fields() { |
200 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' ); |
|
200 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php'); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function mandate_display() { |
211 | 211 | /* translators: statement descriptor */ |
212 | - printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) ); |
|
212 | + printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor)); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function form() { |
222 | 222 | ?> |
223 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
224 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
223 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
224 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
225 | 225 | <p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p> |
226 | 226 | <p class="form-row form-row-wide"> |
227 | 227 | <label for="stripe-iban-element"> |
228 | - <?php esc_html_e( 'IBAN.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span> |
|
228 | + <?php esc_html_e('IBAN.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span> |
|
229 | 229 | </label> |
230 | 230 | <div id="stripe-iban-element" class="wc-stripe-iban-element-field"> |
231 | 231 | <!-- A Stripe Element will be inserted here. --> |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | <!-- Used to display form errors --> |
236 | 236 | <div class="stripe-source-errors" role="alert"></div> |
237 | 237 | <br /> |
238 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
238 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
239 | 239 | <div class="clear"></div> |
240 | 240 | </fieldset> |
241 | 241 | <?php |
@@ -246,45 +246,45 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function payment_fields() { |
248 | 248 | $total = WC()->cart->total; |
249 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
249 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
250 | 250 | $description = $this->get_description(); |
251 | - $description = ! empty( $description ) ? $description : ''; |
|
251 | + $description = ! empty($description) ? $description : ''; |
|
252 | 252 | |
253 | 253 | // If paying from order, we need to get total from order not cart. |
254 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
255 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
254 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
255 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
256 | 256 | $total = $order->get_total(); |
257 | 257 | } |
258 | 258 | |
259 | - if ( is_add_payment_method_page() ) { |
|
259 | + if (is_add_payment_method_page()) { |
|
260 | 260 | $total = ''; |
261 | 261 | } |
262 | 262 | |
263 | 263 | echo '<div |
264 | 264 | id="stripe-sepa_debit-payment-data" |
265 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
266 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
265 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
266 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
267 | 267 | |
268 | - if ( $this->testmode ) { |
|
269 | - $description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' ); |
|
268 | + if ($this->testmode) { |
|
269 | + $description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe'); |
|
270 | 270 | } |
271 | 271 | |
272 | - $description = trim( $description ); |
|
272 | + $description = trim($description); |
|
273 | 273 | |
274 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
274 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
275 | 275 | |
276 | - if ( $display_tokenization ) { |
|
276 | + if ($display_tokenization) { |
|
277 | 277 | $this->tokenization_script(); |
278 | 278 | $this->saved_payment_methods(); |
279 | 279 | } |
280 | 280 | |
281 | 281 | $this->form(); |
282 | 282 | |
283 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
283 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
284 | 284 | $this->save_payment_method_checkbox(); |
285 | 285 | } |
286 | 286 | |
287 | - do_action( 'wc_stripe_sepa_payment_fields', $this->id ); |
|
287 | + do_action('wc_stripe_sepa_payment_fields', $this->id); |
|
288 | 288 | |
289 | 289 | echo '</div>'; |
290 | 290 | } |
@@ -300,99 +300,99 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return array|void |
302 | 302 | */ |
303 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
303 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
304 | 304 | try { |
305 | - $order = wc_get_order( $order_id ); |
|
305 | + $order = wc_get_order($order_id); |
|
306 | 306 | |
307 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
308 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
307 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
308 | + return $this->pre_orders->process_pre_order($order_id); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | // This comes from the create account checkbox in the checkout page. |
312 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
312 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
313 | 313 | |
314 | - if ( $create_account ) { |
|
315 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
316 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
314 | + if ($create_account) { |
|
315 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
316 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
317 | 317 | $new_stripe_customer->create_customer(); |
318 | 318 | } |
319 | 319 | |
320 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
320 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
321 | 321 | |
322 | - $this->save_source_to_order( $order, $prepared_source ); |
|
322 | + $this->save_source_to_order($order, $prepared_source); |
|
323 | 323 | |
324 | 324 | // Result from Stripe API request. |
325 | 325 | $response = null; |
326 | 326 | |
327 | - if ( $order->get_total() > 0 ) { |
|
327 | + if ($order->get_total() > 0) { |
|
328 | 328 | // This will throw exception if not valid. |
329 | - $this->validate_minimum_order_amount( $order ); |
|
329 | + $this->validate_minimum_order_amount($order); |
|
330 | 330 | |
331 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
331 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
332 | 332 | |
333 | 333 | // Make the request. |
334 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
334 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
335 | 335 | |
336 | - if ( ! empty( $response->error ) ) { |
|
336 | + if ( ! empty($response->error)) { |
|
337 | 337 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
338 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
339 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
340 | - delete_user_option( $order->customer_user, '_stripe_customer_id' ); |
|
341 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
338 | + if ($this->is_no_such_customer_error($response->error)) { |
|
339 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
340 | + delete_user_option($order->customer_user, '_stripe_customer_id'); |
|
341 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
342 | 342 | } else { |
343 | - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); |
|
344 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
343 | + delete_user_option($order->get_customer_id(), '_stripe_customer_id'); |
|
344 | + $order->delete_meta_data('_stripe_customer_id'); |
|
345 | 345 | $order->save(); |
346 | 346 | } |
347 | 347 | } |
348 | 348 | |
349 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
349 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
350 | 350 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
351 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
351 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
352 | 352 | $wc_token->delete(); |
353 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
354 | - $order->add_order_note( $localized_message ); |
|
355 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
353 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
354 | + $order->add_order_note($localized_message); |
|
355 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | // We want to retry. |
359 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
360 | - if ( $retry ) { |
|
359 | + if ($this->is_retryable_error($response->error)) { |
|
360 | + if ($retry) { |
|
361 | 361 | // Don't do anymore retries after this. |
362 | - if ( 5 <= $this->retry_interval ) { |
|
362 | + if (5 <= $this->retry_interval) { |
|
363 | 363 | |
364 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
364 | + return $this->process_payment($order_id, false, $force_save_source); |
|
365 | 365 | } |
366 | 366 | |
367 | - sleep( $this->retry_interval ); |
|
367 | + sleep($this->retry_interval); |
|
368 | 368 | |
369 | 369 | $this->retry_interval++; |
370 | 370 | |
371 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
371 | + return $this->process_payment($order_id, true, $force_save_source); |
|
372 | 372 | } else { |
373 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
374 | - $order->add_order_note( $localized_message ); |
|
375 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
373 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
374 | + $order->add_order_note($localized_message); |
|
375 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
379 | 379 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
380 | 380 | |
381 | - if ( 'card_error' === $response->error->type ) { |
|
382 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
381 | + if ('card_error' === $response->error->type) { |
|
382 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
383 | 383 | } else { |
384 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
384 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
385 | 385 | } |
386 | 386 | |
387 | - $order->add_order_note( $localized_message ); |
|
387 | + $order->add_order_note($localized_message); |
|
388 | 388 | |
389 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
389 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
390 | 390 | } |
391 | 391 | |
392 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
392 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
393 | 393 | |
394 | 394 | // Process valid response. |
395 | - $this->process_response( $response, $order ); |
|
395 | + $this->process_response($response, $order); |
|
396 | 396 | } else { |
397 | 397 | $order->payment_complete(); |
398 | 398 | } |
@@ -403,17 +403,17 @@ discard block |
||
403 | 403 | // Return thank you page redirect. |
404 | 404 | return array( |
405 | 405 | 'result' => 'success', |
406 | - 'redirect' => $this->get_return_url( $order ), |
|
406 | + 'redirect' => $this->get_return_url($order), |
|
407 | 407 | ); |
408 | 408 | |
409 | - } catch ( WC_Stripe_Exception $e ) { |
|
410 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
411 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
409 | + } catch (WC_Stripe_Exception $e) { |
|
410 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
411 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
412 | 412 | |
413 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
413 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
414 | 414 | |
415 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
416 | - $this->send_failed_order_email( $order_id ); |
|
415 | + if ($order->has_status(array('pending', 'failed'))) { |
|
416 | + $this->send_failed_order_email($order_id); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | return array( |