@@ -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,8 +51,8 @@ discard block |
||
| 51 | 51 | * Set Stripe customer ID. |
| 52 | 52 | * @param [type] $id [description] |
| 53 | 53 | */ |
| 54 | - public function set_id( $id ) { |
|
| 55 | - $this->id = wc_clean( $id ); |
|
| 54 | + public function set_id($id) { |
|
| 55 | + $this->id = wc_clean($id); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
| 60 | 60 | * @return int |
| 61 | 61 | */ |
| 62 | 62 | public function get_user_id() { |
| 63 | - return absint( $this->user_id ); |
|
| 63 | + return absint($this->user_id); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Set User ID used by WordPress. |
| 68 | 68 | * @param int $user_id |
| 69 | 69 | */ |
| 70 | - public function set_user_id( $user_id ) { |
|
| 71 | - $this->user_id = absint( $user_id ); |
|
| 70 | + public function set_user_id($user_id) { |
|
| 71 | + $this->user_id = absint($user_id); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | * @return WP_User |
| 77 | 77 | */ |
| 78 | 78 | protected function get_user() { |
| 79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
| 79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * Store data from the Stripe API about this customer |
| 84 | 84 | */ |
| 85 | - public function set_customer_data( $data ) { |
|
| 85 | + public function set_customer_data($data) { |
|
| 86 | 86 | $this->customer_data = $data; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | * Get data from the Stripe API about this customer |
| 91 | 91 | */ |
| 92 | 92 | public function get_customer_data() { |
| 93 | - $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ); |
|
| 93 | + $this->customer_data = get_transient('stripe_customer_' . $this->get_id()); |
|
| 94 | 94 | |
| 95 | - if ( empty( $this->customer_data ) && $this->get_id() && false === $this->customer_data ) { |
|
| 96 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() ); |
|
| 95 | + if (empty($this->customer_data) && $this->get_id() && false === $this->customer_data) { |
|
| 96 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id()); |
|
| 97 | 97 | |
| 98 | - if ( empty( $response->error ) ) { |
|
| 99 | - $this->set_customer_data( $response ); |
|
| 100 | - set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 ); |
|
| 98 | + if (empty($response->error)) { |
|
| 99 | + $this->set_customer_data($response); |
|
| 100 | + set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $data = $this->get_customer_data(); |
| 113 | 113 | $source = ''; |
| 114 | 114 | |
| 115 | - if ( $data ) { |
|
| 115 | + if ($data) { |
|
| 116 | 116 | $source = $data->default_source; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -124,13 +124,13 @@ discard block |
||
| 124 | 124 | * @param array $args |
| 125 | 125 | * @return WP_Error|int |
| 126 | 126 | */ |
| 127 | - public function create_customer( $args = array() ) { |
|
| 128 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
| 127 | + public function create_customer($args = array()) { |
|
| 128 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
| 129 | 129 | $user = $this->get_user(); |
| 130 | 130 | |
| 131 | - if ( $user ) { |
|
| 132 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
| 133 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
| 131 | + if ($user) { |
|
| 132 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
| 133 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
| 134 | 134 | |
| 135 | 135 | $defaults = array( |
| 136 | 136 | 'email' => $user->user_email, |
@@ -145,24 +145,24 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $metadata = array(); |
| 147 | 147 | |
| 148 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
| 148 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
| 149 | 149 | |
| 150 | - $args = wp_parse_args( $args, $defaults ); |
|
| 151 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
| 150 | + $args = wp_parse_args($args, $defaults); |
|
| 151 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
| 152 | 152 | |
| 153 | - if ( ! empty( $response->error ) ) { |
|
| 154 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 153 | + if ( ! empty($response->error)) { |
|
| 154 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - $this->set_id( $response->id ); |
|
| 157 | + $this->set_id($response->id); |
|
| 158 | 158 | $this->clear_cache(); |
| 159 | - $this->set_customer_data( $response ); |
|
| 159 | + $this->set_customer_data($response); |
|
| 160 | 160 | |
| 161 | - if ( $this->get_user_id() ) { |
|
| 162 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
| 161 | + if ($this->get_user_id()) { |
|
| 162 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
| 165 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
| 166 | 166 | |
| 167 | 167 | return $response->id; |
| 168 | 168 | } |
@@ -173,72 +173,72 @@ discard block |
||
| 173 | 173 | * @param bool $retry |
| 174 | 174 | * @return WP_Error|int |
| 175 | 175 | */ |
| 176 | - public function add_source( $source_id, $retry = true ) { |
|
| 177 | - if ( ! $this->get_id() ) { |
|
| 178 | - $this->set_id( $this->create_customer() ); |
|
| 176 | + public function add_source($source_id, $retry = true) { |
|
| 177 | + if ( ! $this->get_id()) { |
|
| 178 | + $this->set_id($this->create_customer()); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - $response = WC_Stripe_API::request( array( |
|
| 181 | + $response = WC_Stripe_API::request(array( |
|
| 182 | 182 | 'source' => $source_id, |
| 183 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
| 183 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
| 184 | 184 | |
| 185 | - if ( ! empty( $response->error ) ) { |
|
| 185 | + if ( ! empty($response->error)) { |
|
| 186 | 186 | // It is possible the WC user once was linked to a customer on Stripe |
| 187 | 187 | // but no longer exists. Instead of failing, lets try to create a |
| 188 | 188 | // new customer. |
| 189 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
| 190 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
| 189 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
| 190 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
| 191 | 191 | $this->create_customer(); |
| 192 | - return $this->add_source( $source_id, false ); |
|
| 192 | + return $this->add_source($source_id, false); |
|
| 193 | 193 | } else { |
| 194 | 194 | return $response; |
| 195 | 195 | } |
| 196 | - } elseif ( empty( $response->id ) ) { |
|
| 197 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
| 196 | + } elseif (empty($response->id)) { |
|
| 197 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Add token to WooCommerce. |
| 201 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 202 | - if ( ! empty( $response->type ) ) { |
|
| 203 | - switch ( $response->type ) { |
|
| 201 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
| 202 | + if ( ! empty($response->type)) { |
|
| 203 | + switch ($response->type) { |
|
| 204 | 204 | case 'alipay': |
| 205 | 205 | break; |
| 206 | 206 | case 'sepa_debit': |
| 207 | 207 | $wc_token = new WC_Payment_Token_SEPA(); |
| 208 | - $wc_token->set_token( $response->id ); |
|
| 209 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
| 210 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
| 208 | + $wc_token->set_token($response->id); |
|
| 209 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
| 210 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
| 211 | 211 | break; |
| 212 | 212 | default: |
| 213 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
| 213 | + if ('source' === $response->object && 'card' === $response->type) { |
|
| 214 | 214 | $wc_token = new WC_Payment_Token_CC(); |
| 215 | - $wc_token->set_token( $response->id ); |
|
| 216 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 217 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
| 218 | - $wc_token->set_last4( $response->card->last4 ); |
|
| 219 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
| 220 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
| 215 | + $wc_token->set_token($response->id); |
|
| 216 | + $wc_token->set_gateway_id('stripe'); |
|
| 217 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
| 218 | + $wc_token->set_last4($response->card->last4); |
|
| 219 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
| 220 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
| 221 | 221 | } |
| 222 | 222 | break; |
| 223 | 223 | } |
| 224 | 224 | } else { |
| 225 | 225 | // Legacy. |
| 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->brand ) ); |
|
| 230 | - $wc_token->set_last4( $response->last4 ); |
|
| 231 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
| 232 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
| 227 | + $wc_token->set_token($response->id); |
|
| 228 | + $wc_token->set_gateway_id('stripe'); |
|
| 229 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
| 230 | + $wc_token->set_last4($response->last4); |
|
| 231 | + $wc_token->set_expiry_month($response->exp_month); |
|
| 232 | + $wc_token->set_expiry_year($response->exp_year); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
| 235 | + $wc_token->set_user_id($this->get_user_id()); |
|
| 236 | 236 | $wc_token->save(); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $this->clear_cache(); |
| 240 | 240 | |
| 241 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
| 241 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
| 242 | 242 | |
| 243 | 243 | return $response->id; |
| 244 | 244 | } |
@@ -250,46 +250,46 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | public function get_sources() { |
| 253 | - if ( ! $this->get_id() ) { |
|
| 253 | + if ( ! $this->get_id()) { |
|
| 254 | 254 | return array(); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 257 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
| 258 | 258 | |
| 259 | 259 | //if ( false === $sources ) { |
| 260 | - $response = WC_Stripe_API::request( array( |
|
| 260 | + $response = WC_Stripe_API::request(array( |
|
| 261 | 261 | 'limit' => 100, |
| 262 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
| 262 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
| 263 | 263 | |
| 264 | - if ( ! empty( $response->error ) ) { |
|
| 264 | + if ( ! empty($response->error)) { |
|
| 265 | 265 | return array(); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - if ( is_array( $response->data ) ) { |
|
| 268 | + if (is_array($response->data)) { |
|
| 269 | 269 | $sources = $response->data; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - set_transient( 'stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24 ); |
|
| 272 | + set_transient('stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24); |
|
| 273 | 273 | //} |
| 274 | 274 | |
| 275 | - return empty( $sources ) ? array() : $sources; |
|
| 275 | + return empty($sources) ? array() : $sources; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
| 279 | 279 | * Delete a source from stripe. |
| 280 | 280 | * @param string $source_id |
| 281 | 281 | */ |
| 282 | - public function delete_source( $source_id ) { |
|
| 283 | - if ( ! $this->get_id() ) { |
|
| 282 | + public function delete_source($source_id) { |
|
| 283 | + if ( ! $this->get_id()) { |
|
| 284 | 284 | return false; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
| 287 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
| 288 | 288 | |
| 289 | 289 | $this->clear_cache(); |
| 290 | 290 | |
| 291 | - if ( empty( $response->error ) ) { |
|
| 292 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
| 291 | + if (empty($response->error)) { |
|
| 292 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
| 293 | 293 | |
| 294 | 294 | return true; |
| 295 | 295 | } |
@@ -301,15 +301,15 @@ discard block |
||
| 301 | 301 | * Set default source in Stripe |
| 302 | 302 | * @param string $source_id |
| 303 | 303 | */ |
| 304 | - public function set_default_source( $source_id ) { |
|
| 305 | - $response = WC_Stripe_API::request( array( |
|
| 306 | - 'default_source' => sanitize_text_field( $source_id ), |
|
| 307 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
| 304 | + public function set_default_source($source_id) { |
|
| 305 | + $response = WC_Stripe_API::request(array( |
|
| 306 | + 'default_source' => sanitize_text_field($source_id), |
|
| 307 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
| 308 | 308 | |
| 309 | 309 | $this->clear_cache(); |
| 310 | 310 | |
| 311 | - if ( empty( $response->error ) ) { |
|
| 312 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
| 311 | + if (empty($response->error)) { |
|
| 312 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
| 313 | 313 | |
| 314 | 314 | return true; |
| 315 | 315 | } |
@@ -321,8 +321,8 @@ discard block |
||
| 321 | 321 | * Deletes caches for this users cards. |
| 322 | 322 | */ |
| 323 | 323 | public function clear_cache() { |
| 324 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 325 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
| 324 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
| 325 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
| 326 | 326 | $this->customer_data = array(); |
| 327 | 327 | } |
| 328 | 328 | } |
@@ -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,24 +15,24 @@ 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 ); |
|
| 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 | 23 | |
| 24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 26 | 26 | |
| 27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
| 28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
| 34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @since 4.0.0 |
| 44 | 44 | * @version 4.0.0 |
| 45 | 45 | */ |
| 46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param int $order_id |
| 57 | 57 | * @return boolean |
| 58 | 58 | */ |
| 59 | - public function has_subscription( $order_id ) { |
|
| 60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 59 | + public function has_subscription($order_id) { |
|
| 60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @param int $order_id |
| 66 | 66 | * @return boolean |
| 67 | 67 | */ |
| 68 | - protected function is_pre_order( $order_id ) { |
|
| 69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
| 68 | + protected function is_pre_order($order_id) { |
|
| 69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * @param int $order_id |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 78 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 78 | + if ($this->has_subscription($order_id)) { |
|
| 79 | 79 | // Regular payment with force customer enabled |
| 80 | - return parent::process_payment( $order_id, true, true ); |
|
| 81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
| 82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
| 80 | + return parent::process_payment($order_id, true, true); |
|
| 81 | + } elseif ($this->is_pre_order($order_id)) { |
|
| 82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
| 83 | 83 | } else { |
| 84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | * @param array $metadata |
| 93 | 93 | * @param object $order |
| 94 | 94 | */ |
| 95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
| 96 | - if ( ! $this->has_subscription( $order->get_id() ) ) { |
|
| 95 | + public function add_subscription_meta_data($metadata, $order) { |
|
| 96 | + if ( ! $this->has_subscription($order->get_id())) { |
|
| 97 | 97 | return $metadata; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $metadata += array( |
| 101 | 101 | 'payment_type' => 'recurring', |
| 102 | - 'site_url' => esc_url( get_site_url() ), |
|
| 102 | + 'site_url' => esc_url(get_site_url()), |
|
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
| 109 | 109 | * @since 3.1.0 |
| 110 | 110 | * @version 4.0.0 |
| 111 | 111 | */ |
| 112 | - public function save_source( $order, $source ) { |
|
| 113 | - parent::save_source( $order, $source ); |
|
| 112 | + public function save_source($order, $source) { |
|
| 113 | + parent::save_source($order, $source); |
|
| 114 | 114 | |
| 115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 116 | 116 | |
| 117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order |
| 118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 122 | 122 | } else { |
| 123 | 123 | $subscriptions = array(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach ( $subscriptions as $subscription ) { |
|
| 126 | + foreach ($subscriptions as $subscription) { |
|
| 127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
| 128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -137,37 +137,37 @@ discard block |
||
| 137 | 137 | * @param string $stripe_token (default: '') |
| 138 | 138 | * @param bool initial_payment |
| 139 | 139 | */ |
| 140 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
| 141 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 140 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
| 141 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 142 | 142 | /* translators: minimum amount */ |
| 143 | - 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 ) ) ); |
|
| 143 | + 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))); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | $customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 147 | 147 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 148 | 148 | |
| 149 | 149 | // Get source from order |
| 150 | - $prepared_source = $this->prepare_order_source( $order ); |
|
| 150 | + $prepared_source = $this->prepare_order_source($order); |
|
| 151 | 151 | |
| 152 | 152 | // Or fail :( |
| 153 | - if ( ! $prepared_source->customer ) { |
|
| 154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 153 | + if ( ! $prepared_source->customer) { |
|
| 154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 158 | 158 | |
| 159 | 159 | // Make the request |
| 160 | - $request = $this->generate_payment_request( $order, $prepared_source ); |
|
| 160 | + $request = $this->generate_payment_request($order, $prepared_source); |
|
| 161 | 161 | $request['capture'] = 'true'; |
| 162 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 163 | - $response = WC_Stripe_API::request( $request ); |
|
| 162 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 163 | + $response = WC_Stripe_API::request($request); |
|
| 164 | 164 | |
| 165 | 165 | // Process valid response |
| 166 | - if ( ! empty( $response->error ) ) { |
|
| 166 | + if ( ! empty($response->error)) { |
|
| 167 | 167 | return $response; // Default catch all errors. |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - $this->process_response( $response, $order ); |
|
| 170 | + $this->process_response($response, $order); |
|
| 171 | 171 | |
| 172 | 172 | return $response; |
| 173 | 173 | } |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 177 | 177 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 178 | 178 | */ |
| 179 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 180 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 181 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 179 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 180 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 181 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 182 | 182 | // For BW compat will remove in future |
| 183 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 184 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 183 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 184 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 189 | 189 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 190 | 190 | */ |
| 191 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 192 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
| 193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
| 191 | + public function delete_renewal_meta($renewal_order) { |
|
| 192 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
| 193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
| 194 | 194 | return $renewal_order; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,17 +200,17 @@ discard block |
||
| 200 | 200 | * @param $amount_to_charge float The amount to charge. |
| 201 | 201 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 202 | 202 | */ |
| 203 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 204 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
| 203 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 204 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
| 205 | 205 | |
| 206 | - if ( is_wp_error( $response ) ) { |
|
| 206 | + if (is_wp_error($response)) { |
|
| 207 | 207 | /* translators: error message */ |
| 208 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 208 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( ! empty( $response->error ) ) { |
|
| 211 | + if ( ! empty($response->error)) { |
|
| 212 | 212 | /* translators: error message */ |
| 213 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 213 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
@@ -218,20 +218,20 @@ discard block |
||
| 218 | 218 | * Remove order meta |
| 219 | 219 | * @param object $order |
| 220 | 220 | */ |
| 221 | - public function remove_order_source_before_retry( $order ) { |
|
| 221 | + public function remove_order_source_before_retry($order) { |
|
| 222 | 222 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 223 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 223 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 224 | 224 | // For BW compat will remove in the future. |
| 225 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 225 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Remove order meta |
| 230 | 230 | * @param object $order |
| 231 | 231 | */ |
| 232 | - public function remove_order_customer_before_retry( $order ) { |
|
| 232 | + public function remove_order_customer_before_retry($order) { |
|
| 233 | 233 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 234 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 234 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 244 | 244 | * @return void |
| 245 | 245 | */ |
| 246 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 247 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 248 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 249 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 246 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 247 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 248 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 249 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 250 | 250 | |
| 251 | 251 | } else { |
| 252 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 253 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 252 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 253 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -263,21 +263,21 @@ discard block |
||
| 263 | 263 | * @param WC_Subscription $subscription An instance of a subscription object |
| 264 | 264 | * @return array |
| 265 | 265 | */ |
| 266 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 267 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 266 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 267 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 268 | 268 | |
| 269 | 269 | // For BW compat will remove in future. |
| 270 | - if ( empty( $source_id ) ) { |
|
| 271 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 270 | + if (empty($source_id)) { |
|
| 271 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 272 | 272 | |
| 273 | 273 | // Take this opportunity to update the key name. |
| 274 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
| 274 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $payment_meta[ $this->id ] = array( |
|
| 277 | + $payment_meta[$this->id] = array( |
|
| 278 | 278 | 'post_meta' => array( |
| 279 | 279 | '_stripe_customer_id' => array( |
| 280 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 280 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 281 | 281 | 'label' => 'Stripe Customer ID', |
| 282 | 282 | ), |
| 283 | 283 | '_stripe_source_id' => array( |
@@ -299,17 +299,17 @@ discard block |
||
| 299 | 299 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 300 | 300 | * @return array |
| 301 | 301 | */ |
| 302 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 303 | - if ( $this->id === $payment_method_id ) { |
|
| 302 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 303 | + if ($this->id === $payment_method_id) { |
|
| 304 | 304 | |
| 305 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 306 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
| 307 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 308 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
| 305 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 306 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
| 307 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 308 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) { |
|
| 312 | - throw new Exception( 'A "_stripe_source_id" value is required.' ); |
|
| 311 | + if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) { |
|
| 312 | + throw new Exception('A "_stripe_source_id" value is required.'); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | } |
@@ -322,91 +322,91 @@ discard block |
||
| 322 | 322 | * @param WC_Subscription $subscription the subscription details |
| 323 | 323 | * @return string the subscription payment method |
| 324 | 324 | */ |
| 325 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 325 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 326 | 326 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
| 327 | 327 | |
| 328 | 328 | // bail for other payment methods |
| 329 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 329 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 330 | 330 | return $payment_method_to_display; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 333 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 334 | 334 | |
| 335 | 335 | // For BW compat will remove in future. |
| 336 | - if ( empty( $stripe_source_id ) ) { |
|
| 337 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 336 | + if (empty($stripe_source_id)) { |
|
| 337 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 338 | 338 | |
| 339 | 339 | // Take this opportunity to update the key name. |
| 340 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 340 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | $stripe_customer = new WC_Stripe_Customer(); |
| 344 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 344 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 345 | 345 | |
| 346 | 346 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 347 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 347 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 348 | 348 | $user_id = $customer_user; |
| 349 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 350 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 349 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 350 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 351 | 351 | |
| 352 | 352 | // For BW compat will remove in future. |
| 353 | - if ( empty( $stripe_source_id ) ) { |
|
| 354 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 353 | + if (empty($stripe_source_id)) { |
|
| 354 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 355 | 355 | |
| 356 | 356 | // Take this opportunity to update the key name. |
| 357 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 357 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 362 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 363 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 364 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 362 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 363 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 364 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 365 | 365 | |
| 366 | 366 | // For BW compat will remove in future. |
| 367 | - if ( empty( $stripe_source_id ) ) { |
|
| 368 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 367 | + if (empty($stripe_source_id)) { |
|
| 368 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 369 | 369 | |
| 370 | 370 | // Take this opportunity to update the key name. |
| 371 | - WC_Stripe_Helper::is_pre_30() ? 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 ); |
|
| 371 | + WC_Stripe_Helper::is_pre_30() ? 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); |
|
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 375 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 376 | 376 | $sources = $stripe_customer->get_sources(); |
| 377 | 377 | |
| 378 | - if ( $sources ) { |
|
| 378 | + if ($sources) { |
|
| 379 | 379 | $found_source = false; |
| 380 | - foreach ( $sources as $source ) { |
|
| 381 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 380 | + foreach ($sources as $source) { |
|
| 381 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 382 | 382 | $card = $source->card; |
| 383 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
| 383 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
| 384 | 384 | $card = $source; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - if ( $source->id === $stripe_source_id ) { |
|
| 387 | + if ($source->id === $stripe_source_id) { |
|
| 388 | 388 | $found_source = true; |
| 389 | 389 | |
| 390 | - if ( $card ) { |
|
| 390 | + if ($card) { |
|
| 391 | 391 | /* translators: 1) card brand 2) last 4 digits */ |
| 392 | - $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 ); |
|
| 392 | + $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); |
|
| 393 | 393 | } else { |
| 394 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 394 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 395 | 395 | } |
| 396 | 396 | break; |
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - if ( ! $found_source ) { |
|
| 401 | - if ( 'card' === $sources[0]->type ) { |
|
| 400 | + if ( ! $found_source) { |
|
| 401 | + if ('card' === $sources[0]->type) { |
|
| 402 | 402 | $card = $sources[0]->card; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - if ( $card ) { |
|
| 405 | + if ($card) { |
|
| 406 | 406 | /* translators: 1) card brand 2) last 4 digits */ |
| 407 | - $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 ); |
|
| 407 | + $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); |
|
| 408 | 408 | } else { |
| 409 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 409 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | } |
@@ -419,43 +419,43 @@ discard block |
||
| 419 | 419 | * @param int $order_id |
| 420 | 420 | * @return array |
| 421 | 421 | */ |
| 422 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
| 423 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 422 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
| 423 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
| 424 | 424 | try { |
| 425 | - $order = wc_get_order( $order_id ); |
|
| 425 | + $order = wc_get_order($order_id); |
|
| 426 | 426 | |
| 427 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 427 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 428 | 428 | /* translators: minimum amount */ |
| 429 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 429 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - $source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), true ); |
|
| 432 | + $source = $this->prepare_source($this->create_source_object(), get_current_user_id(), true); |
|
| 433 | 433 | |
| 434 | 434 | // We need a source on file to continue. |
| 435 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 436 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 435 | + if (empty($source->customer) || empty($source->source)) { |
|
| 436 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // Store source to order meta |
| 440 | - $this->save_source( $order, $source ); |
|
| 440 | + $this->save_source($order, $source); |
|
| 441 | 441 | |
| 442 | 442 | // Remove cart |
| 443 | 443 | WC()->cart->empty_cart(); |
| 444 | 444 | |
| 445 | 445 | // Is pre ordered! |
| 446 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 446 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 447 | 447 | |
| 448 | 448 | // Return thank you page redirect |
| 449 | 449 | return array( |
| 450 | 450 | 'result' => 'success', |
| 451 | - 'redirect' => $this->get_return_url( $order ), |
|
| 451 | + 'redirect' => $this->get_return_url($order), |
|
| 452 | 452 | ); |
| 453 | - } catch ( Exception $e ) { |
|
| 454 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 453 | + } catch (Exception $e) { |
|
| 454 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 455 | 455 | return; |
| 456 | 456 | } |
| 457 | 457 | } else { |
| 458 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 458 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | * @param WC_Order $order |
| 465 | 465 | * @return void |
| 466 | 466 | */ |
| 467 | - public function process_pre_order_release_payment( $order ) { |
|
| 467 | + public function process_pre_order_release_payment($order) { |
|
| 468 | 468 | try { |
| 469 | 469 | // Define some callbacks if the first attempt fails. |
| 470 | 470 | $retry_callbacks = array( |
@@ -472,33 +472,33 @@ discard block |
||
| 472 | 472 | 'remove_order_customer_before_retry', |
| 473 | 473 | ); |
| 474 | 474 | |
| 475 | - while ( 1 ) { |
|
| 476 | - $source = $this->prepare_order_source( $order ); |
|
| 477 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 475 | + while (1) { |
|
| 476 | + $source = $this->prepare_order_source($order); |
|
| 477 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 478 | 478 | |
| 479 | - if ( ! empty( $response->error ) ) { |
|
| 480 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 481 | - throw new Exception( $response->error->message ); |
|
| 479 | + if ( ! empty($response->error)) { |
|
| 480 | + if (0 === sizeof($retry_callbacks)) { |
|
| 481 | + throw new Exception($response->error->message); |
|
| 482 | 482 | } else { |
| 483 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 484 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 483 | + $retry_callback = array_shift($retry_callbacks); |
|
| 484 | + call_user_func(array($this, $retry_callback), $order); |
|
| 485 | 485 | } |
| 486 | 486 | } else { |
| 487 | 487 | // Successful |
| 488 | - $this->process_response( $response, $order ); |
|
| 488 | + $this->process_response($response, $order); |
|
| 489 | 489 | break; |
| 490 | 490 | } |
| 491 | 491 | } |
| 492 | - } catch ( Exception $e ) { |
|
| 492 | + } catch (Exception $e) { |
|
| 493 | 493 | /* translators: error message */ |
| 494 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 494 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 495 | 495 | |
| 496 | 496 | // Mark order as failed if not already set, |
| 497 | 497 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 498 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 499 | - $order->update_status( 'failed', $order_note ); |
|
| 498 | + if ( ! $order->has_status('failed')) { |
|
| 499 | + $order->update_status('failed', $order_note); |
|
| 500 | 500 | } else { |
| 501 | - $order->add_order_note( $order_note ); |
|
| 501 | + $order->add_order_note($order_note); |
|
| 502 | 502 | } |
| 503 | 503 | } |
| 504 | 504 | } |