@@ -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( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
| 35 | + public function __construct($user_id = 0) { |
|
| 36 | + if ($user_id) { |
|
| 37 | + $this->set_user_id($user_id); |
|
| 38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
| 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 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $id ); |
|
| 59 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $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 | |
@@ -98,37 +98,37 @@ discard block |
||
| 98 | 98 | * @param array $args |
| 99 | 99 | * @return WP_Error|int |
| 100 | 100 | */ |
| 101 | - public function create_customer( $args = array() ) { |
|
| 102 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
| 101 | + public function create_customer($args = array()) { |
|
| 102 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
| 103 | 103 | $user = $this->get_user(); |
| 104 | 104 | |
| 105 | - if ( $user ) { |
|
| 106 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
| 107 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
| 105 | + if ($user) { |
|
| 106 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
| 107 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
| 108 | 108 | |
| 109 | 109 | // If billing first name does not exists try the user first name. |
| 110 | - if ( empty( $billing_first_name ) ) { |
|
| 111 | - $billing_first_name = get_user_meta( $user->ID, 'first_name', true ); |
|
| 110 | + if (empty($billing_first_name)) { |
|
| 111 | + $billing_first_name = get_user_meta($user->ID, 'first_name', true); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // If billing last name does not exists try the user last name. |
| 115 | - if ( empty( $billing_last_name ) ) { |
|
| 116 | - $billing_last_name = get_user_meta( $user->ID, 'last_name', true ); |
|
| 115 | + if (empty($billing_last_name)) { |
|
| 116 | + $billing_last_name = get_user_meta($user->ID, 'last_name', true); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // translators: %1$s First name, %2$s Second name, %3$s Username. |
| 120 | - $description = sprintf( __( 'Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name, $user->user_login ); |
|
| 120 | + $description = sprintf(__('Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name, $user->user_login); |
|
| 121 | 121 | |
| 122 | 122 | $defaults = array( |
| 123 | 123 | 'email' => $user->user_email, |
| 124 | 124 | 'description' => $description, |
| 125 | 125 | ); |
| 126 | 126 | } else { |
| 127 | - $billing_first_name = isset( $_POST['billing_first_name'] ) ? filter_var( wp_unslash( $_POST['billing_first_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 128 | - $billing_last_name = isset( $_POST['billing_last_name'] ) ? filter_var( wp_unslash( $_POST['billing_last_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 127 | + $billing_first_name = isset($_POST['billing_first_name']) ? filter_var(wp_unslash($_POST['billing_first_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 128 | + $billing_last_name = isset($_POST['billing_last_name']) ? filter_var(wp_unslash($_POST['billing_last_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 129 | 129 | |
| 130 | 130 | // translators: %1$s First name, %2$s Second name. |
| 131 | - $description = sprintf( __( 'Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name ); |
|
| 131 | + $description = sprintf(__('Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name); |
|
| 132 | 132 | |
| 133 | 133 | $defaults = array( |
| 134 | 134 | 'email' => $billing_email, |
@@ -138,24 +138,24 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | $metadata = array(); |
| 140 | 140 | |
| 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 | - $args = wp_parse_args( $args, $defaults ); |
|
| 144 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
| 143 | + $args = wp_parse_args($args, $defaults); |
|
| 144 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
| 145 | 145 | |
| 146 | - if ( ! empty( $response->error ) ) { |
|
| 147 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 146 | + if ( ! empty($response->error)) { |
|
| 147 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $this->set_id( $response->id ); |
|
| 150 | + $this->set_id($response->id); |
|
| 151 | 151 | $this->clear_cache(); |
| 152 | - $this->set_customer_data( $response ); |
|
| 152 | + $this->set_customer_data($response); |
|
| 153 | 153 | |
| 154 | - if ( $this->get_user_id() ) { |
|
| 155 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
| 154 | + if ($this->get_user_id()) { |
|
| 155 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
| 158 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
| 159 | 159 | |
| 160 | 160 | return $response->id; |
| 161 | 161 | } |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | * @since 4.1.2 |
| 168 | 168 | * @param array $error |
| 169 | 169 | */ |
| 170 | - public function is_no_such_customer_error( $error ) { |
|
| 170 | + public function is_no_such_customer_error($error) { |
|
| 171 | 171 | return ( |
| 172 | 172 | $error && |
| 173 | 173 | 'invalid_request_error' === $error->type && |
| 174 | - preg_match( '/No such customer/i', $error->message ) |
|
| 174 | + preg_match('/No such customer/i', $error->message) |
|
| 175 | 175 | ); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | * @param string $source_id |
| 181 | 181 | * @return WP_Error|int |
| 182 | 182 | */ |
| 183 | - public function add_source( $source_id ) { |
|
| 184 | - if ( ! $this->get_id() ) { |
|
| 185 | - $this->set_id( $this->create_customer() ); |
|
| 183 | + public function add_source($source_id) { |
|
| 184 | + if ( ! $this->get_id()) { |
|
| 185 | + $this->set_id($this->create_customer()); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | $response = WC_Stripe_API::request( |
@@ -194,63 +194,63 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | $wc_token = false; |
| 196 | 196 | |
| 197 | - if ( ! empty( $response->error ) ) { |
|
| 197 | + if ( ! empty($response->error)) { |
|
| 198 | 198 | // It is possible the WC user once was linked to a customer on Stripe |
| 199 | 199 | // but no longer exists. Instead of failing, lets try to create a |
| 200 | 200 | // new customer. |
| 201 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 202 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
| 201 | + if ($this->is_no_such_customer_error($response->error)) { |
|
| 202 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
| 203 | 203 | $this->create_customer(); |
| 204 | - return $this->add_source( $source_id ); |
|
| 204 | + return $this->add_source($source_id); |
|
| 205 | 205 | } else { |
| 206 | 206 | return $response; |
| 207 | 207 | } |
| 208 | - } elseif ( empty( $response->id ) ) { |
|
| 209 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
| 208 | + } elseif (empty($response->id)) { |
|
| 209 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // Add token to WooCommerce. |
| 213 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 214 | - if ( ! empty( $response->type ) ) { |
|
| 215 | - switch ( $response->type ) { |
|
| 213 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
| 214 | + if ( ! empty($response->type)) { |
|
| 215 | + switch ($response->type) { |
|
| 216 | 216 | case 'alipay': |
| 217 | 217 | break; |
| 218 | 218 | case 'sepa_debit': |
| 219 | 219 | $wc_token = new WC_Payment_Token_SEPA(); |
| 220 | - $wc_token->set_token( $response->id ); |
|
| 221 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
| 222 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
| 220 | + $wc_token->set_token($response->id); |
|
| 221 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
| 222 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
| 223 | 223 | break; |
| 224 | 224 | default: |
| 225 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
| 225 | + if ('source' === $response->object && 'card' === $response->type) { |
|
| 226 | 226 | $wc_token = new WC_Payment_Token_CC(); |
| 227 | - $wc_token->set_token( $response->id ); |
|
| 228 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 229 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
| 230 | - $wc_token->set_last4( $response->card->last4 ); |
|
| 231 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
| 232 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
| 227 | + $wc_token->set_token($response->id); |
|
| 228 | + $wc_token->set_gateway_id('stripe'); |
|
| 229 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
| 230 | + $wc_token->set_last4($response->card->last4); |
|
| 231 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
| 232 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
| 233 | 233 | } |
| 234 | 234 | break; |
| 235 | 235 | } |
| 236 | 236 | } else { |
| 237 | 237 | // Legacy. |
| 238 | 238 | $wc_token = new WC_Payment_Token_CC(); |
| 239 | - $wc_token->set_token( $response->id ); |
|
| 240 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 241 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
| 242 | - $wc_token->set_last4( $response->last4 ); |
|
| 243 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
| 244 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
| 239 | + $wc_token->set_token($response->id); |
|
| 240 | + $wc_token->set_gateway_id('stripe'); |
|
| 241 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
| 242 | + $wc_token->set_last4($response->last4); |
|
| 243 | + $wc_token->set_expiry_month($response->exp_month); |
|
| 244 | + $wc_token->set_expiry_year($response->exp_year); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
| 247 | + $wc_token->set_user_id($this->get_user_id()); |
|
| 248 | 248 | $wc_token->save(); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $this->clear_cache(); |
| 252 | 252 | |
| 253 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
| 253 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
| 254 | 254 | |
| 255 | 255 | return $response->id; |
| 256 | 256 | } |
@@ -262,11 +262,11 @@ discard block |
||
| 262 | 262 | * @return array |
| 263 | 263 | */ |
| 264 | 264 | public function get_sources() { |
| 265 | - if ( ! $this->get_id() ) { |
|
| 265 | + if ( ! $this->get_id()) { |
|
| 266 | 266 | return array(); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 269 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
| 270 | 270 | |
| 271 | 271 | $response = WC_Stripe_API::request( |
| 272 | 272 | array( |
@@ -276,32 +276,32 @@ discard block |
||
| 276 | 276 | 'GET' |
| 277 | 277 | ); |
| 278 | 278 | |
| 279 | - if ( ! empty( $response->error ) ) { |
|
| 279 | + if ( ! empty($response->error)) { |
|
| 280 | 280 | return array(); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if ( is_array( $response->data ) ) { |
|
| 283 | + if (is_array($response->data)) { |
|
| 284 | 284 | $sources = $response->data; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - return empty( $sources ) ? array() : $sources; |
|
| 287 | + return empty($sources) ? array() : $sources; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
| 291 | 291 | * Delete a source from stripe. |
| 292 | 292 | * @param string $source_id |
| 293 | 293 | */ |
| 294 | - public function delete_source( $source_id ) { |
|
| 295 | - if ( ! $this->get_id() ) { |
|
| 294 | + public function delete_source($source_id) { |
|
| 295 | + if ( ! $this->get_id()) { |
|
| 296 | 296 | return false; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
| 299 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
| 300 | 300 | |
| 301 | 301 | $this->clear_cache(); |
| 302 | 302 | |
| 303 | - if ( empty( $response->error ) ) { |
|
| 304 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
| 303 | + if (empty($response->error)) { |
|
| 304 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
| 305 | 305 | |
| 306 | 306 | return true; |
| 307 | 307 | } |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * Set default source in Stripe |
| 314 | 314 | * @param string $source_id |
| 315 | 315 | */ |
| 316 | - public function set_default_source( $source_id ) { |
|
| 316 | + public function set_default_source($source_id) { |
|
| 317 | 317 | $response = WC_Stripe_API::request( |
| 318 | 318 | array( |
| 319 | - 'default_source' => sanitize_text_field( $source_id ), |
|
| 319 | + 'default_source' => sanitize_text_field($source_id), |
|
| 320 | 320 | ), |
| 321 | 321 | 'customers/' . $this->get_id(), |
| 322 | 322 | 'POST' |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | |
| 325 | 325 | $this->clear_cache(); |
| 326 | 326 | |
| 327 | - if ( empty( $response->error ) ) { |
|
| 328 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
| 327 | + if (empty($response->error)) { |
|
| 328 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
| 329 | 329 | |
| 330 | 330 | return true; |
| 331 | 331 | } |
@@ -340,25 +340,25 @@ discard block |
||
| 340 | 340 | * @return object|null Either a basic source object, or null. |
| 341 | 341 | */ |
| 342 | 342 | public function get_default_source() { |
| 343 | - if ( ! $this->get_id() ) { |
|
| 343 | + if ( ! $this->get_id()) { |
|
| 344 | 344 | return null; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | // First, try to load the default source from the WooCommerce customer object. |
| 348 | - if ( ! empty( $this->user_id ) ) { |
|
| 349 | - $default_token = WC_Payment_Tokens::get_customer_default_token( $this->user_id ); |
|
| 348 | + if ( ! empty($this->user_id)) { |
|
| 349 | + $default_token = WC_Payment_Tokens::get_customer_default_token($this->user_id); |
|
| 350 | 350 | |
| 351 | - if ( ! empty( $default_token ) && 'stripe' === $default_token->get_gateway_id() ) { |
|
| 352 | - $source = WC_Stripe_API::request( array(), 'sources/' . $default_token->get_token(), 'GET' ); |
|
| 353 | - if ( empty( $source->error ) && ! empty( $source->customer ) && $this->id === $source->customer ) { |
|
| 351 | + if ( ! empty($default_token) && 'stripe' === $default_token->get_gateway_id()) { |
|
| 352 | + $source = WC_Stripe_API::request(array(), 'sources/' . $default_token->get_token(), 'GET'); |
|
| 353 | + if (empty($source->error) && ! empty($source->customer) && $this->id === $source->customer) { |
|
| 354 | 354 | return $source; |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | // Second, try to load the default source based on the user. |
| 360 | - $customer_object = WC_Stripe_API::request( array( 'expand[]' => 'default_source' ), 'customers/' . $this->id, 'GET' ); |
|
| 361 | - if ( empty( $customer_object->error ) && ! empty( $customer_object->default_source ) && is_object( $customer_object->default_source ) ) { |
|
| 360 | + $customer_object = WC_Stripe_API::request(array('expand[]' => 'default_source'), 'customers/' . $this->id, 'GET'); |
|
| 361 | + if (empty($customer_object->error) && ! empty($customer_object->default_source) && is_object($customer_object->default_source)) { |
|
| 362 | 362 | return $customer_object->default_source; |
| 363 | 363 | } |
| 364 | 364 | |
@@ -369,8 +369,8 @@ discard block |
||
| 369 | 369 | * Deletes caches for this users cards. |
| 370 | 370 | */ |
| 371 | 371 | public function clear_cache() { |
| 372 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 373 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
| 372 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
| 373 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
| 374 | 374 | $this->customer_data = array(); |
| 375 | 375 | } |
| 376 | 376 | } |
@@ -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, 3 ); |
|
| 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, 3); |
|
| 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 | /** |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function display_update_subs_payment_checkout() { |
| 86 | 86 | if ( |
| 87 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
| 88 | - wcs_user_has_subscription( get_current_user_id(), '', 'active' ) && |
|
| 87 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
| 88 | + wcs_user_has_subscription(get_current_user_id(), '', 'active') && |
|
| 89 | 89 | is_add_payment_method_page() |
| 90 | 90 | ) { |
| 91 | 91 | printf( |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | <input id="wc-%1$s-update-subs-payment-method-card" name="wc-%1$s-update-subs-payment-method-card" type="checkbox" value="true" style="width:auto;" /> |
| 94 | 94 | <label for="wc-%1$s-update-subs-payment-method-card" style="display:inline;">%2$s</label> |
| 95 | 95 | </p>', |
| 96 | - esc_attr( $this->id ), |
|
| 97 | - esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe' ) ) ) |
|
| 96 | + esc_attr($this->id), |
|
| 97 | + esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe'))) |
|
| 98 | 98 | ); |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @param string $source_id |
| 107 | 107 | * @param object $source_object |
| 108 | 108 | */ |
| 109 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
| 110 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
| 109 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
| 110 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
| 111 | 111 | $all_subs = wcs_get_users_subscriptions(); |
| 112 | 112 | |
| 113 | - if ( ! empty( $all_subs ) ) { |
|
| 114 | - foreach ( $all_subs as $sub ) { |
|
| 115 | - if ( 'active' === $sub->get_status() ) { |
|
| 116 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
| 117 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
| 118 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
| 113 | + if ( ! empty($all_subs)) { |
|
| 114 | + foreach ($all_subs as $sub) { |
|
| 115 | + if ('active' === $sub->get_status()) { |
|
| 116 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
| 117 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
| 118 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -129,24 +129,24 @@ discard block |
||
| 129 | 129 | * @since 4.1.11 Remove 3DS check as it is not needed. |
| 130 | 130 | * @param int $order_id |
| 131 | 131 | */ |
| 132 | - public function change_subs_payment_method( $order_id ) { |
|
| 132 | + public function change_subs_payment_method($order_id) { |
|
| 133 | 133 | try { |
| 134 | - $subscription = wc_get_order( $order_id ); |
|
| 135 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
| 134 | + $subscription = wc_get_order($order_id); |
|
| 135 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
| 136 | 136 | |
| 137 | - $this->maybe_disallow_prepaid_card( $prepared_source ); |
|
| 138 | - $this->check_source( $prepared_source ); |
|
| 139 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
| 137 | + $this->maybe_disallow_prepaid_card($prepared_source); |
|
| 138 | + $this->check_source($prepared_source); |
|
| 139 | + $this->save_source_to_order($subscription, $prepared_source); |
|
| 140 | 140 | |
| 141 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
| 141 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
| 142 | 142 | |
| 143 | 143 | return array( |
| 144 | 144 | 'result' => 'success', |
| 145 | - 'redirect' => $this->get_return_url( $subscription ), |
|
| 145 | + 'redirect' => $this->get_return_url($subscription), |
|
| 146 | 146 | ); |
| 147 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 148 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 149 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 147 | + } catch (WC_Stripe_Exception $e) { |
|
| 148 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 149 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
@@ -155,16 +155,16 @@ discard block |
||
| 155 | 155 | * @param int $order_id |
| 156 | 156 | * @return array |
| 157 | 157 | */ |
| 158 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
| 159 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 160 | - if ( $this->is_subs_change_payment() ) { |
|
| 161 | - return $this->change_subs_payment_method( $order_id ); |
|
| 158 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
| 159 | + if ($this->has_subscription($order_id)) { |
|
| 160 | + if ($this->is_subs_change_payment()) { |
|
| 161 | + return $this->change_subs_payment_method($order_id); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Regular payment with force customer enabled |
| 165 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
| 165 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
| 166 | 166 | } else { |
| 167 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
| 167 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | * @param object $prepared_source The source that is used for the payment. |
| 177 | 177 | * @return array The arguments for the request. |
| 178 | 178 | */ |
| 179 | - public function generate_create_intent_request( $order, $prepared_source ) { |
|
| 180 | - $request = parent::generate_create_intent_request( $order, $prepared_source ); |
|
| 179 | + public function generate_create_intent_request($order, $prepared_source) { |
|
| 180 | + $request = parent::generate_create_intent_request($order, $prepared_source); |
|
| 181 | 181 | |
| 182 | 182 | // Non-subscription orders do not need any additional parameters. |
| 183 | - if ( ! $this->has_subscription( $order ) ) { |
|
| 183 | + if ( ! $this->has_subscription($order)) { |
|
| 184 | 184 | return $request; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -196,8 +196,8 @@ discard block |
||
| 196 | 196 | * @param $amount_to_charge float The amount to charge. |
| 197 | 197 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 198 | 198 | */ |
| 199 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 200 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
| 199 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 200 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -211,114 +211,114 @@ discard block |
||
| 211 | 211 | * @param bool $retry Should we retry the process? |
| 212 | 212 | * @param object $previous_error |
| 213 | 213 | */ |
| 214 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
| 214 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
| 215 | 215 | try { |
| 216 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 216 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 217 | 217 | /* translators: minimum amount */ |
| 218 | - 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 ) ) ); |
|
| 218 | + 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))); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
| 221 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
| 222 | 222 | |
| 223 | 223 | // Check for an existing intent, which is associated with the order. |
| 224 | - if ( $this->has_authentication_already_failed( $renewal_order ) ) { |
|
| 224 | + if ($this->has_authentication_already_failed($renewal_order)) { |
|
| 225 | 225 | return; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // Get source from order |
| 229 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 229 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
| 230 | 230 | $source_object = $prepared_source->source_object; |
| 231 | 231 | |
| 232 | - if ( ! $prepared_source->customer ) { |
|
| 233 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 232 | + if ( ! $prepared_source->customer) { |
|
| 233 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 236 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 237 | 237 | |
| 238 | 238 | /* If we're doing a retry and source is chargeable, we need to pass |
| 239 | 239 | * a different idempotency key and retry for success. |
| 240 | 240 | */ |
| 241 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
| 242 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
| 241 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
| 242 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - 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 ) ) { |
|
| 245 | + 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)) { |
|
| 246 | 246 | // Passing empty source will charge customer default. |
| 247 | 247 | $prepared_source->source = ''; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - $response = $this->create_and_confirm_intent_for_off_session( $renewal_order, $prepared_source, $amount ); |
|
| 250 | + $response = $this->create_and_confirm_intent_for_off_session($renewal_order, $prepared_source, $amount); |
|
| 251 | 251 | |
| 252 | - $is_authentication_required = $this->is_authentication_required_for_payment( $response ); |
|
| 252 | + $is_authentication_required = $this->is_authentication_required_for_payment($response); |
|
| 253 | 253 | |
| 254 | 254 | // It's only a failed payment if it's an error and it's not of the type 'authentication_required'. |
| 255 | 255 | // If it's 'authentication_required', then we should email the user and ask them to authenticate. |
| 256 | - if ( ! empty( $response->error ) && ! $is_authentication_required ) { |
|
| 256 | + if ( ! empty($response->error) && ! $is_authentication_required) { |
|
| 257 | 257 | // We want to retry. |
| 258 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
| 259 | - if ( $retry ) { |
|
| 258 | + if ($this->is_retryable_error($response->error)) { |
|
| 259 | + if ($retry) { |
|
| 260 | 260 | // Don't do anymore retries after this. |
| 261 | - if ( 5 <= $this->retry_interval ) { |
|
| 262 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
| 261 | + if (5 <= $this->retry_interval) { |
|
| 262 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - sleep( $this->retry_interval ); |
|
| 265 | + sleep($this->retry_interval); |
|
| 266 | 266 | |
| 267 | 267 | $this->retry_interval++; |
| 268 | 268 | |
| 269 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
| 269 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
| 270 | 270 | } else { |
| 271 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 272 | - $renewal_order->add_order_note( $localized_message ); |
|
| 273 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 271 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
| 272 | + $renewal_order->add_order_note($localized_message); |
|
| 273 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 278 | 278 | |
| 279 | - if ( 'card_error' === $response->error->type ) { |
|
| 280 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 279 | + if ('card_error' === $response->error->type) { |
|
| 280 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 281 | 281 | } else { |
| 282 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 282 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - $renewal_order->add_order_note( $localized_message ); |
|
| 285 | + $renewal_order->add_order_note($localized_message); |
|
| 286 | 286 | |
| 287 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 287 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | // By this point the charge _did not fail_. This means that the source and customer objects work, so make sure they are saved. |
| 291 | - $this->save_source_to_order( $renewal_order, $prepared_source ); |
|
| 291 | + $this->save_source_to_order($renewal_order, $prepared_source); |
|
| 292 | 292 | |
| 293 | 293 | // Either the charge was successfully captured, or it requires further authentication. |
| 294 | - if ( $is_authentication_required ) { |
|
| 295 | - do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response ); |
|
| 294 | + if ($is_authentication_required) { |
|
| 295 | + do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response); |
|
| 296 | 296 | |
| 297 | - $error_message = __( 'This transaction requires authentication.', 'woocommerce-gateway-stripe' ); |
|
| 298 | - $renewal_order->add_order_note( $error_message ); |
|
| 297 | + $error_message = __('This transaction requires authentication.', 'woocommerce-gateway-stripe'); |
|
| 298 | + $renewal_order->add_order_note($error_message); |
|
| 299 | 299 | |
| 300 | - $charge = end( $response->error->payment_intent->charges->data ); |
|
| 300 | + $charge = end($response->error->payment_intent->charges->data); |
|
| 301 | 301 | $id = $charge->id; |
| 302 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
| 302 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
| 303 | 303 | |
| 304 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $id ) : $renewal_order->set_transaction_id( $id ); |
|
| 305 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $id ) ); |
|
| 306 | - if ( is_callable( array( $renewal_order, 'save' ) ) ) { |
|
| 304 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $id) : $renewal_order->set_transaction_id($id); |
|
| 305 | + $renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $id)); |
|
| 306 | + if (is_callable(array($renewal_order, 'save'))) { |
|
| 307 | 307 | $renewal_order->save(); |
| 308 | 308 | } |
| 309 | 309 | } else { |
| 310 | 310 | // The charge was successfully captured |
| 311 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
| 311 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
| 312 | 312 | |
| 313 | - $this->process_response( end( $response->charges->data ), $renewal_order ); |
|
| 313 | + $this->process_response(end($response->charges->data), $renewal_order); |
|
| 314 | 314 | } |
| 315 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 316 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 315 | + } catch (WC_Stripe_Exception $e) { |
|
| 316 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 317 | 317 | |
| 318 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
| 318 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
| 319 | 319 | |
| 320 | 320 | /* translators: error message */ |
| 321 | - $renewal_order->update_status( 'failed' ); |
|
| 321 | + $renewal_order->update_status('failed'); |
|
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | |
@@ -328,24 +328,24 @@ discard block |
||
| 328 | 328 | * @since 3.1.0 |
| 329 | 329 | * @version 4.0.0 |
| 330 | 330 | */ |
| 331 | - public function save_source_to_order( $order, $source ) { |
|
| 332 | - parent::save_source_to_order( $order, $source ); |
|
| 331 | + public function save_source_to_order($order, $source) { |
|
| 332 | + parent::save_source_to_order($order, $source); |
|
| 333 | 333 | |
| 334 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 334 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 335 | 335 | |
| 336 | 336 | // Also store it on the subscriptions being purchased or paid for in the order |
| 337 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 338 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 339 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 340 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 337 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 338 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 339 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 340 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 341 | 341 | } else { |
| 342 | 342 | $subscriptions = array(); |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - foreach ( $subscriptions as $subscription ) { |
|
| 346 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
| 347 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 348 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 345 | + foreach ($subscriptions as $subscription) { |
|
| 346 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
| 347 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 348 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 349 | 349 | } |
| 350 | 350 | } |
| 351 | 351 | |
@@ -353,26 +353,26 @@ discard block |
||
| 353 | 353 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 354 | 354 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 355 | 355 | */ |
| 356 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 357 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 358 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 356 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 357 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 358 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 359 | 359 | // For BW compat will remove in future |
| 360 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 360 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 361 | 361 | // delete payment intent ID |
| 362 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_intent_id' ); |
|
| 363 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 362 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_intent_id'); |
|
| 363 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
| 367 | 367 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 368 | 368 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 369 | 369 | */ |
| 370 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 371 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
| 372 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
| 370 | + public function delete_renewal_meta($renewal_order) { |
|
| 371 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
| 372 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
| 373 | 373 | |
| 374 | 374 | // delete payment intent ID |
| 375 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id() ), '_stripe_intent_id' ); |
|
| 375 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id()), '_stripe_intent_id'); |
|
| 376 | 376 | |
| 377 | 377 | return $renewal_order; |
| 378 | 378 | } |
@@ -386,14 +386,14 @@ discard block |
||
| 386 | 386 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 387 | 387 | * @return void |
| 388 | 388 | */ |
| 389 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 390 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 391 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 392 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 389 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 390 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 391 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 392 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 393 | 393 | |
| 394 | 394 | } else { |
| 395 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 396 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 395 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 396 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | |
@@ -406,23 +406,23 @@ discard block |
||
| 406 | 406 | * @param WC_Subscription $subscription An instance of a subscription object |
| 407 | 407 | * @return array |
| 408 | 408 | */ |
| 409 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 410 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
| 411 | - $source_id = get_post_meta( $subscription_id, '_stripe_source_id', true ); |
|
| 409 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 410 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
| 411 | + $source_id = get_post_meta($subscription_id, '_stripe_source_id', true); |
|
| 412 | 412 | |
| 413 | 413 | // For BW compat will remove in future. |
| 414 | - if ( empty( $source_id ) ) { |
|
| 415 | - $source_id = get_post_meta( $subscription_id, '_stripe_card_id', true ); |
|
| 414 | + if (empty($source_id)) { |
|
| 415 | + $source_id = get_post_meta($subscription_id, '_stripe_card_id', true); |
|
| 416 | 416 | |
| 417 | 417 | // Take this opportunity to update the key name. |
| 418 | - update_post_meta( $subscription_id, '_stripe_source_id', $source_id ); |
|
| 419 | - delete_post_meta( $subscription_id, '_stripe_card_id', $source_id ); |
|
| 418 | + update_post_meta($subscription_id, '_stripe_source_id', $source_id); |
|
| 419 | + delete_post_meta($subscription_id, '_stripe_card_id', $source_id); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - $payment_meta[ $this->id ] = array( |
|
| 422 | + $payment_meta[$this->id] = array( |
|
| 423 | 423 | 'post_meta' => array( |
| 424 | 424 | '_stripe_customer_id' => array( |
| 425 | - 'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ), |
|
| 425 | + 'value' => get_post_meta($subscription_id, '_stripe_customer_id', true), |
|
| 426 | 426 | 'label' => 'Stripe Customer ID', |
| 427 | 427 | ), |
| 428 | 428 | '_stripe_source_id' => array( |
@@ -447,37 +447,37 @@ discard block |
||
| 447 | 447 | * @param WC_Subscription $subscription The subscription object. |
| 448 | 448 | * @return array |
| 449 | 449 | */ |
| 450 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta, $subscription ) { |
|
| 451 | - if ( $this->id === $payment_method_id ) { |
|
| 450 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta, $subscription) { |
|
| 451 | + if ($this->id === $payment_method_id) { |
|
| 452 | 452 | |
| 453 | - $customer_id = isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) && ! empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) |
|
| 453 | + $customer_id = isset($payment_meta['post_meta']['_stripe_customer_id']['value']) && ! empty($payment_meta['post_meta']['_stripe_customer_id']['value']) |
|
| 454 | 454 | ? $payment_meta['post_meta']['_stripe_customer_id']['value'] |
| 455 | 455 | : null; |
| 456 | 456 | |
| 457 | - $source_id = isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) && ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 457 | + $source_id = isset($payment_meta['post_meta']['_stripe_source_id']['value']) && ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 458 | 458 | ? $payment_meta['post_meta']['_stripe_source_id']['value'] |
| 459 | 459 | : null; |
| 460 | 460 | |
| 461 | 461 | // Reject if there is an invalid customer entered. |
| 462 | - if ( ! empty( $customer_id ) && 0 !== strpos( $customer_id, 'cus_' ) ) { |
|
| 463 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 462 | + if ( ! empty($customer_id) && 0 !== strpos($customer_id, 'cus_')) { |
|
| 463 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | // Reject if there is an invalid source entered. |
| 467 | - if ( ! empty( $source_id ) && 0 !== strpos( $source_id, 'src_' ) && 0 !== strpos( $source_id, 'card_' ) ) { |
|
| 468 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 467 | + if ( ! empty($source_id) && 0 !== strpos($source_id, 'src_') && 0 !== strpos($source_id, 'card_')) { |
|
| 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 | - if ( empty( $customer_id ) ) { |
|
| 471 | + if (empty($customer_id)) { |
|
| 472 | 472 | // Notify merchants that `customer_id` is required when `source_id` was manually entered. |
| 473 | - if ( ! empty( $source_id ) ) { |
|
| 474 | - throw new Exception( __( 'A "Stripe Customer ID" value is required when "Stripe Source ID" is used.', 'woocommerce-gateway-stripe' ) ); |
|
| 473 | + if ( ! empty($source_id)) { |
|
| 474 | + throw new Exception(__('A "Stripe Customer ID" value is required when "Stripe Source ID" is used.', 'woocommerce-gateway-stripe')); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | // Before bailing, check if there is a default source that can be used. |
| 478 | - $default_source = $this->get_default_customer_source_for_order( $subscription ); |
|
| 479 | - if ( empty( $default_source ) ) { |
|
| 480 | - throw new Exception( __( 'A "Stripe Customer ID" value or a customer with a Stripe account are required.', 'woocommerce-gateway-stripe' ) ); |
|
| 478 | + $default_source = $this->get_default_customer_source_for_order($subscription); |
|
| 479 | + if (empty($default_source)) { |
|
| 480 | + throw new Exception(__('A "Stripe Customer ID" value or a customer with a Stripe account are required.', 'woocommerce-gateway-stripe')); |
|
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | } |
@@ -491,75 +491,75 @@ discard block |
||
| 491 | 491 | * @param WC_Subscription $subscription the subscription details |
| 492 | 492 | * @return string the subscription payment method |
| 493 | 493 | */ |
| 494 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 495 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 494 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 495 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 496 | 496 | |
| 497 | 497 | // bail for other payment methods |
| 498 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 498 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 499 | 499 | return $payment_method_to_display; |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 502 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 503 | 503 | |
| 504 | 504 | // For BW compat will remove in future. |
| 505 | - if ( empty( $stripe_source_id ) ) { |
|
| 506 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 505 | + if (empty($stripe_source_id)) { |
|
| 506 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 507 | 507 | |
| 508 | 508 | // Take this opportunity to update the key name. |
| 509 | - 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 ); |
|
| 509 | + 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); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | $stripe_customer = new WC_Stripe_Customer(); |
| 513 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 513 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 514 | 514 | |
| 515 | 515 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 516 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 516 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 517 | 517 | $user_id = $customer_user; |
| 518 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 519 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 518 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 519 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 520 | 520 | |
| 521 | 521 | // For BW compat will remove in future. |
| 522 | - if ( empty( $stripe_source_id ) ) { |
|
| 523 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 522 | + if (empty($stripe_source_id)) { |
|
| 523 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 524 | 524 | |
| 525 | 525 | // Take this opportunity to update the key name. |
| 526 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 526 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 531 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 532 | - $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 ); |
|
| 533 | - $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 ); |
|
| 531 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 532 | + $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); |
|
| 533 | + $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); |
|
| 534 | 534 | |
| 535 | 535 | // For BW compat will remove in future. |
| 536 | - if ( empty( $stripe_source_id ) ) { |
|
| 537 | - $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 ); |
|
| 536 | + if (empty($stripe_source_id)) { |
|
| 537 | + $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); |
|
| 538 | 538 | |
| 539 | 539 | // Take this opportunity to update the key name. |
| 540 | - 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 ); |
|
| 540 | + 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); |
|
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 544 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 545 | 545 | |
| 546 | 546 | $sources = $stripe_customer->get_sources(); |
| 547 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 547 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 548 | 548 | |
| 549 | - if ( $sources ) { |
|
| 549 | + if ($sources) { |
|
| 550 | 550 | $card = false; |
| 551 | 551 | |
| 552 | - foreach ( $sources as $source ) { |
|
| 553 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 552 | + foreach ($sources as $source) { |
|
| 553 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 554 | 554 | $card = $source->card; |
| 555 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
| 555 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
| 556 | 556 | $card = $source; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - if ( $source->id === $stripe_source_id ) { |
|
| 560 | - if ( $card ) { |
|
| 559 | + if ($source->id === $stripe_source_id) { |
|
| 560 | + if ($card) { |
|
| 561 | 561 | /* translators: 1) card brand 2) last 4 digits */ |
| 562 | - $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 ); |
|
| 562 | + $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); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | break; |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | */ |
| 577 | 577 | public function remove_order_pay_var() { |
| 578 | 578 | global $wp; |
| 579 | - if ( isset( $_GET['wc-stripe-confirmation'] ) ) { |
|
| 579 | + if (isset($_GET['wc-stripe-confirmation'])) { |
|
| 580 | 580 | $this->order_pay_var = $wp->query_vars['order-pay']; |
| 581 | 581 | $wp->query_vars['order-pay'] = null; |
| 582 | 582 | } |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | */ |
| 588 | 588 | public function restore_order_pay_var() { |
| 589 | 589 | global $wp; |
| 590 | - if ( isset( $this->order_pay_var ) ) { |
|
| 590 | + if (isset($this->order_pay_var)) { |
|
| 591 | 591 | $wp->query_vars['order-pay'] = $this->order_pay_var; |
| 592 | 592 | } |
| 593 | 593 | } |
@@ -598,13 +598,13 @@ discard block |
||
| 598 | 598 | * @param WC_Order $renewal_order The renewal order. |
| 599 | 599 | * @return boolean |
| 600 | 600 | */ |
| 601 | - public function has_authentication_already_failed( $renewal_order ) { |
|
| 602 | - $existing_intent = $this->get_intent_from_order( $renewal_order ); |
|
| 601 | + public function has_authentication_already_failed($renewal_order) { |
|
| 602 | + $existing_intent = $this->get_intent_from_order($renewal_order); |
|
| 603 | 603 | |
| 604 | 604 | if ( |
| 605 | 605 | ! $existing_intent |
| 606 | 606 | || 'requires_payment_method' !== $existing_intent->status |
| 607 | - || empty( $existing_intent->last_payment_error ) |
|
| 607 | + || empty($existing_intent->last_payment_error) |
|
| 608 | 608 | || 'authentication_required' !== $existing_intent->last_payment_error->code |
| 609 | 609 | ) { |
| 610 | 610 | return false; |
@@ -618,12 +618,12 @@ discard block |
||
| 618 | 618 | * |
| 619 | 619 | * @param WC_Order $renewal_order The order that is being renewed. |
| 620 | 620 | */ |
| 621 | - do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order ); |
|
| 621 | + do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order); |
|
| 622 | 622 | |
| 623 | 623 | // Fail the payment attempt (order would be currently pending because of retry rules). |
| 624 | - $charge = end( $existing_intent->charges->data ); |
|
| 624 | + $charge = end($existing_intent->charges->data); |
|
| 625 | 625 | $charge_id = $charge->id; |
| 626 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $charge_id ) ); |
|
| 626 | + $renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $charge_id)); |
|
| 627 | 627 | |
| 628 | 628 | return true; |
| 629 | 629 | } |
@@ -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_meta( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
| 256 | + public function get_stripe_customer_id($order) { |
|
| 257 | + $customer = get_user_meta(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
| 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,60 +575,60 @@ 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 ) { |
|
| 580 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
| 581 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
| 578 | + public function prepare_source($user_id, $force_save_source = false) { |
|
| 579 | + $customer = new WC_Stripe_Customer($user_id); |
|
| 580 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
| 582 | 581 | $source_object = ''; |
| 583 | 582 | $source_id = ''; |
| 584 | 583 | $wc_token_id = false; |
| 585 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
| 584 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
| 586 | 585 | $is_token = false; |
| 587 | 586 | |
| 588 | 587 | // New CC info was entered and we have a new source to process. |
| 589 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
| 590 | - $source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) ); |
|
| 588 | + if ( ! empty($_POST['stripe_source'])) { |
|
| 589 | + $source_object = self::get_source_object(wc_clean($_POST['stripe_source'])); |
|
| 591 | 590 | $source_id = $source_object->id; |
| 592 | 591 | |
| 593 | 592 | // This checks to see if customer opted to save the payment method to file. |
| 594 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 593 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 595 | 594 | |
| 596 | 595 | /** |
| 597 | 596 | * This is true if the user wants to store the card to their account. |
| 598 | 597 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
| 599 | 598 | * actually reusable. Either that or force_save_source is true. |
| 600 | 599 | */ |
| 601 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
| 602 | - $response = $customer->add_source( $source_object->id ); |
|
| 600 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
| 601 | + $response = $customer->add_source($source_object->id); |
|
| 603 | 602 | |
| 604 | - if ( ! empty( $response->error ) ) { |
|
| 605 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 603 | + if ( ! empty($response->error)) { |
|
| 604 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 606 | 605 | } |
| 607 | 606 | } |
| 608 | - } elseif ( $this->is_using_saved_payment_method() ) { |
|
| 607 | + } elseif ($this->is_using_saved_payment_method()) { |
|
| 609 | 608 | // Use an existing token, and then process the payment. |
| 610 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
| 611 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
| 609 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
| 610 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
| 612 | 611 | |
| 613 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
| 614 | - WC()->session->set( 'refresh_totals', true ); |
|
| 615 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 612 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
| 613 | + WC()->session->set('refresh_totals', true); |
|
| 614 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 616 | 615 | } |
| 617 | 616 | |
| 618 | 617 | $source_id = $wc_token->get_token(); |
| 619 | 618 | |
| 620 | - if ( $this->is_type_legacy_card( $source_id ) ) { |
|
| 619 | + if ($this->is_type_legacy_card($source_id)) { |
|
| 621 | 620 | $is_token = true; |
| 622 | 621 | } |
| 623 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
| 624 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 625 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 622 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
| 623 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 624 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 626 | 625 | |
| 627 | 626 | // This is true if the user wants to store the card to their account. |
| 628 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
| 629 | - $response = $customer->add_source( $stripe_token ); |
|
| 627 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
| 628 | + $response = $customer->add_source($stripe_token); |
|
| 630 | 629 | |
| 631 | - if ( ! empty( $response->error ) ) { |
|
| 632 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 630 | + if ( ! empty($response->error)) { |
|
| 631 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 633 | 632 | } |
| 634 | 633 | } else { |
| 635 | 634 | $source_id = $stripe_token; |
@@ -638,13 +637,13 @@ discard block |
||
| 638 | 637 | } |
| 639 | 638 | |
| 640 | 639 | $customer_id = $customer->get_id(); |
| 641 | - if ( ! $customer_id ) { |
|
| 642 | - $customer->set_id( $customer->create_customer() ); |
|
| 640 | + if ( ! $customer_id) { |
|
| 641 | + $customer->set_id($customer->create_customer()); |
|
| 643 | 642 | $customer_id = $customer->get_id(); |
| 644 | 643 | } |
| 645 | 644 | |
| 646 | - if ( empty( $source_object ) && ! $is_token ) { |
|
| 647 | - $source_object = self::get_source_object( $source_id ); |
|
| 645 | + if (empty($source_object) && ! $is_token) { |
|
| 646 | + $source_object = self::get_source_object($source_id); |
|
| 648 | 647 | } |
| 649 | 648 | |
| 650 | 649 | return (object) array( |
@@ -668,46 +667,46 @@ discard block |
||
| 668 | 667 | * @param object $order |
| 669 | 668 | * @return object |
| 670 | 669 | */ |
| 671 | - public function prepare_order_source( $order = null ) { |
|
| 670 | + public function prepare_order_source($order = null) { |
|
| 672 | 671 | $stripe_customer = new WC_Stripe_Customer(); |
| 673 | 672 | $stripe_source = false; |
| 674 | 673 | $token_id = false; |
| 675 | 674 | $source_object = false; |
| 676 | 675 | |
| 677 | - if ( $order ) { |
|
| 678 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 676 | + if ($order) { |
|
| 677 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 679 | 678 | |
| 680 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
| 679 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
| 681 | 680 | |
| 682 | - if ( $stripe_customer_id ) { |
|
| 683 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 681 | + if ($stripe_customer_id) { |
|
| 682 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 684 | 683 | } |
| 685 | 684 | |
| 686 | - $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 ); |
|
| 685 | + $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); |
|
| 687 | 686 | |
| 688 | 687 | // Since 4.0.0, we changed card to source so we need to account for that. |
| 689 | - if ( empty( $source_id ) ) { |
|
| 690 | - $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 ); |
|
| 688 | + if (empty($source_id)) { |
|
| 689 | + $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); |
|
| 691 | 690 | |
| 692 | 691 | // Take this opportunity to update the key name. |
| 693 | - 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 ); |
|
| 692 | + 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); |
|
| 694 | 693 | |
| 695 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 694 | + if (is_callable(array($order, 'save'))) { |
|
| 696 | 695 | $order->save(); |
| 697 | 696 | } |
| 698 | 697 | } |
| 699 | 698 | |
| 700 | - if ( $source_id ) { |
|
| 699 | + if ($source_id) { |
|
| 701 | 700 | $stripe_source = $source_id; |
| 702 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
| 703 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 701 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
| 702 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 704 | 703 | /* |
| 705 | 704 | * ~We can attempt to charge the customer's default source~ |
| 706 | 705 | * ~by sending empty source id.~ |
| 707 | 706 | * We retrieve the default customer source manually. |
| 708 | 707 | */ |
| 709 | - $default_source = $this->get_default_customer_source_for_order( $order ); |
|
| 710 | - if ( ! empty( $default_source ) ) { |
|
| 708 | + $default_source = $this->get_default_customer_source_for_order($order); |
|
| 709 | + if ( ! empty($default_source)) { |
|
| 711 | 710 | return $default_source; |
| 712 | 711 | } |
| 713 | 712 | } |
@@ -728,36 +727,36 @@ discard block |
||
| 728 | 727 | * @param WC_Order $order The order to use as a starting point. |
| 729 | 728 | * @return stdClass|null Either an object with the necessary data or null. |
| 730 | 729 | */ |
| 731 | - public function get_default_customer_source_for_order( $order ) { |
|
| 730 | + public function get_default_customer_source_for_order($order) { |
|
| 732 | 731 | $stripe_customer = null; |
| 733 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 732 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 734 | 733 | |
| 735 | 734 | // Check for explicit manual input first. |
| 736 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
| 737 | - if ( ! empty( $stripe_customer_id ) ) { |
|
| 735 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
| 736 | + if ( ! empty($stripe_customer_id)) { |
|
| 738 | 737 | $stripe_customer = new WC_Stripe_Customer(); |
| 739 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 738 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 740 | 739 | } |
| 741 | 740 | |
| 742 | 741 | // If there is a WooCommerce customer to work with, check if they have a Stripe ID. |
| 743 | - if ( empty( $stripe_customer ) ) { |
|
| 742 | + if (empty($stripe_customer)) { |
|
| 744 | 743 | $wc_customer = $order->get_user(); |
| 745 | - if ( $wc_customer ) { |
|
| 746 | - $stripe_customer = new WC_Stripe_Customer( $wc_customer->ID ); |
|
| 747 | - if ( empty( $stripe_customer->get_id() ) ) { |
|
| 744 | + if ($wc_customer) { |
|
| 745 | + $stripe_customer = new WC_Stripe_Customer($wc_customer->ID); |
|
| 746 | + if (empty($stripe_customer->get_id())) { |
|
| 748 | 747 | $stripe_customer = null; |
| 749 | 748 | } |
| 750 | 749 | } |
| 751 | 750 | } |
| 752 | 751 | |
| 753 | 752 | // No customer to work with, neither coming from WooCommerce nor Subscription's fields. |
| 754 | - if ( empty( $stripe_customer ) ) { |
|
| 753 | + if (empty($stripe_customer)) { |
|
| 755 | 754 | return null; |
| 756 | 755 | } |
| 757 | 756 | |
| 758 | 757 | // Try to retrieve the default source of the customer. |
| 759 | 758 | $source_object = $stripe_customer->get_default_source(); |
| 760 | - if ( empty( $source_object ) ) { |
|
| 759 | + if (empty($source_object)) { |
|
| 761 | 760 | return null; |
| 762 | 761 | } |
| 763 | 762 | |
@@ -777,27 +776,27 @@ discard block |
||
| 777 | 776 | * @param WC_Order $order For to which the source applies. |
| 778 | 777 | * @param stdClass $source Source information. |
| 779 | 778 | */ |
| 780 | - public function save_source_to_order( $order, $source ) { |
|
| 781 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 779 | + public function save_source_to_order($order, $source) { |
|
| 780 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 782 | 781 | |
| 783 | 782 | // Store source in the order. |
| 784 | - if ( $source->customer ) { |
|
| 785 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 786 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
| 783 | + if ($source->customer) { |
|
| 784 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 785 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
| 787 | 786 | } else { |
| 788 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
| 787 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
| 789 | 788 | } |
| 790 | 789 | } |
| 791 | 790 | |
| 792 | - if ( $source->source ) { |
|
| 793 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 794 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
| 791 | + if ($source->source) { |
|
| 792 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 793 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
| 795 | 794 | } else { |
| 796 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
| 795 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
| 797 | 796 | } |
| 798 | 797 | } |
| 799 | 798 | |
| 800 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 799 | + if (is_callable(array($order, 'save'))) { |
|
| 801 | 800 | $order->save(); |
| 802 | 801 | } |
| 803 | 802 | } |
@@ -811,38 +810,38 @@ discard block |
||
| 811 | 810 | * @param object $order The order object |
| 812 | 811 | * @param int $balance_transaction_id |
| 813 | 812 | */ |
| 814 | - public function update_fees( $order, $balance_transaction_id ) { |
|
| 815 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 813 | + public function update_fees($order, $balance_transaction_id) { |
|
| 814 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 816 | 815 | |
| 817 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
| 816 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
| 818 | 817 | |
| 819 | - if ( empty( $balance_transaction->error ) ) { |
|
| 820 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
| 818 | + if (empty($balance_transaction->error)) { |
|
| 819 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
| 821 | 820 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 822 | 821 | // values are in the local currency of the Stripe account, not from WC. |
| 823 | - $fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
| 824 | - $net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
| 822 | + $fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
| 823 | + $net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
| 825 | 824 | |
| 826 | 825 | // Current data fee & net. |
| 827 | - $fee_current = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
| 828 | - $net_current = WC_Stripe_Helper::get_stripe_net( $order ); |
|
| 826 | + $fee_current = WC_Stripe_Helper::get_stripe_fee($order); |
|
| 827 | + $net_current = WC_Stripe_Helper::get_stripe_net($order); |
|
| 829 | 828 | |
| 830 | 829 | // Calculation. |
| 831 | 830 | $fee = (float) $fee_current + (float) $fee_refund; |
| 832 | 831 | $net = (float) $net_current + (float) $net_refund; |
| 833 | 832 | |
| 834 | - WC_Stripe_Helper::update_stripe_fee( $order, $fee ); |
|
| 835 | - WC_Stripe_Helper::update_stripe_net( $order, $net ); |
|
| 833 | + WC_Stripe_Helper::update_stripe_fee($order, $fee); |
|
| 834 | + WC_Stripe_Helper::update_stripe_net($order, $net); |
|
| 836 | 835 | |
| 837 | - $currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null; |
|
| 838 | - WC_Stripe_Helper::update_stripe_currency( $order, $currency ); |
|
| 836 | + $currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null; |
|
| 837 | + WC_Stripe_Helper::update_stripe_currency($order, $currency); |
|
| 839 | 838 | |
| 840 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 839 | + if (is_callable(array($order, 'save'))) { |
|
| 841 | 840 | $order->save(); |
| 842 | 841 | } |
| 843 | 842 | } |
| 844 | 843 | } else { |
| 845 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
| 844 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
| 846 | 845 | } |
| 847 | 846 | } |
| 848 | 847 | |
@@ -855,99 +854,99 @@ discard block |
||
| 855 | 854 | * @param float $amount |
| 856 | 855 | * @return bool |
| 857 | 856 | */ |
| 858 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 859 | - $order = wc_get_order( $order_id ); |
|
| 857 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 858 | + $order = wc_get_order($order_id); |
|
| 860 | 859 | |
| 861 | - if ( ! $order ) { |
|
| 860 | + if ( ! $order) { |
|
| 862 | 861 | return false; |
| 863 | 862 | } |
| 864 | 863 | |
| 865 | 864 | $request = array(); |
| 866 | 865 | |
| 867 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 868 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
| 869 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
| 870 | - $charge_id = get_post_meta( $order_id, '_transaction_id', true ); |
|
| 866 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 867 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
| 868 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
| 869 | + $charge_id = get_post_meta($order_id, '_transaction_id', true); |
|
| 871 | 870 | } else { |
| 872 | 871 | $order_currency = $order->get_currency(); |
| 873 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
| 872 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
| 874 | 873 | $charge_id = $order->get_transaction_id(); |
| 875 | 874 | } |
| 876 | 875 | |
| 877 | - if ( ! $charge_id ) { |
|
| 876 | + if ( ! $charge_id) { |
|
| 878 | 877 | return false; |
| 879 | 878 | } |
| 880 | 879 | |
| 881 | - if ( ! is_null( $amount ) ) { |
|
| 882 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
| 880 | + if ( ! is_null($amount)) { |
|
| 881 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
| 883 | 882 | } |
| 884 | 883 | |
| 885 | 884 | // If order is only authorized, don't pass amount. |
| 886 | - if ( 'yes' !== $captured ) { |
|
| 887 | - unset( $request['amount'] ); |
|
| 885 | + if ('yes' !== $captured) { |
|
| 886 | + unset($request['amount']); |
|
| 888 | 887 | } |
| 889 | 888 | |
| 890 | - if ( $reason ) { |
|
| 889 | + if ($reason) { |
|
| 891 | 890 | $request['metadata'] = array( |
| 892 | 891 | 'reason' => $reason, |
| 893 | 892 | ); |
| 894 | 893 | } |
| 895 | 894 | |
| 896 | 895 | $request['charge'] = $charge_id; |
| 897 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$charge_id} for the amount of {$amount}" ); |
|
| 896 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$charge_id} for the amount of {$amount}"); |
|
| 898 | 897 | |
| 899 | - $request = apply_filters( 'wc_stripe_refund_request', $request, $order ); |
|
| 898 | + $request = apply_filters('wc_stripe_refund_request', $request, $order); |
|
| 900 | 899 | |
| 901 | - $intent = $this->get_intent_from_order( $order ); |
|
| 900 | + $intent = $this->get_intent_from_order($order); |
|
| 902 | 901 | $intent_cancelled = false; |
| 903 | - if ( $intent ) { |
|
| 902 | + if ($intent) { |
|
| 904 | 903 | // If the order has a Payment Intent pending capture, then the Intent itself must be refunded (cancelled), not the Charge |
| 905 | - if ( ! empty( $intent->error ) ) { |
|
| 904 | + if ( ! empty($intent->error)) { |
|
| 906 | 905 | $response = $intent; |
| 907 | 906 | $intent_cancelled = true; |
| 908 | - } elseif ( 'requires_capture' === $intent->status ) { |
|
| 907 | + } elseif ('requires_capture' === $intent->status) { |
|
| 909 | 908 | $result = WC_Stripe_API::request( |
| 910 | 909 | array(), |
| 911 | 910 | 'payment_intents/' . $intent->id . '/cancel' |
| 912 | 911 | ); |
| 913 | 912 | $intent_cancelled = true; |
| 914 | 913 | |
| 915 | - if ( ! empty( $result->error ) ) { |
|
| 914 | + if ( ! empty($result->error)) { |
|
| 916 | 915 | $response = $result; |
| 917 | 916 | } else { |
| 918 | - $charge = end( $result->charges->data ); |
|
| 919 | - $response = end( $charge->refunds->data ); |
|
| 917 | + $charge = end($result->charges->data); |
|
| 918 | + $response = end($charge->refunds->data); |
|
| 920 | 919 | } |
| 921 | 920 | } |
| 922 | 921 | } |
| 923 | 922 | |
| 924 | - if ( ! $intent_cancelled ) { |
|
| 925 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
| 923 | + if ( ! $intent_cancelled) { |
|
| 924 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
| 926 | 925 | } |
| 927 | 926 | |
| 928 | - if ( ! empty( $response->error ) ) { |
|
| 929 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
| 927 | + if ( ! empty($response->error)) { |
|
| 928 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
| 930 | 929 | |
| 931 | 930 | return $response; |
| 932 | 931 | |
| 933 | - } elseif ( ! empty( $response->id ) ) { |
|
| 934 | - 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 ); |
|
| 932 | + } elseif ( ! empty($response->id)) { |
|
| 933 | + 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); |
|
| 935 | 934 | |
| 936 | - $amount = wc_price( $response->amount / 100 ); |
|
| 935 | + $amount = wc_price($response->amount / 100); |
|
| 937 | 936 | |
| 938 | - 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() ) ) { |
|
| 939 | - $amount = wc_price( $response->amount ); |
|
| 937 | + 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())) { |
|
| 938 | + $amount = wc_price($response->amount); |
|
| 940 | 939 | } |
| 941 | 940 | |
| 942 | - if ( isset( $response->balance_transaction ) ) { |
|
| 943 | - $this->update_fees( $order, $response->balance_transaction ); |
|
| 941 | + if (isset($response->balance_transaction)) { |
|
| 942 | + $this->update_fees($order, $response->balance_transaction); |
|
| 944 | 943 | } |
| 945 | 944 | |
| 946 | 945 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
| 947 | - $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' ); |
|
| 946 | + $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'); |
|
| 948 | 947 | |
| 949 | - $order->add_order_note( $refund_message ); |
|
| 950 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) ); |
|
| 948 | + $order->add_order_note($refund_message); |
|
| 949 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message))); |
|
| 951 | 950 | |
| 952 | 951 | return true; |
| 953 | 952 | } |
@@ -962,46 +961,46 @@ discard block |
||
| 962 | 961 | */ |
| 963 | 962 | public function add_payment_method() { |
| 964 | 963 | $error = false; |
| 965 | - $error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' ); |
|
| 964 | + $error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe'); |
|
| 966 | 965 | $source_id = ''; |
| 967 | 966 | |
| 968 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 967 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 969 | 968 | $error = true; |
| 970 | 969 | } |
| 971 | 970 | |
| 972 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 971 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 973 | 972 | |
| 974 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
| 973 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
| 975 | 974 | |
| 976 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
| 975 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
| 977 | 976 | |
| 978 | - if ( isset( $source_object ) ) { |
|
| 979 | - if ( ! empty( $source_object->error ) ) { |
|
| 977 | + if (isset($source_object)) { |
|
| 978 | + if ( ! empty($source_object->error)) { |
|
| 980 | 979 | $error = true; |
| 981 | 980 | } |
| 982 | 981 | |
| 983 | 982 | $source_id = $source_object->id; |
| 984 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
| 985 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
| 983 | + } elseif (isset($_POST['stripe_token'])) { |
|
| 984 | + $source_id = wc_clean($_POST['stripe_token']); |
|
| 986 | 985 | } |
| 987 | 986 | |
| 988 | - $response = $stripe_customer->add_source( $source_id ); |
|
| 987 | + $response = $stripe_customer->add_source($source_id); |
|
| 989 | 988 | |
| 990 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
| 989 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
| 991 | 990 | $error = true; |
| 992 | 991 | } |
| 993 | 992 | |
| 994 | - if ( $error ) { |
|
| 995 | - wc_add_notice( $error_msg, 'error' ); |
|
| 996 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
| 993 | + if ($error) { |
|
| 994 | + wc_add_notice($error_msg, 'error'); |
|
| 995 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
| 997 | 996 | return; |
| 998 | 997 | } |
| 999 | 998 | |
| 1000 | - do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object ); |
|
| 999 | + do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object); |
|
| 1001 | 1000 | |
| 1002 | 1001 | return array( |
| 1003 | 1002 | 'result' => 'success', |
| 1004 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 1003 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 1005 | 1004 | ); |
| 1006 | 1005 | } |
| 1007 | 1006 | |
@@ -1018,10 +1017,10 @@ discard block |
||
| 1018 | 1017 | * Stripe expects Norwegian to only be passed NO. |
| 1019 | 1018 | * But WP has different dialects. |
| 1020 | 1019 | */ |
| 1021 | - if ( 'NO' === substr( $locale, 3, 2 ) ) { |
|
| 1020 | + if ('NO' === substr($locale, 3, 2)) { |
|
| 1022 | 1021 | $locale = 'no'; |
| 1023 | 1022 | } else { |
| 1024 | - $locale = substr( get_locale(), 0, 2 ); |
|
| 1023 | + $locale = substr(get_locale(), 0, 2); |
|
| 1025 | 1024 | } |
| 1026 | 1025 | |
| 1027 | 1026 | return $locale; |
@@ -1035,9 +1034,9 @@ discard block |
||
| 1035 | 1034 | * @param string $idempotency_key |
| 1036 | 1035 | * @param array $request |
| 1037 | 1036 | */ |
| 1038 | - public function change_idempotency_key( $idempotency_key, $request ) { |
|
| 1039 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
| 1040 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
| 1037 | + public function change_idempotency_key($idempotency_key, $request) { |
|
| 1038 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
| 1039 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
| 1041 | 1040 | $count = $this->retry_interval; |
| 1042 | 1041 | |
| 1043 | 1042 | return $request['metadata']['order_id'] . '-' . $count . '-' . $source; |
@@ -1051,8 +1050,8 @@ discard block |
||
| 1051 | 1050 | * @since 4.0.6 |
| 1052 | 1051 | * @param array $headers |
| 1053 | 1052 | */ |
| 1054 | - public function is_original_request( $headers ) { |
|
| 1055 | - if ( $headers['original-request'] === $headers['request-id'] ) { |
|
| 1053 | + public function is_original_request($headers) { |
|
| 1054 | + if ($headers['original-request'] === $headers['request-id']) { |
|
| 1056 | 1055 | return true; |
| 1057 | 1056 | } |
| 1058 | 1057 | |
@@ -1066,27 +1065,27 @@ discard block |
||
| 1066 | 1065 | * @param object $prepared_source The source that is used for the payment. |
| 1067 | 1066 | * @return array The arguments for the request. |
| 1068 | 1067 | */ |
| 1069 | - public function generate_create_intent_request( $order, $prepared_source ) { |
|
| 1068 | + public function generate_create_intent_request($order, $prepared_source) { |
|
| 1070 | 1069 | // The request for a charge contains metadata for the intent. |
| 1071 | - $full_request = $this->generate_payment_request( $order, $prepared_source ); |
|
| 1070 | + $full_request = $this->generate_payment_request($order, $prepared_source); |
|
| 1072 | 1071 | |
| 1073 | 1072 | $request = array( |
| 1074 | 1073 | 'source' => $prepared_source->source, |
| 1075 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ), |
|
| 1076 | - 'currency' => strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ), |
|
| 1074 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()), |
|
| 1075 | + 'currency' => strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()), |
|
| 1077 | 1076 | 'description' => $full_request['description'], |
| 1078 | 1077 | 'metadata' => $full_request['metadata'], |
| 1079 | - 'capture_method' => ( 'true' === $full_request['capture'] ) ? 'automatic' : 'manual', |
|
| 1078 | + 'capture_method' => ('true' === $full_request['capture']) ? 'automatic' : 'manual', |
|
| 1080 | 1079 | 'payment_method_types' => array( |
| 1081 | 1080 | 'card', |
| 1082 | 1081 | ), |
| 1083 | 1082 | ); |
| 1084 | 1083 | |
| 1085 | - if ( $prepared_source->customer ) { |
|
| 1084 | + if ($prepared_source->customer) { |
|
| 1086 | 1085 | $request['customer'] = $prepared_source->customer; |
| 1087 | 1086 | } |
| 1088 | 1087 | |
| 1089 | - if ( isset( $full_request['statement_descriptor'] ) ) { |
|
| 1088 | + if (isset($full_request['statement_descriptor'])) { |
|
| 1090 | 1089 | $request['statement_descriptor'] = $full_request['statement_descriptor']; |
| 1091 | 1090 | } |
| 1092 | 1091 | |
@@ -1098,7 +1097,7 @@ discard block |
||
| 1098 | 1097 | * @param WC_Order $order |
| 1099 | 1098 | * @param object $source |
| 1100 | 1099 | */ |
| 1101 | - return apply_filters( 'wc_stripe_generate_create_intent_request', $request, $order, $prepared_source ); |
|
| 1100 | + return apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source); |
|
| 1102 | 1101 | } |
| 1103 | 1102 | |
| 1104 | 1103 | /** |
@@ -1108,20 +1107,20 @@ discard block |
||
| 1108 | 1107 | * @param object $prepared_source The source that is used for the payment. |
| 1109 | 1108 | * @return object An intent or an error. |
| 1110 | 1109 | */ |
| 1111 | - public function create_intent( $order, $prepared_source ) { |
|
| 1112 | - $request = $this->generate_create_intent_request( $order, $prepared_source ); |
|
| 1110 | + public function create_intent($order, $prepared_source) { |
|
| 1111 | + $request = $this->generate_create_intent_request($order, $prepared_source); |
|
| 1113 | 1112 | |
| 1114 | 1113 | // Create an intent that awaits an action. |
| 1115 | - $intent = WC_Stripe_API::request( $request, 'payment_intents' ); |
|
| 1116 | - if ( ! empty( $intent->error ) ) { |
|
| 1114 | + $intent = WC_Stripe_API::request($request, 'payment_intents'); |
|
| 1115 | + if ( ! empty($intent->error)) { |
|
| 1117 | 1116 | return $intent; |
| 1118 | 1117 | } |
| 1119 | 1118 | |
| 1120 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 1121 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id initiated for order $order_id" ); |
|
| 1119 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 1120 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id initiated for order $order_id"); |
|
| 1122 | 1121 | |
| 1123 | 1122 | // Save the intent ID to the order. |
| 1124 | - $this->save_intent_to_order( $order, $intent ); |
|
| 1123 | + $this->save_intent_to_order($order, $intent); |
|
| 1125 | 1124 | |
| 1126 | 1125 | return $intent; |
| 1127 | 1126 | } |
@@ -1134,27 +1133,27 @@ discard block |
||
| 1134 | 1133 | * @param object $prepared_source Currently selected source. |
| 1135 | 1134 | * @return object An updated intent. |
| 1136 | 1135 | */ |
| 1137 | - public function update_existing_intent( $intent, $order, $prepared_source ) { |
|
| 1136 | + public function update_existing_intent($intent, $order, $prepared_source) { |
|
| 1138 | 1137 | $request = array(); |
| 1139 | 1138 | |
| 1140 | - if ( $prepared_source->source !== $intent->source ) { |
|
| 1139 | + if ($prepared_source->source !== $intent->source) { |
|
| 1141 | 1140 | $request['source'] = $prepared_source->source; |
| 1142 | 1141 | } |
| 1143 | 1142 | |
| 1144 | - $new_amount = WC_Stripe_Helper::get_stripe_amount( $order->get_total() ); |
|
| 1145 | - if ( $intent->amount !== $new_amount ) { |
|
| 1143 | + $new_amount = WC_Stripe_Helper::get_stripe_amount($order->get_total()); |
|
| 1144 | + if ($intent->amount !== $new_amount) { |
|
| 1146 | 1145 | $request['amount'] = $new_amount; |
| 1147 | 1146 | } |
| 1148 | 1147 | |
| 1149 | - if ( $prepared_source->customer && $intent->customer !== $prepared_source->customer ) { |
|
| 1148 | + if ($prepared_source->customer && $intent->customer !== $prepared_source->customer) { |
|
| 1150 | 1149 | $request['customer'] = $prepared_source->customer; |
| 1151 | 1150 | } |
| 1152 | 1151 | |
| 1153 | - if ( empty( $request ) ) { |
|
| 1152 | + if (empty($request)) { |
|
| 1154 | 1153 | return $intent; |
| 1155 | 1154 | } |
| 1156 | 1155 | |
| 1157 | - return WC_Stripe_API::request( $request, "payment_intents/$intent->id" ); |
|
| 1156 | + return WC_Stripe_API::request($request, "payment_intents/$intent->id"); |
|
| 1158 | 1157 | } |
| 1159 | 1158 | |
| 1160 | 1159 | /** |
@@ -1166,8 +1165,8 @@ discard block |
||
| 1166 | 1165 | * @param object $prepared_source The source that is being charged. |
| 1167 | 1166 | * @return object Either an error or the updated intent. |
| 1168 | 1167 | */ |
| 1169 | - public function confirm_intent( $intent, $order, $prepared_source ) { |
|
| 1170 | - if ( 'requires_confirmation' !== $intent->status ) { |
|
| 1168 | + public function confirm_intent($intent, $order, $prepared_source) { |
|
| 1169 | + if ('requires_confirmation' !== $intent->status) { |
|
| 1171 | 1170 | return $intent; |
| 1172 | 1171 | } |
| 1173 | 1172 | |
@@ -1176,18 +1175,18 @@ discard block |
||
| 1176 | 1175 | 'source' => $prepared_source->source, |
| 1177 | 1176 | ); |
| 1178 | 1177 | |
| 1179 | - $confirmed_intent = WC_Stripe_API::request( $confirm_request, "payment_intents/$intent->id/confirm" ); |
|
| 1178 | + $confirmed_intent = WC_Stripe_API::request($confirm_request, "payment_intents/$intent->id/confirm"); |
|
| 1180 | 1179 | |
| 1181 | - if ( ! empty( $confirmed_intent->error ) ) { |
|
| 1180 | + if ( ! empty($confirmed_intent->error)) { |
|
| 1182 | 1181 | return $confirmed_intent; |
| 1183 | 1182 | } |
| 1184 | 1183 | |
| 1185 | 1184 | // Save a note about the status of the intent. |
| 1186 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 1187 | - if ( 'succeeded' === $confirmed_intent->status ) { |
|
| 1188 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" ); |
|
| 1189 | - } elseif ( 'requires_action' === $confirmed_intent->status ) { |
|
| 1190 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id requires authentication for order $order_id" ); |
|
| 1185 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 1186 | + if ('succeeded' === $confirmed_intent->status) { |
|
| 1187 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id"); |
|
| 1188 | + } elseif ('requires_action' === $confirmed_intent->status) { |
|
| 1189 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id requires authentication for order $order_id"); |
|
| 1191 | 1190 | } |
| 1192 | 1191 | |
| 1193 | 1192 | return $confirmed_intent; |
@@ -1200,16 +1199,16 @@ discard block |
||
| 1200 | 1199 | * @param WC_Order $order For to which the source applies. |
| 1201 | 1200 | * @param stdClass $intent Payment intent information. |
| 1202 | 1201 | */ |
| 1203 | - public function save_intent_to_order( $order, $intent ) { |
|
| 1204 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 1202 | + public function save_intent_to_order($order, $intent) { |
|
| 1203 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 1205 | 1204 | |
| 1206 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 1207 | - update_post_meta( $order_id, '_stripe_intent_id', $intent->id ); |
|
| 1205 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 1206 | + update_post_meta($order_id, '_stripe_intent_id', $intent->id); |
|
| 1208 | 1207 | } else { |
| 1209 | - $order->update_meta_data( '_stripe_intent_id', $intent->id ); |
|
| 1208 | + $order->update_meta_data('_stripe_intent_id', $intent->id); |
|
| 1210 | 1209 | } |
| 1211 | 1210 | |
| 1212 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 1211 | + if (is_callable(array($order, 'save'))) { |
|
| 1213 | 1212 | $order->save(); |
| 1214 | 1213 | } |
| 1215 | 1214 | } |
@@ -1221,28 +1220,28 @@ discard block |
||
| 1221 | 1220 | * @param WC_Order $order The order to retrieve an intent for. |
| 1222 | 1221 | * @return obect|bool Either the intent object or `false`. |
| 1223 | 1222 | */ |
| 1224 | - public function get_intent_from_order( $order ) { |
|
| 1225 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 1223 | + public function get_intent_from_order($order) { |
|
| 1224 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 1226 | 1225 | |
| 1227 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 1228 | - $intent_id = get_post_meta( $order_id, '_stripe_intent_id', true ); |
|
| 1226 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 1227 | + $intent_id = get_post_meta($order_id, '_stripe_intent_id', true); |
|
| 1229 | 1228 | } else { |
| 1230 | - $intent_id = $order->get_meta( '_stripe_intent_id' ); |
|
| 1229 | + $intent_id = $order->get_meta('_stripe_intent_id'); |
|
| 1231 | 1230 | } |
| 1232 | 1231 | |
| 1233 | - if ( $intent_id ) { |
|
| 1234 | - return WC_Stripe_API::request( array(), "payment_intents/$intent_id", 'GET' ); |
|
| 1232 | + if ($intent_id) { |
|
| 1233 | + return WC_Stripe_API::request(array(), "payment_intents/$intent_id", 'GET'); |
|
| 1235 | 1234 | } |
| 1236 | 1235 | |
| 1237 | 1236 | // The order doesn't have a payment intent, but it may have a setup intent. |
| 1238 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 1239 | - $intent_id = get_post_meta( $order_id, '_stripe_setup_intent', true ); |
|
| 1237 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 1238 | + $intent_id = get_post_meta($order_id, '_stripe_setup_intent', true); |
|
| 1240 | 1239 | } else { |
| 1241 | - $intent_id = $order->get_meta( '_stripe_setup_intent' ); |
|
| 1240 | + $intent_id = $order->get_meta('_stripe_setup_intent'); |
|
| 1242 | 1241 | } |
| 1243 | 1242 | |
| 1244 | - if ( $intent_id ) { |
|
| 1245 | - return WC_Stripe_API::request( array(), "setup_intents/$intent_id", 'GET' ); |
|
| 1243 | + if ($intent_id) { |
|
| 1244 | + return WC_Stripe_API::request(array(), "setup_intents/$intent_id", 'GET'); |
|
| 1246 | 1245 | } |
| 1247 | 1246 | |
| 1248 | 1247 | return false; |
@@ -1256,18 +1255,18 @@ discard block |
||
| 1256 | 1255 | * @param stdClass $intent The intent that is being processed. |
| 1257 | 1256 | * @return bool A flag that indicates whether the order is already locked. |
| 1258 | 1257 | */ |
| 1259 | - public function lock_order_payment( $order, $intent ) { |
|
| 1260 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 1258 | + public function lock_order_payment($order, $intent) { |
|
| 1259 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 1261 | 1260 | $transient_name = 'wc_stripe_processing_intent_' . $order_id; |
| 1262 | - $processing = get_transient( $transient_name ); |
|
| 1261 | + $processing = get_transient($transient_name); |
|
| 1263 | 1262 | |
| 1264 | 1263 | // Block the process if the same intent is already being handled. |
| 1265 | - if ( $processing === $intent->id ) { |
|
| 1264 | + if ($processing === $intent->id) { |
|
| 1266 | 1265 | return true; |
| 1267 | 1266 | } |
| 1268 | 1267 | |
| 1269 | 1268 | // Save the new intent as a transient, eventually overwriting another one. |
| 1270 | - set_transient( $transient_name, $intent->id, 5 * MINUTE_IN_SECONDS ); |
|
| 1269 | + set_transient($transient_name, $intent->id, 5 * MINUTE_IN_SECONDS); |
|
| 1271 | 1270 | |
| 1272 | 1271 | return false; |
| 1273 | 1272 | } |
@@ -1278,9 +1277,9 @@ discard block |
||
| 1278 | 1277 | * @since 4.2 |
| 1279 | 1278 | * @param WC_Order $order The order that is being unlocked. |
| 1280 | 1279 | */ |
| 1281 | - public function unlock_order_payment( $order ) { |
|
| 1282 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 1283 | - delete_transient( 'wc_stripe_processing_intent_' . $order_id ); |
|
| 1280 | + public function unlock_order_payment($order) { |
|
| 1281 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 1282 | + delete_transient('wc_stripe_processing_intent_' . $order_id); |
|
| 1284 | 1283 | } |
| 1285 | 1284 | |
| 1286 | 1285 | /** |
@@ -1290,9 +1289,9 @@ discard block |
||
| 1290 | 1289 | * @param object $response The response from Stripe. |
| 1291 | 1290 | * @return boolean Whether or not it's a 'authentication_required' error |
| 1292 | 1291 | */ |
| 1293 | - public function is_authentication_required_for_payment( $response ) { |
|
| 1294 | - return ( ! empty( $response->error ) && 'authentication_required' === $response->error->code ) |
|
| 1295 | - || ( ! empty( $response->last_payment_error ) && 'authentication_required' === $response->last_payment_error->code ); |
|
| 1292 | + public function is_authentication_required_for_payment($response) { |
|
| 1293 | + return ( ! empty($response->error) && 'authentication_required' === $response->error->code) |
|
| 1294 | + || ( ! empty($response->last_payment_error) && 'authentication_required' === $response->last_payment_error->code); |
|
| 1296 | 1295 | } |
| 1297 | 1296 | |
| 1298 | 1297 | /** |
@@ -1302,21 +1301,21 @@ discard block |
||
| 1302 | 1301 | * @param object $prepared_source The source, entered/chosen by the customer. |
| 1303 | 1302 | * @return string The client secret of the intent, used for confirmation in JS. |
| 1304 | 1303 | */ |
| 1305 | - public function setup_intent( $order, $prepared_source ) { |
|
| 1306 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 1307 | - $setup_intent = WC_Stripe_API::request( array( |
|
| 1304 | + public function setup_intent($order, $prepared_source) { |
|
| 1305 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 1306 | + $setup_intent = WC_Stripe_API::request(array( |
|
| 1308 | 1307 | 'payment_method' => $prepared_source->source, |
| 1309 | 1308 | 'customer' => $prepared_source->customer, |
| 1310 | 1309 | 'confirm' => 'true', |
| 1311 | - ), 'setup_intents' ); |
|
| 1310 | + ), 'setup_intents'); |
|
| 1312 | 1311 | |
| 1313 | - if ( is_wp_error( $setup_intent ) ) { |
|
| 1314 | - WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) ); |
|
| 1315 | - } elseif ( 'requires_action' === $setup_intent->status ) { |
|
| 1316 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 1317 | - update_post_meta( $order_id, '_stripe_setup_intent', $setup_intent->id ); |
|
| 1312 | + if (is_wp_error($setup_intent)) { |
|
| 1313 | + WC_Stripe_Logger::log("Unable to create SetupIntent for Order #$order_id: " . print_r($setup_intent, true)); |
|
| 1314 | + } elseif ('requires_action' === $setup_intent->status) { |
|
| 1315 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 1316 | + update_post_meta($order_id, '_stripe_setup_intent', $setup_intent->id); |
|
| 1318 | 1317 | } else { |
| 1319 | - $order->update_meta_data( '_stripe_setup_intent', $setup_intent->id ); |
|
| 1318 | + $order->update_meta_data('_stripe_setup_intent', $setup_intent->id); |
|
| 1320 | 1319 | $order->save(); |
| 1321 | 1320 | } |
| 1322 | 1321 | |
@@ -1332,12 +1331,12 @@ discard block |
||
| 1332 | 1331 | * @param float $amount The amount to charge. If not specified, it will be read from the order. |
| 1333 | 1332 | * @return object An intent or an error. |
| 1334 | 1333 | */ |
| 1335 | - public function create_and_confirm_intent_for_off_session( $order, $prepared_source, $amount = NULL ) { |
|
| 1334 | + public function create_and_confirm_intent_for_off_session($order, $prepared_source, $amount = NULL) { |
|
| 1336 | 1335 | // The request for a charge contains metadata for the intent. |
| 1337 | - $full_request = $this->generate_payment_request( $order, $prepared_source ); |
|
| 1336 | + $full_request = $this->generate_payment_request($order, $prepared_source); |
|
| 1338 | 1337 | |
| 1339 | 1338 | $request = array( |
| 1340 | - 'amount' => $amount ? WC_Stripe_Helper::get_stripe_amount( $amount, $full_request['currency'] ) : $full_request['amount'], |
|
| 1339 | + 'amount' => $amount ? WC_Stripe_Helper::get_stripe_amount($amount, $full_request['currency']) : $full_request['amount'], |
|
| 1341 | 1340 | 'currency' => $full_request['currency'], |
| 1342 | 1341 | 'description' => $full_request['description'], |
| 1343 | 1342 | 'metadata' => $full_request['metadata'], |
@@ -1349,38 +1348,38 @@ discard block |
||
| 1349 | 1348 | 'confirmation_method' => 'automatic', |
| 1350 | 1349 | ); |
| 1351 | 1350 | |
| 1352 | - if ( isset( $full_request['statement_descriptor'] ) ) { |
|
| 1351 | + if (isset($full_request['statement_descriptor'])) { |
|
| 1353 | 1352 | $request['statement_descriptor'] = $full_request['statement_descriptor']; |
| 1354 | 1353 | } |
| 1355 | 1354 | |
| 1356 | - if ( isset( $full_request['customer'] ) ) { |
|
| 1355 | + if (isset($full_request['customer'])) { |
|
| 1357 | 1356 | $request['customer'] = $full_request['customer']; |
| 1358 | 1357 | } |
| 1359 | 1358 | |
| 1360 | - if ( isset( $full_request['source'] ) ) { |
|
| 1359 | + if (isset($full_request['source'])) { |
|
| 1361 | 1360 | $request['source'] = $full_request['source']; |
| 1362 | 1361 | } |
| 1363 | 1362 | |
| 1364 | - $intent = WC_Stripe_API::request( $request, 'payment_intents' ); |
|
| 1365 | - $is_authentication_required = $this->is_authentication_required_for_payment( $intent ); |
|
| 1363 | + $intent = WC_Stripe_API::request($request, 'payment_intents'); |
|
| 1364 | + $is_authentication_required = $this->is_authentication_required_for_payment($intent); |
|
| 1366 | 1365 | |
| 1367 | - if ( ! empty( $intent->error ) && ! $is_authentication_required ) { |
|
| 1366 | + if ( ! empty($intent->error) && ! $is_authentication_required) { |
|
| 1368 | 1367 | return $intent; |
| 1369 | 1368 | } |
| 1370 | 1369 | |
| 1371 | - $intent_id = ( ! empty( $intent->error ) |
|
| 1370 | + $intent_id = ( ! empty($intent->error) |
|
| 1372 | 1371 | ? $intent->error->payment_intent->id |
| 1373 | 1372 | : $intent->id |
| 1374 | 1373 | ); |
| 1375 | - $payment_intent = ( ! empty( $intent->error ) |
|
| 1374 | + $payment_intent = ( ! empty($intent->error) |
|
| 1376 | 1375 | ? $intent->error->payment_intent |
| 1377 | 1376 | : $intent |
| 1378 | 1377 | ); |
| 1379 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 1380 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent_id initiated for order $order_id" ); |
|
| 1378 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 1379 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent_id initiated for order $order_id"); |
|
| 1381 | 1380 | |
| 1382 | 1381 | // Save the intent ID to the order. |
| 1383 | - $this->save_intent_to_order( $order, $payment_intent ); |
|
| 1382 | + $this->save_intent_to_order($order, $payment_intent); |
|
| 1384 | 1383 | |
| 1385 | 1384 | return $intent; |
| 1386 | 1385 | } |