From 7bec9175db38e51e1f589eef3180d9aab8ffc503 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 13 May 2025 10:03:41 -0300 Subject: [PATCH 1/6] Introducing constant class for order metas --- includes/class-wc-stripe-order.php | 913 ------------------ .../constants/class-wc-stripe-order-metas.php | 155 +++ 2 files changed, 155 insertions(+), 913 deletions(-) delete mode 100644 includes/class-wc-stripe-order.php create mode 100644 includes/constants/class-wc-stripe-order-metas.php diff --git a/includes/class-wc-stripe-order.php b/includes/class-wc-stripe-order.php deleted file mode 100644 index 1766afb121..0000000000 --- a/includes/class-wc-stripe-order.php +++ /dev/null @@ -1,913 +0,0 @@ -get_billing_first_name(); - $billing_last_name = $this->get_billing_last_name(); - - $details = []; - - $name = $billing_first_name . ' ' . $billing_last_name; - $email = $this->get_billing_email(); - $phone = $this->get_billing_phone(); - - if ( ! empty( $phone ) ) { - $details['phone'] = $phone; - } - - if ( ! empty( $name ) ) { - $details['name'] = $name; - } - - if ( ! empty( $email ) ) { - $details['email'] = $email; - } - - $details['address']['line1'] = $this->get_billing_address_1(); - $details['address']['line2'] = $this->get_billing_address_2(); - $details['address']['state'] = $this->get_billing_state(); - $details['address']['city'] = $this->get_billing_city(); - $details['address']['postal_code'] = $this->get_billing_postcode(); - $details['address']['country'] = $this->get_billing_country(); - - return (object) apply_filters( 'wc_stripe_owner_details', $details, $this ); - } - - /** - * Validates that the order meets the minimum order amount - * set by Stripe. - * - * @throws WC_Stripe_Exception If the order does not meet the minimum amount. - */ - public function validate_minimum_amount() { - if ( $this->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { - /* translators: 1) amount (including currency symbol) */ - 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 ) ) ); - } - } - - /** - * Adds payment intent id and order note to order if payment intent is not already saved - * - * @param $payment_intent_id string The payment intent id to add to the order. - */ - public function add_payment_intent_to_order( $payment_intent_id ) { - $old_intent_id = $this->get_intent_id(); - if ( $old_intent_id === $payment_intent_id ) { - return; - } - - $this->add_order_note( - sprintf( - /* translators: $1%s payment intent ID */ - __( 'Stripe payment intent created (Payment Intent ID: %1$s)', 'woocommerce-gateway-stripe' ), - $payment_intent_id - ) - ); - - $this->set_intent_id( $payment_intent_id ); - $this->save(); - } - - /** - * Gets the Stripe fee for order. With legacy check. - * - * @return string $amount - */ - public function get_fee() { - $amount = $this->get_meta( self::META_STRIPE_FEE ); - - // If not found let's check for legacy name. - if ( empty( $amount ) ) { - $amount = $this->get_meta( 'Stripe Fee' ); - - // If found update to new name. - if ( $amount ) { - $this->set_fee( $amount ); - } - } - - return $amount; - } - - /** - * Updates the Stripe fee for order. - * - * @param float $amount - */ - public function set_fee( $amount = 0.0 ) { - $this->update_meta_data( self::META_STRIPE_FEE, $amount ); - } - - /** - * Deletes the Stripe fee for order. - */ - public function delete_fee() { - $this->delete_meta_data( self::META_STRIPE_FEE ); - $this->delete_meta_data( 'Stripe Fee' ); - } - - /** - * Gets the Stripe net for order. With legacy check. - * - * @return string $amount - */ - public function get_net() { - $amount = $this->get_meta( self::META_STRIPE_NET, true ); - - // If not found let's check for legacy name. - if ( empty( $amount ) ) { - $amount = $this->get_meta( 'Net Revenue From Stripe', true ); - - // If found update to new name. - if ( $amount ) { - $this->set_net( $amount ); - } - } - - return $amount; - } - - /** - * Updates the Stripe net for order. - * - * @param float $amount - */ - public function set_net( $amount = 0.0 ) { - $this->update_meta_data( self::META_STRIPE_NET, $amount ); - } - - /** - * Deletes the Stripe net for order. - */ - public function delete_net() { - $this->delete_meta_data( self::META_STRIPE_NET ); - $this->delete_meta_data( 'Net Revenue From Stripe' ); - } - - /** - * Gets the Stripe currency for order. - * - * @return string $currency - */ - public function get_stripe_currency() { - return $this->get_meta( self::META_STRIPE_CURRENCY ); - } - - /** - * Updates the Stripe currency for order. - * - * @param string $currency - */ - public function set_stripe_currency( $currency ) { - $this->update_meta_data( self::META_STRIPE_CURRENCY, $currency ); - } - - /** - * Adds metadata to the order to indicate that the payment is awaiting action. - * - * This meta is primarily used to prevent orders from being cancelled by WooCommerce's hold stock settings. - * - * @return void - */ - public function set_payment_awaiting_action( $save = true ) { - $this->update_meta_data( self::META_STRIPE_PAYMENT_AWAITING_ACTION, wc_bool_to_string( true ) ); - - if ( $save ) { - $this->save(); - } - } - - /** - * Gets the metadata that indicates that the payment is awaiting action. - * - * @return bool Whether the payment is awaiting action. - */ - public function is_payment_awaiting_action() { - return wc_string_to_bool( $this->get_meta( self::META_STRIPE_PAYMENT_AWAITING_ACTION ) ); - } - - /** - * Removes the metadata from the order that was used to indicate that the payment was awaiting action. - * - * @param bool $save Whether to save the order after removing the metadata. - * - * @return void - */ - public function remove_payment_awaiting_action( $save = true ) { - $this->delete_meta_data( self::META_STRIPE_PAYMENT_AWAITING_ACTION ); - - if ( $save ) { - $this->save(); - } - } - - /** - * Set the preferred card brand. - * - * @param $brand string The brand to set. - * @return void - */ - public function set_card_brand( $brand ) { - $this->update_meta_data( self::META_STRIPE_CARD_BRAND, $brand ); - } - - /** - * Get the preferred card brand. - * - * @return string - */ - public function get_card_brand() { - return $this->get_meta( self::META_STRIPE_CARD_BRAND ); - } - - /** - * Locks an order for refund processing for 5 minutes. - * - * @return bool A flag that indicates whether the order is already locked. - */ - public function lock_refund() { - $this->read_meta_data( true ); - - $existing_lock = $this->get_lock_refund(); - - if ( $existing_lock ) { - $expiration = (int) $existing_lock; - - // If the lock is still active, return true. - if ( time() <= $expiration ) { - return true; - } - } - - $new_lock = time() + self::REFUND_LOCK_EXPIRATION; - - $this->set_lock_refund( $new_lock ); - $this->save_meta_data(); - - return false; - } - - /** - * Unlocks an order for processing refund. - */ - public function unlock_refund() { - $this->delete_meta_data( self::META_STRIPE_LOCK_REFUND ); - $this->save_meta_data(); - } - - /** - * Set the lock refund time. - * - * @param $time int The time to set. - * @return void - */ - public function set_lock_refund( $time ) { - $this->update_meta_data( self::META_STRIPE_LOCK_REFUND, $time ); - } - - /** - * Get the lock refund time. - * - * @return int - */ - public function get_lock_refund() { - return $this->get_meta( self::META_STRIPE_LOCK_REFUND ); - } - - /** - * Set the setup intent. - * - * @param $value string The value to set. - * @return void - */ - public function set_setup_intent( $value ) { - $this->update_meta_data( self::META_STRIPE_SETUP_INTENT, $value ); - } - - /** - * Get the setup intent. - * - * @return string - */ - public function get_setup_intent() { - return $this->get_meta( self::META_STRIPE_SETUP_INTENT ); - } - - /** - * Set the UPE redirect processed flag. - * - * @param $value bool The value to set. - * @return void - */ - public function set_upe_redirect_processed( $value ) { - $this->update_meta_data( self::META_STRIPE_UPE_REDIRECT_PROCESSED, $value ); - } - - /** - * Whether the UPE redirect has been processed. - * - * @return bool The value of the flag. - */ - public function is_upe_redirect_processed() { - return (bool) $this->get_meta( self::META_STRIPE_UPE_REDIRECT_PROCESSED ); - } - - /** - * Stores the status of the order before being put on hold in metadata. - * - * @param string $status The order status to store. Accepts 'default_payment_complete' which will fetch the default status for payment complete orders. - * @return void - */ - public function set_status_before_hold( $status ) { - if ( 'default_payment_complete' === $status ) { - $payment_complete_status = $this->needs_processing() ? OrderStatus::PROCESSING : OrderStatus::COMPLETED; - $status = apply_filters( 'woocommerce_payment_complete_order_status', $payment_complete_status, $this->get_id(), $this ); - } - - $this->update_meta_data( '_stripe_status_before_hold', $status ); - } - - /** - * Helper method to retrieve the status of the order before it was put on hold. - * - * @return string The status of the order before it was put on hold. - */ - public function get_status_before_hold() { - $before_hold_status = $this->get_meta( self::META_STRIPE_STATUS_BEFORE_HOLD ); - - if ( ! empty( $before_hold_status ) ) { - return $before_hold_status; - } - - $default_before_hold_status = $this->needs_processing() ? OrderStatus::PROCESSING : OrderStatus::COMPLETED; - return apply_filters( 'woocommerce_payment_complete_order_status', $default_before_hold_status, $this->get_id(), $this ); - } - - /** - * Set the UPE waiting for redirect flag. - * - * @param $value bool The value to set. - * @return void - */ - public function set_upe_waiting_for_redirect( $value ) { - $this->update_meta_data( self::META_STRIPE_UPE_WAITING_FOR_REDIRECT, $value ); - } - - /** - * Whether the UPE payment is waiting for redirect. - * - * @return bool - */ - public function is_upe_waiting_for_redirect() { - return (bool) $this->get_meta( self::META_STRIPE_UPE_WAITING_FOR_REDIRECT ); - } - - /** - * Set the mandate ID. - * - * @param $mandate_id string The mandate ID to set. - * @return void - */ - public function set_mandate_id( $mandate_id ) { - $this->update_meta_data( self::META_STRIPE_MANDATE_ID, $mandate_id ); - } - - /** - * Get the mandate ID. - * - * @return string - */ - public function get_mandate_id() { - return $this->get_meta( self::META_STRIPE_MANDATE_ID ); - } - - /** - * Locks an order for payment intent processing for 5 minutes. - * - * @param stdClass $intent The intent that is being processed. - * @return bool A flag that indicates whether the order is already locked. - */ - public function lock_payment( $intent = null ) { - $this->read_meta_data( true ); - - $existing_lock = $this->get_lock_payment(); - - if ( $existing_lock ) { - $parts = explode( '|', $existing_lock ); // Format is: "{expiry_timestamp}" or "{expiry_timestamp}|{pi_xxxx}" if an intent is passed. - $expiration = (int) $parts[0]; - $locked_intent = ! empty( $parts[1] ) ? $parts[1] : ''; - - // If the lock is still active, return true. - if ( time() <= $expiration && ( empty( $intent ) || empty( $locked_intent ) || ( $intent->id ?? '' ) === $locked_intent ) ) { - return true; - } - } - - $new_lock = ( time() + self::PAYMENT_LOCK_EXPIRATION ) . ( isset( $intent->id ) ? '|' . $intent->id : '' ); - - $this->set_lock_payment( $new_lock ); - $this->save_meta_data(); - - return false; - } - - /** - * Unlocks an order for processing by payment intents. - */ - public function unlock_payment() { - $this->delete_meta_data( self::META_STRIPE_LOCK_PAYMENT ); - $this->save_meta_data(); - } - - /** - * Set the lock payment time. - * - * @param $time int The time to set. - * @return void - */ - public function set_lock_payment( $time ) { - $this->update_meta_data( self::META_STRIPE_LOCK_PAYMENT, $time ); - } - - /** - * Get the lock payment time. - * - * @return int - */ - public function get_lock_payment() { - return $this->get_meta( self::META_STRIPE_LOCK_PAYMENT ); - } - - /** - * Set the refund ID. - * - * @param $refund_id string The refund ID to set. - * @return void - */ - public function set_refund_id( $refund_id ) { - $this->update_meta_data( self::META_STRIPE_REFUND_ID, $refund_id ); - } - - /** - * Get the refund ID. - * - * @return string - */ - public function get_refund_id() { - return $this->get_meta( self::META_STRIPE_REFUND_ID ); - } - - /** - * Set the Multibanco data. - * - * @param $data array The Multibanco data to set. - * @return void - */ - public function set_multibanco_data( $data ) { - $this->update_meta_data( self::META_STRIPE_MULTIBANCO, $data ); - } - - /** - * Get the Multibanco data. - * - * @return array - */ - public function get_multibanco_data() { - return $this->get_meta( self::META_STRIPE_MULTIBANCO ); - } - - /** - * Set the Stripe intent ID. - * - * @param $intent_id string The intent ID to set. - * @return void - */ - public function set_intent_id( $intent_id ) { - $this->update_meta_data( self::META_STRIPE_INTENT_ID, $intent_id ); - } - - /** - * Get the Stripe intent ID. - * - * @return string - */ - public function get_intent_id() { - return $this->get_meta( self::META_STRIPE_INTENT_ID ); - } - - /** - * Set the UPE payment type. - * - * @param $payment_type string The payment type to set. - * @return void - */ - public function set_upe_payment_type( $payment_type ) { - $this->update_meta_data( self::META_STRIPE_UPE_PAYMENT_TYPE, $payment_type ); - } - - /** - * Get the UPE payment type. - * - * @return string - */ - public function get_upe_payment_type() { - return $this->get_meta( self::META_STRIPE_UPE_PAYMENT_TYPE ); - } - - /** - * Set the Stripe source ID. - * - * @param $source_id string The Stripe source ID. - * @return void - */ - public function set_source_id( $source_id ) { - $this->update_meta_data( self::META_STRIPE_SOURCE_ID, $source_id ); - } - - /** - * Get the Stripe source ID. - * - * @return string - */ - public function get_source_id() { - return $this->get_meta( self::META_STRIPE_SOURCE_ID ); - } - - /** - * Set the Stripe customer ID. - * - * @param $customer_id string The Stripe customer ID. - * @return void - */ - public function set_stripe_customer_id( $customer_id ) { - $this->update_meta_data( self::META_STRIPE_CUSTOMER_ID, $customer_id ); - } - - /** - * Get the Stripe customer ID. - * - * @return string - */ - public function get_stripe_customer_id() { - return $this->get_meta( self::META_STRIPE_CUSTOMER_ID ); - } - - /** - * Set the charge captured flag. - * - * @param $value string The value to set. - * @return void - */ - public function set_charge_captured( $value ) { - $this->update_meta_data( self::META_STRIPE_CHARGE_CAPTURED, $value ); - } - /** - * Whether the charge has been captured. - * - * @return bool - */ - public function is_charge_captured() { - return wc_string_to_bool( $this->get_meta( self::META_STRIPE_CHARGE_CAPTURED ) ); - } - - /** - * Set the status final value. - * - * @param $value bool The value to set. - * @return void - */ - public function set_status_final( $value ) { - $this->update_meta_data( self::META_STRIPE_STATUS_FINAL, $value ); - } - - /** - * Whether the current order status is final. - * - * @return bool - */ - public function is_status_final() { - return (bool) $this->get_meta( self::META_STRIPE_STATUS_FINAL ); - } - - /** - * Queries for an order by a specific meta key and value. - * - * @param $meta_key string The meta key to search for. - * @param $meta_value string The meta value to search for. - * @return bool|WC_Stripe_Order - */ - private static function get_by_meta( $meta_key, $meta_value ) { - global $wpdb; - - if ( WC_Stripe_Woo_Compat_Utils::is_custom_orders_table_enabled() ) { - $params = [ 'limit' => 1 ]; - // Check if the meta key is a transaction ID. If so, use the transaction ID to query the order, instead of the meta when HPOS is enabled. - if ( self::META_STRIPE_CHARGE_ID === $meta_key ) { - $params['transaction_id'] = $meta_value; - } else { - $params['meta_query'] = [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query - [ - 'key' => $meta_key, - 'value' => $meta_value, - ], - ]; - } - - $orders = self::query( $params ); - $order_id = current( $orders ) ? current( $orders )->get_id() : false; - } else { - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $meta_value, $meta_key ) ); - } - - if ( ! empty( $order_id ) ) { - $order = self::get_by_id( $order_id ); - } - - if ( ! empty( $order ) && $order->get_status() !== OrderStatus::TRASH ) { - return $order; - } - - return false; - } -} diff --git a/includes/constants/class-wc-stripe-order-metas.php b/includes/constants/class-wc-stripe-order-metas.php new file mode 100644 index 0000000000..1b86dd0814 --- /dev/null +++ b/includes/constants/class-wc-stripe-order-metas.php @@ -0,0 +1,155 @@ + Date: Tue, 13 May 2025 10:05:00 -0300 Subject: [PATCH 2/6] Requiring file --- woocommerce-gateway-stripe.php | 1 + 1 file changed, 1 insertion(+) diff --git a/woocommerce-gateway-stripe.php b/woocommerce-gateway-stripe.php index f8a484c094..5b1bea99b1 100644 --- a/woocommerce-gateway-stripe.php +++ b/woocommerce-gateway-stripe.php @@ -230,6 +230,7 @@ public function init() { require_once __DIR__ . '/includes/constants/class-wc-stripe-currency-code.php'; require_once __DIR__ . '/includes/constants/class-wc-stripe-payment-methods.php'; require_once __DIR__ . '/includes/constants/class-wc-stripe-intent-status.php'; + require_once __DIR__ . '/includes/constants/class-wc-stripe-order-metas.php'; require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php'; require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method.php'; require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-cc.php'; From 970d04385ad913f4a3abfa40e11e062661b5dca8 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 13 May 2025 10:07:18 -0300 Subject: [PATCH 3/6] Deprecating the order wrapper class instead of removing it --- includes/class-wc-stripe-order.php | 913 +++++++++++++++++++++++++++++ 1 file changed, 913 insertions(+) create mode 100644 includes/class-wc-stripe-order.php diff --git a/includes/class-wc-stripe-order.php b/includes/class-wc-stripe-order.php new file mode 100644 index 0000000000..1766afb121 --- /dev/null +++ b/includes/class-wc-stripe-order.php @@ -0,0 +1,913 @@ +get_billing_first_name(); + $billing_last_name = $this->get_billing_last_name(); + + $details = []; + + $name = $billing_first_name . ' ' . $billing_last_name; + $email = $this->get_billing_email(); + $phone = $this->get_billing_phone(); + + if ( ! empty( $phone ) ) { + $details['phone'] = $phone; + } + + if ( ! empty( $name ) ) { + $details['name'] = $name; + } + + if ( ! empty( $email ) ) { + $details['email'] = $email; + } + + $details['address']['line1'] = $this->get_billing_address_1(); + $details['address']['line2'] = $this->get_billing_address_2(); + $details['address']['state'] = $this->get_billing_state(); + $details['address']['city'] = $this->get_billing_city(); + $details['address']['postal_code'] = $this->get_billing_postcode(); + $details['address']['country'] = $this->get_billing_country(); + + return (object) apply_filters( 'wc_stripe_owner_details', $details, $this ); + } + + /** + * Validates that the order meets the minimum order amount + * set by Stripe. + * + * @throws WC_Stripe_Exception If the order does not meet the minimum amount. + */ + public function validate_minimum_amount() { + if ( $this->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { + /* translators: 1) amount (including currency symbol) */ + 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 ) ) ); + } + } + + /** + * Adds payment intent id and order note to order if payment intent is not already saved + * + * @param $payment_intent_id string The payment intent id to add to the order. + */ + public function add_payment_intent_to_order( $payment_intent_id ) { + $old_intent_id = $this->get_intent_id(); + if ( $old_intent_id === $payment_intent_id ) { + return; + } + + $this->add_order_note( + sprintf( + /* translators: $1%s payment intent ID */ + __( 'Stripe payment intent created (Payment Intent ID: %1$s)', 'woocommerce-gateway-stripe' ), + $payment_intent_id + ) + ); + + $this->set_intent_id( $payment_intent_id ); + $this->save(); + } + + /** + * Gets the Stripe fee for order. With legacy check. + * + * @return string $amount + */ + public function get_fee() { + $amount = $this->get_meta( self::META_STRIPE_FEE ); + + // If not found let's check for legacy name. + if ( empty( $amount ) ) { + $amount = $this->get_meta( 'Stripe Fee' ); + + // If found update to new name. + if ( $amount ) { + $this->set_fee( $amount ); + } + } + + return $amount; + } + + /** + * Updates the Stripe fee for order. + * + * @param float $amount + */ + public function set_fee( $amount = 0.0 ) { + $this->update_meta_data( self::META_STRIPE_FEE, $amount ); + } + + /** + * Deletes the Stripe fee for order. + */ + public function delete_fee() { + $this->delete_meta_data( self::META_STRIPE_FEE ); + $this->delete_meta_data( 'Stripe Fee' ); + } + + /** + * Gets the Stripe net for order. With legacy check. + * + * @return string $amount + */ + public function get_net() { + $amount = $this->get_meta( self::META_STRIPE_NET, true ); + + // If not found let's check for legacy name. + if ( empty( $amount ) ) { + $amount = $this->get_meta( 'Net Revenue From Stripe', true ); + + // If found update to new name. + if ( $amount ) { + $this->set_net( $amount ); + } + } + + return $amount; + } + + /** + * Updates the Stripe net for order. + * + * @param float $amount + */ + public function set_net( $amount = 0.0 ) { + $this->update_meta_data( self::META_STRIPE_NET, $amount ); + } + + /** + * Deletes the Stripe net for order. + */ + public function delete_net() { + $this->delete_meta_data( self::META_STRIPE_NET ); + $this->delete_meta_data( 'Net Revenue From Stripe' ); + } + + /** + * Gets the Stripe currency for order. + * + * @return string $currency + */ + public function get_stripe_currency() { + return $this->get_meta( self::META_STRIPE_CURRENCY ); + } + + /** + * Updates the Stripe currency for order. + * + * @param string $currency + */ + public function set_stripe_currency( $currency ) { + $this->update_meta_data( self::META_STRIPE_CURRENCY, $currency ); + } + + /** + * Adds metadata to the order to indicate that the payment is awaiting action. + * + * This meta is primarily used to prevent orders from being cancelled by WooCommerce's hold stock settings. + * + * @return void + */ + public function set_payment_awaiting_action( $save = true ) { + $this->update_meta_data( self::META_STRIPE_PAYMENT_AWAITING_ACTION, wc_bool_to_string( true ) ); + + if ( $save ) { + $this->save(); + } + } + + /** + * Gets the metadata that indicates that the payment is awaiting action. + * + * @return bool Whether the payment is awaiting action. + */ + public function is_payment_awaiting_action() { + return wc_string_to_bool( $this->get_meta( self::META_STRIPE_PAYMENT_AWAITING_ACTION ) ); + } + + /** + * Removes the metadata from the order that was used to indicate that the payment was awaiting action. + * + * @param bool $save Whether to save the order after removing the metadata. + * + * @return void + */ + public function remove_payment_awaiting_action( $save = true ) { + $this->delete_meta_data( self::META_STRIPE_PAYMENT_AWAITING_ACTION ); + + if ( $save ) { + $this->save(); + } + } + + /** + * Set the preferred card brand. + * + * @param $brand string The brand to set. + * @return void + */ + public function set_card_brand( $brand ) { + $this->update_meta_data( self::META_STRIPE_CARD_BRAND, $brand ); + } + + /** + * Get the preferred card brand. + * + * @return string + */ + public function get_card_brand() { + return $this->get_meta( self::META_STRIPE_CARD_BRAND ); + } + + /** + * Locks an order for refund processing for 5 minutes. + * + * @return bool A flag that indicates whether the order is already locked. + */ + public function lock_refund() { + $this->read_meta_data( true ); + + $existing_lock = $this->get_lock_refund(); + + if ( $existing_lock ) { + $expiration = (int) $existing_lock; + + // If the lock is still active, return true. + if ( time() <= $expiration ) { + return true; + } + } + + $new_lock = time() + self::REFUND_LOCK_EXPIRATION; + + $this->set_lock_refund( $new_lock ); + $this->save_meta_data(); + + return false; + } + + /** + * Unlocks an order for processing refund. + */ + public function unlock_refund() { + $this->delete_meta_data( self::META_STRIPE_LOCK_REFUND ); + $this->save_meta_data(); + } + + /** + * Set the lock refund time. + * + * @param $time int The time to set. + * @return void + */ + public function set_lock_refund( $time ) { + $this->update_meta_data( self::META_STRIPE_LOCK_REFUND, $time ); + } + + /** + * Get the lock refund time. + * + * @return int + */ + public function get_lock_refund() { + return $this->get_meta( self::META_STRIPE_LOCK_REFUND ); + } + + /** + * Set the setup intent. + * + * @param $value string The value to set. + * @return void + */ + public function set_setup_intent( $value ) { + $this->update_meta_data( self::META_STRIPE_SETUP_INTENT, $value ); + } + + /** + * Get the setup intent. + * + * @return string + */ + public function get_setup_intent() { + return $this->get_meta( self::META_STRIPE_SETUP_INTENT ); + } + + /** + * Set the UPE redirect processed flag. + * + * @param $value bool The value to set. + * @return void + */ + public function set_upe_redirect_processed( $value ) { + $this->update_meta_data( self::META_STRIPE_UPE_REDIRECT_PROCESSED, $value ); + } + + /** + * Whether the UPE redirect has been processed. + * + * @return bool The value of the flag. + */ + public function is_upe_redirect_processed() { + return (bool) $this->get_meta( self::META_STRIPE_UPE_REDIRECT_PROCESSED ); + } + + /** + * Stores the status of the order before being put on hold in metadata. + * + * @param string $status The order status to store. Accepts 'default_payment_complete' which will fetch the default status for payment complete orders. + * @return void + */ + public function set_status_before_hold( $status ) { + if ( 'default_payment_complete' === $status ) { + $payment_complete_status = $this->needs_processing() ? OrderStatus::PROCESSING : OrderStatus::COMPLETED; + $status = apply_filters( 'woocommerce_payment_complete_order_status', $payment_complete_status, $this->get_id(), $this ); + } + + $this->update_meta_data( '_stripe_status_before_hold', $status ); + } + + /** + * Helper method to retrieve the status of the order before it was put on hold. + * + * @return string The status of the order before it was put on hold. + */ + public function get_status_before_hold() { + $before_hold_status = $this->get_meta( self::META_STRIPE_STATUS_BEFORE_HOLD ); + + if ( ! empty( $before_hold_status ) ) { + return $before_hold_status; + } + + $default_before_hold_status = $this->needs_processing() ? OrderStatus::PROCESSING : OrderStatus::COMPLETED; + return apply_filters( 'woocommerce_payment_complete_order_status', $default_before_hold_status, $this->get_id(), $this ); + } + + /** + * Set the UPE waiting for redirect flag. + * + * @param $value bool The value to set. + * @return void + */ + public function set_upe_waiting_for_redirect( $value ) { + $this->update_meta_data( self::META_STRIPE_UPE_WAITING_FOR_REDIRECT, $value ); + } + + /** + * Whether the UPE payment is waiting for redirect. + * + * @return bool + */ + public function is_upe_waiting_for_redirect() { + return (bool) $this->get_meta( self::META_STRIPE_UPE_WAITING_FOR_REDIRECT ); + } + + /** + * Set the mandate ID. + * + * @param $mandate_id string The mandate ID to set. + * @return void + */ + public function set_mandate_id( $mandate_id ) { + $this->update_meta_data( self::META_STRIPE_MANDATE_ID, $mandate_id ); + } + + /** + * Get the mandate ID. + * + * @return string + */ + public function get_mandate_id() { + return $this->get_meta( self::META_STRIPE_MANDATE_ID ); + } + + /** + * Locks an order for payment intent processing for 5 minutes. + * + * @param stdClass $intent The intent that is being processed. + * @return bool A flag that indicates whether the order is already locked. + */ + public function lock_payment( $intent = null ) { + $this->read_meta_data( true ); + + $existing_lock = $this->get_lock_payment(); + + if ( $existing_lock ) { + $parts = explode( '|', $existing_lock ); // Format is: "{expiry_timestamp}" or "{expiry_timestamp}|{pi_xxxx}" if an intent is passed. + $expiration = (int) $parts[0]; + $locked_intent = ! empty( $parts[1] ) ? $parts[1] : ''; + + // If the lock is still active, return true. + if ( time() <= $expiration && ( empty( $intent ) || empty( $locked_intent ) || ( $intent->id ?? '' ) === $locked_intent ) ) { + return true; + } + } + + $new_lock = ( time() + self::PAYMENT_LOCK_EXPIRATION ) . ( isset( $intent->id ) ? '|' . $intent->id : '' ); + + $this->set_lock_payment( $new_lock ); + $this->save_meta_data(); + + return false; + } + + /** + * Unlocks an order for processing by payment intents. + */ + public function unlock_payment() { + $this->delete_meta_data( self::META_STRIPE_LOCK_PAYMENT ); + $this->save_meta_data(); + } + + /** + * Set the lock payment time. + * + * @param $time int The time to set. + * @return void + */ + public function set_lock_payment( $time ) { + $this->update_meta_data( self::META_STRIPE_LOCK_PAYMENT, $time ); + } + + /** + * Get the lock payment time. + * + * @return int + */ + public function get_lock_payment() { + return $this->get_meta( self::META_STRIPE_LOCK_PAYMENT ); + } + + /** + * Set the refund ID. + * + * @param $refund_id string The refund ID to set. + * @return void + */ + public function set_refund_id( $refund_id ) { + $this->update_meta_data( self::META_STRIPE_REFUND_ID, $refund_id ); + } + + /** + * Get the refund ID. + * + * @return string + */ + public function get_refund_id() { + return $this->get_meta( self::META_STRIPE_REFUND_ID ); + } + + /** + * Set the Multibanco data. + * + * @param $data array The Multibanco data to set. + * @return void + */ + public function set_multibanco_data( $data ) { + $this->update_meta_data( self::META_STRIPE_MULTIBANCO, $data ); + } + + /** + * Get the Multibanco data. + * + * @return array + */ + public function get_multibanco_data() { + return $this->get_meta( self::META_STRIPE_MULTIBANCO ); + } + + /** + * Set the Stripe intent ID. + * + * @param $intent_id string The intent ID to set. + * @return void + */ + public function set_intent_id( $intent_id ) { + $this->update_meta_data( self::META_STRIPE_INTENT_ID, $intent_id ); + } + + /** + * Get the Stripe intent ID. + * + * @return string + */ + public function get_intent_id() { + return $this->get_meta( self::META_STRIPE_INTENT_ID ); + } + + /** + * Set the UPE payment type. + * + * @param $payment_type string The payment type to set. + * @return void + */ + public function set_upe_payment_type( $payment_type ) { + $this->update_meta_data( self::META_STRIPE_UPE_PAYMENT_TYPE, $payment_type ); + } + + /** + * Get the UPE payment type. + * + * @return string + */ + public function get_upe_payment_type() { + return $this->get_meta( self::META_STRIPE_UPE_PAYMENT_TYPE ); + } + + /** + * Set the Stripe source ID. + * + * @param $source_id string The Stripe source ID. + * @return void + */ + public function set_source_id( $source_id ) { + $this->update_meta_data( self::META_STRIPE_SOURCE_ID, $source_id ); + } + + /** + * Get the Stripe source ID. + * + * @return string + */ + public function get_source_id() { + return $this->get_meta( self::META_STRIPE_SOURCE_ID ); + } + + /** + * Set the Stripe customer ID. + * + * @param $customer_id string The Stripe customer ID. + * @return void + */ + public function set_stripe_customer_id( $customer_id ) { + $this->update_meta_data( self::META_STRIPE_CUSTOMER_ID, $customer_id ); + } + + /** + * Get the Stripe customer ID. + * + * @return string + */ + public function get_stripe_customer_id() { + return $this->get_meta( self::META_STRIPE_CUSTOMER_ID ); + } + + /** + * Set the charge captured flag. + * + * @param $value string The value to set. + * @return void + */ + public function set_charge_captured( $value ) { + $this->update_meta_data( self::META_STRIPE_CHARGE_CAPTURED, $value ); + } + /** + * Whether the charge has been captured. + * + * @return bool + */ + public function is_charge_captured() { + return wc_string_to_bool( $this->get_meta( self::META_STRIPE_CHARGE_CAPTURED ) ); + } + + /** + * Set the status final value. + * + * @param $value bool The value to set. + * @return void + */ + public function set_status_final( $value ) { + $this->update_meta_data( self::META_STRIPE_STATUS_FINAL, $value ); + } + + /** + * Whether the current order status is final. + * + * @return bool + */ + public function is_status_final() { + return (bool) $this->get_meta( self::META_STRIPE_STATUS_FINAL ); + } + + /** + * Queries for an order by a specific meta key and value. + * + * @param $meta_key string The meta key to search for. + * @param $meta_value string The meta value to search for. + * @return bool|WC_Stripe_Order + */ + private static function get_by_meta( $meta_key, $meta_value ) { + global $wpdb; + + if ( WC_Stripe_Woo_Compat_Utils::is_custom_orders_table_enabled() ) { + $params = [ 'limit' => 1 ]; + // Check if the meta key is a transaction ID. If so, use the transaction ID to query the order, instead of the meta when HPOS is enabled. + if ( self::META_STRIPE_CHARGE_ID === $meta_key ) { + $params['transaction_id'] = $meta_value; + } else { + $params['meta_query'] = [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query + [ + 'key' => $meta_key, + 'value' => $meta_value, + ], + ]; + } + + $orders = self::query( $params ); + $order_id = current( $orders ) ? current( $orders )->get_id() : false; + } else { + $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $meta_value, $meta_key ) ); + } + + if ( ! empty( $order_id ) ) { + $order = self::get_by_id( $order_id ); + } + + if ( ! empty( $order ) && $order->get_status() !== OrderStatus::TRASH ) { + return $order; + } + + return false; + } +} From 91e1b1a8422868eb835c434b2e5f5b47b8846c15 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 13 May 2025 10:07:49 -0300 Subject: [PATCH 4/6] Deprecating the order wrapper class instead of removing it --- includes/class-wc-stripe-order.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/class-wc-stripe-order.php b/includes/class-wc-stripe-order.php index 1766afb121..f3e404a155 100644 --- a/includes/class-wc-stripe-order.php +++ b/includes/class-wc-stripe-order.php @@ -10,6 +10,8 @@ * Class WC_Stripe_Order * * Wrapper for the original WC_Order class to allow custom getters and setter with the extension's specific metadata. + * + * @deprecated 9.5.0 This class is deprecated due bugs and incompatibility with some existing flows. */ class WC_Stripe_Order extends WC_Order { /** From aeb4d45d631860365f93e2b400d297149d1653ee Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 13 May 2025 10:08:27 -0300 Subject: [PATCH 5/6] Replacing meta values occurences --- ...ract-wc-stripe-payment-gateway-voucher.php | 4 +- .../abstract-wc-stripe-payment-gateway.php | 58 +++++++-------- ...class-wc-rest-stripe-orders-controller.php | 4 +- includes/admin/class-wc-stripe-privacy.php | 44 ++++++------ includes/class-wc-stripe-customer.php | 6 +- includes/class-wc-stripe-helper.php | 60 ++++++++++------ .../class-wc-stripe-intent-controller.php | 4 +- includes/class-wc-stripe-order-handler.php | 12 ++-- includes/class-wc-stripe-webhook-handler.php | 38 +++++----- .../class-wc-stripe-subscriptions-helper.php | 4 +- ...subscriptions-legacy-sepa-token-update.php | 2 +- .../compat/trait-wc-stripe-pre-orders.php | 2 +- .../compat/trait-wc-stripe-subscriptions.php | 70 +++++++++---------- ...scriptions-repairer-legacy-sepa-tokens.php | 2 +- .../class-wc-gateway-stripe-alipay.php | 2 +- .../class-wc-gateway-stripe-bancontact.php | 2 +- .../class-wc-gateway-stripe-boleto.php | 2 +- .../class-wc-gateway-stripe-eps.php | 2 +- .../class-wc-gateway-stripe-giropay.php | 2 +- .../class-wc-gateway-stripe-ideal.php | 2 +- .../class-wc-gateway-stripe-multibanco.php | 6 +- .../class-wc-gateway-stripe-oxxo.php | 2 +- .../class-wc-gateway-stripe-p24.php | 2 +- .../class-wc-gateway-stripe-sepa.php | 4 +- .../class-wc-gateway-stripe-sofort.php | 2 +- .../class-wc-stripe-upe-payment-gateway.php | 30 ++++---- ...ss-wc-stripe-upe-payment-method-boleto.php | 2 +- ...c-stripe-upe-payment-method-multibanco.php | 6 +- ...lass-wc-stripe-upe-payment-method-oxxo.php | 2 +- 29 files changed, 197 insertions(+), 181 deletions(-) diff --git a/includes/abstracts/abstract-wc-stripe-payment-gateway-voucher.php b/includes/abstracts/abstract-wc-stripe-payment-gateway-voucher.php index 0ff21cbdb7..27ae18cd1f 100644 --- a/includes/abstracts/abstract-wc-stripe-payment-gateway-voucher.php +++ b/includes/abstracts/abstract-wc-stripe-payment-gateway-voucher.php @@ -264,7 +264,7 @@ public function process_payment( $order_id, $retry = true, $force_save_save = fa $intent = $this->create_or_update_payment_intent( $order ); - $order->update_meta_data( '_stripe_upe_payment_type', $this->stripe_id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE, $this->stripe_id ); $order->update_status( OrderStatus::PENDING, __( 'Awaiting payment.', 'woocommerce-gateway-stripe' ) ); $order->save(); @@ -386,7 +386,7 @@ public function update_payment_intent_ajax() { $intent = $this->create_or_update_payment_intent( $order ); $order->update_status( OrderStatus::PENDING, __( 'Awaiting payment.', 'woocommerce-gateway-stripe' ) ); - $order->update_meta_data( '_stripe_upe_payment_type', $this->stripe_id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE, $this->stripe_id ); $order->save(); wp_send_json( diff --git a/includes/abstracts/abstract-wc-stripe-payment-gateway.php b/includes/abstracts/abstract-wc-stripe-payment-gateway.php index c4c0046164..6bd890dfa5 100644 --- a/includes/abstracts/abstract-wc-stripe-payment-gateway.php +++ b/includes/abstracts/abstract-wc-stripe-payment-gateway.php @@ -329,8 +329,8 @@ public function maybe_remove_non_existent_customer( $error, $order ) { return false; } - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); - $order->delete_meta_data( '_stripe_customer_id' ); + delete_user_option( $order->get_customer_id(), WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); $order->save(); return true; @@ -410,10 +410,10 @@ public function get_transaction_url( $order ) { */ public function get_stripe_customer_id( $order ) { // Try to get it via the order first. - $customer = $order->get_meta( '_stripe_customer_id', true ); + $customer = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, true ); if ( empty( $customer ) ) { - $customer = get_user_option( '_stripe_customer_id', $order->get_customer_id() ); + $customer = get_user_option( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $order->get_customer_id() ); } return $customer; @@ -554,7 +554,7 @@ public function process_response( $response, $order ) { $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; // Store charge data. - $order->update_meta_data( '_stripe_charge_captured', $captured ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED, $captured ); if ( isset( $response->balance_transaction ) ) { $this->update_fees( $order, is_string( $response->balance_transaction ) ? $response->balance_transaction : $response->balance_transaction->id ); @@ -564,9 +564,9 @@ public function process_response( $response, $order ) { // The mandate ID is not available for the intent object, so we need to fetch the charge. // Mandate ID is necessary for renewal payments for certain payment methods and Indian cards. if ( isset( $response->payment_method_details->card->mandate ) ) { - $order->update_meta_data( '_stripe_mandate_id', $response->payment_method_details->card->mandate ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_MANDATE_ID, $response->payment_method_details->card->mandate ); } elseif ( isset( $response->payment_method_details->acss_debit->mandate ) ) { - $order->update_meta_data( '_stripe_mandate_id', $response->payment_method_details->acss_debit->mandate ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_MANDATE_ID, $response->payment_method_details->acss_debit->mandate ); } if ( isset( $response->payment_method, $response->payment_method_details ) ) { @@ -979,14 +979,14 @@ public function prepare_order_source( $order = null ) { $stripe_customer->set_id( $stripe_customer_id ); } - $source_id = $order->get_meta( '_stripe_source_id', true ); + $source_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ); // Since 4.0.0, we changed card to source so we need to account for that. if ( empty( $source_id ) ) { $source_id = $order->get_meta( '_stripe_card_id', true ); // Take this opportunity to update the key name. - $order->update_meta_data( '_stripe_source_id', $source_id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $source_id ); if ( is_callable( [ $order, 'save' ] ) ) { $order->save(); @@ -1039,11 +1039,11 @@ public function check_source( $prepared_source ) { public function save_source_to_order( $order, $source ) { // Store source in the order. if ( $source->customer ) { - $order->update_meta_data( '_stripe_customer_id', $source->customer ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $source->customer ); } if ( $source->source ) { - $order->update_meta_data( '_stripe_source_id', $source->source ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $source->source ); } if ( is_callable( [ $order, 'save' ] ) ) { @@ -1116,7 +1116,7 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { $request = []; $order_currency = $order->get_currency(); - $captured = $order->get_meta( '_stripe_charge_captured', true ); + $captured = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED, true ); $charge_id = $order->get_transaction_id(); if ( ! $charge_id ) { @@ -1234,7 +1234,7 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { } } - $order->update_meta_data( '_stripe_refund_id', $response->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID, $response->id ); if ( isset( $response->balance_transaction ) ) { $this->update_fees( $order, $response->balance_transaction ); @@ -1644,16 +1644,16 @@ public function save_intent_to_order( $order, $intent ) { $charge = $this->get_latest_charge_from_intent( $intent ); if ( isset( $charge->payment_method_details->card->mandate ) ) { - $order->update_meta_data( '_stripe_mandate_id', $charge->payment_method_details->card->mandate ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_MANDATE_ID, $charge->payment_method_details->card->mandate ); } elseif ( isset( $charge->payment_method_details->acss_debit->mandate ) ) { - $order->update_meta_data( '_stripe_mandate_id', $charge->payment_method_details->acss_debit->mandate ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_MANDATE_ID, $charge->payment_method_details->acss_debit->mandate ); } } elseif ( 'setup_intent' === $intent->object ) { - $order->update_meta_data( '_stripe_setup_intent', $intent->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SETUP_INTENT, $intent->id ); // Add mandate for free trial subscriptions. if ( isset( $intent->mandate ) ) { - $order->update_meta_data( '_stripe_mandate_id', $intent->mandate ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_MANDATE_ID, $intent->mandate ); } } @@ -1670,14 +1670,14 @@ public function save_intent_to_order( $order, $intent ) { * @return obect|bool Either the intent object or `false`. */ public function get_intent_from_order( $order ) { - $intent_id = $order->get_meta( '_stripe_intent_id' ); + $intent_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_INTENT_ID ); if ( $intent_id ) { return $this->get_intent( 'payment_intents', $intent_id ); } // The order doesn't have a payment intent, but it may have a setup intent. - $intent_id = $order->get_meta( '_stripe_setup_intent' ); + $intent_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SETUP_INTENT ); if ( $intent_id ) { return $this->get_intent( 'setup_intents', $intent_id ); @@ -1722,7 +1722,7 @@ private function get_intent( $intent_type, $intent_id ) { public function lock_order_payment( $order, $intent = null ) { $order->read_meta_data( true ); - $existing_lock = $order->get_meta( '_stripe_lock_payment', true ); + $existing_lock = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_LOCK_PAYMENT, true ); if ( $existing_lock ) { $parts = explode( '|', $existing_lock ); // Format is: "{expiry_timestamp}" or "{expiry_timestamp}|{pi_xxxx}" if an intent is passed. @@ -1737,7 +1737,7 @@ public function lock_order_payment( $order, $intent = null ) { $new_lock = ( time() + 5 * MINUTE_IN_SECONDS ) . ( isset( $intent->id ) ? '|' . $intent->id : '' ); - $order->update_meta_data( '_stripe_lock_payment', $new_lock ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_LOCK_PAYMENT, $new_lock ); $order->save_meta_data(); return false; @@ -1750,7 +1750,7 @@ public function lock_order_payment( $order, $intent = null ) { * @param WC_Order $order The order that is being unlocked. */ public function unlock_order_payment( $order ) { - $order->delete_meta_data( '_stripe_lock_payment' ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_LOCK_PAYMENT ); $order->save_meta_data(); } @@ -1764,7 +1764,7 @@ public function unlock_order_payment( $order ) { public function lock_order_refund( $order ) { $order->read_meta_data( true ); - $existing_lock = $order->get_meta( '_stripe_lock_refund', true ); + $existing_lock = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_LOCK_REFUND, true ); if ( $existing_lock ) { $expiration = (int) $existing_lock; @@ -1777,7 +1777,7 @@ public function lock_order_refund( $order ) { $new_lock = time() + 5 * MINUTE_IN_SECONDS; - $order->update_meta_data( '_stripe_lock_refund', $new_lock ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_LOCK_REFUND, $new_lock ); $order->save_meta_data(); return false; @@ -1790,7 +1790,7 @@ public function lock_order_refund( $order ) { * @param WC_Order $order The order that is being unlocked. */ public function unlock_order_refund( $order ) { - $order->delete_meta_data( '_stripe_lock_refund' ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_LOCK_REFUND ); $order->save_meta_data(); } @@ -1834,7 +1834,7 @@ public function setup_intent( $order, $prepared_source ) { if ( is_wp_error( $setup_intent ) ) { WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) ); } elseif ( WC_Stripe_Intent_Status::REQUIRES_ACTION === $setup_intent->status ) { - $order->update_meta_data( '_stripe_setup_intent', $setup_intent->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SETUP_INTENT, $setup_intent->id ); $order->save(); return $setup_intent->client_secret; @@ -1884,7 +1884,7 @@ public function create_and_confirm_intent_for_off_session( $order, $prepared_sou } // Add mandate if it exists. - $mandate = $order->get_meta( '_stripe_mandate_id', true ); + $mandate = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_MANDATE_ID, true ); if ( ! empty( $mandate ) ) { $request['mandate'] = $mandate; } @@ -2268,7 +2268,7 @@ private function needs_ssl_setup() { * @return string The status of the order before it was put on hold. */ protected function get_stripe_order_status_before_hold( $order ) { - $before_hold_status = $order->get_meta( '_stripe_status_before_hold' ); + $before_hold_status = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_STATUS_BEFORE_HOLD ); if ( ! empty( $before_hold_status ) ) { return $before_hold_status; @@ -2294,7 +2294,7 @@ protected function set_stripe_order_status_before_hold( $order, $status ) { $status = apply_filters( 'woocommerce_payment_complete_order_status', $payment_complete_status, $order->get_id(), $order ); } - $order->update_meta_data( '_stripe_status_before_hold', $status ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_STATUS_BEFORE_HOLD, $status ); } /** diff --git a/includes/admin/class-wc-rest-stripe-orders-controller.php b/includes/admin/class-wc-rest-stripe-orders-controller.php index 1526f50ade..2476af164f 100644 --- a/includes/admin/class-wc-rest-stripe-orders-controller.php +++ b/includes/admin/class-wc-rest-stripe-orders-controller.php @@ -126,7 +126,7 @@ public function create_customer( $request ) { $customer = new WC_Stripe_Customer( $order_user->ID ); // Set the customer ID if known but not already set. - $customer_id = $order->get_meta( '_stripe_customer_id', true ); + $customer_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, true ); if ( ! $customer->get_id() && $customer_id ) { $customer->set_id( $customer_id ); } @@ -143,7 +143,7 @@ public function create_customer( $request ) { return new WP_Error( 'stripe_error', $e->getMessage() ); } - $order->update_meta_data( '_stripe_customer_id', $customer_id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $customer_id ); $order->save(); return rest_ensure_response( [ 'id' => $customer_id ] ); diff --git a/includes/admin/class-wc-stripe-privacy.php b/includes/admin/class-wc-stripe-privacy.php index de01186b96..3d704e5f9f 100644 --- a/includes/admin/class-wc-stripe-privacy.php +++ b/includes/admin/class-wc-stripe-privacy.php @@ -133,11 +133,11 @@ public function order_data_exporter( $email_address, $page = 1 ) { 'data' => [ [ 'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ), - 'value' => $order->get_meta( '_stripe_source_id', true ), + 'value' => $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ), ], [ 'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ), - 'value' => $order->get_meta( '_stripe_customer_id', true ), + 'value' => $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, true ), ], ], ]; @@ -198,11 +198,11 @@ public function subscriptions_data_exporter( $email_address, $page = 1 ) { 'data' => [ [ 'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ), - 'value' => $subscription->get_meta( '_stripe_source_id', true ), + 'value' => $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ), ], [ 'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ), - 'value' => $subscription->get_meta( '_stripe_customer_id', true ), + 'value' => $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, true ), ], ], ]; @@ -238,7 +238,7 @@ public function customer_data_exporter( $email_address, $page ) { 'data' => [ [ 'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ), - 'value' => get_user_option( '_stripe_source_id', $user->ID ), + 'value' => get_user_option( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $user->ID ), ], [ 'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ), @@ -268,8 +268,8 @@ public function customer_data_eraser( $email_address, $page ) { $stripe_source_id = ''; if ( $user instanceof WP_User ) { - $stripe_customer_id = get_user_option( '_stripe_customer_id', $user->ID ); - $stripe_source_id = get_user_option( '_stripe_source_id', $user->ID ); + $stripe_customer_id = get_user_option( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $user->ID ); + $stripe_source_id = get_user_option( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $user->ID ); } $items_removed = false; @@ -277,8 +277,8 @@ public function customer_data_eraser( $email_address, $page ) { if ( ! empty( $stripe_customer_id ) || ! empty( $stripe_source_id ) ) { $items_removed = true; - delete_user_option( $user->ID, '_stripe_customer_id' ); - delete_user_option( $user->ID, '_stripe_source_id' ); + delete_user_option( $user->ID, WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); + delete_user_option( $user->ID, WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID ); $messages[] = __( 'Stripe User Data Erased.', 'woocommerce-gateway-stripe' ); } @@ -350,7 +350,7 @@ protected function maybe_handle_subscription( $order ) { $subscription = current( wcs_get_subscriptions_for_order( $order->get_id() ) ); - $stripe_source_id = $subscription->get_meta( '_stripe_source_id', true ); + $stripe_source_id = $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ); if ( empty( $stripe_source_id ) ) { return [ false, false, [] ]; @@ -369,14 +369,14 @@ protected function maybe_handle_subscription( $order ) { $renewal_orders = class_exists( 'WC_Subscriptions_Renewal_Order' ) ? WC_Subscriptions_Renewal_Order::get_renewal_orders( $order->get_id(), 'WC_Order' ) : []; foreach ( $renewal_orders as $renewal_order ) { - $renewal_order->delete_meta_data( '_stripe_source_id' ); - $renewal_order->delete_meta_data( '_stripe_refund_id' ); - $renewal_order->delete_meta_data( '_stripe_customer_id' ); + $renewal_order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID ); + $renewal_order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID ); + $renewal_order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); } - $subscription->delete_meta_data( '_stripe_source_id' ); - $subscription->delete_meta_data( '_stripe_refund_id' ); - $subscription->delete_meta_data( '_stripe_customer_id' ); + $subscription->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID ); + $subscription->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID ); + $subscription->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); return [ true, false, [ __( 'Stripe Subscription Data Erased.', 'woocommerce-gateway-stripe' ) ] ]; } @@ -388,9 +388,9 @@ protected function maybe_handle_subscription( $order ) { * @return array */ protected function maybe_handle_order( $order ) { - $stripe_source_id = $order->get_meta( '_stripe_source_id', true ); - $stripe_refund_id = $order->get_meta( '_stripe_refund_id', true ); - $stripe_customer_id = $order->get_meta( '_stripe_customer_id', true ); + $stripe_source_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ); + $stripe_refund_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID, true ); + $stripe_customer_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, true ); if ( ! $this->is_retention_expired( $order->get_date_created()->getTimestamp() ) ) { /* translators: %d Order ID */ @@ -401,9 +401,9 @@ protected function maybe_handle_order( $order ) { return [ false, false, [] ]; } - $order->delete_meta_data( '_stripe_source_id' ); - $order->delete_meta_data( '_stripe_refund_id' ); - $order->delete_meta_data( '_stripe_customer_id' ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); return [ true, false, [ __( 'Stripe personal data erased.', 'woocommerce-gateway-stripe' ) ] ]; } diff --git a/includes/class-wc-stripe-customer.php b/includes/class-wc-stripe-customer.php index 12c8f6e05e..ec5d2ceb98 100644 --- a/includes/class-wc-stripe-customer.php +++ b/includes/class-wc-stripe-customer.php @@ -719,7 +719,7 @@ public function clear_cache() { * @return string|bool Either the Stripe ID or false. */ public function get_id_from_meta( $user_id ) { - return get_user_option( '_stripe_customer_id', $user_id ); + return get_user_option( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $user_id ); } /** @@ -728,14 +728,14 @@ public function get_id_from_meta( $user_id ) { * @param string $id The Stripe customer ID. */ public function update_id_in_meta( $id ) { - update_user_option( $this->get_user_id(), '_stripe_customer_id', $id, false ); + update_user_option( $this->get_user_id(), WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $id, false ); } /** * Deletes the user ID from the meta table with the right key. */ public function delete_id_from_meta() { - delete_user_option( $this->get_user_id(), '_stripe_customer_id', false ); + delete_user_option( $this->get_user_id(), WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, false ); } /** diff --git a/includes/class-wc-stripe-helper.php b/includes/class-wc-stripe-helper.php index f3cf3b77d6..1c9950c477 100644 --- a/includes/class-wc-stripe-helper.php +++ b/includes/class-wc-stripe-helper.php @@ -15,11 +15,27 @@ class WC_Stripe_Helper { const SETTINGS_OPTION = 'woocommerce_stripe_settings'; const LEGACY_META_NAME_FEE = 'Stripe Fee'; const LEGACY_META_NAME_NET = 'Net Revenue From Stripe'; - const META_NAME_FEE = '_stripe_fee'; - const META_NAME_NET = '_stripe_net'; const META_NAME_STRIPE_CURRENCY = '_stripe_currency'; const PAYMENT_AWAITING_ACTION_META = '_stripe_payment_awaiting_action'; + /** + * Meta key for the Stripe fee amount. + * + * @var string + * + * @deprecated 9.5.0 Use WC_Stripe_Order_Metas::META_STRIPE_FEE instead. + */ + const META_NAME_FEE = '_stripe_fee'; + + /** + * Meta key for the Stripe net amount. + * + * @var string + * + * @deprecated 9.5.0 Use WC_Stripe_Order_Metas::META_STRIPE_NET instead. + */ + const META_NAME_NET = '_stripe_net'; + /** * List of legacy Stripe gateways. * @@ -102,7 +118,7 @@ public static function get_stripe_fee( $order = null ) { return false; } - $amount = $order->get_meta( self::META_NAME_FEE, true ); + $amount = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_FEE, true ); // If not found let's check for legacy name. if ( empty( $amount ) ) { @@ -129,7 +145,7 @@ public static function update_stripe_fee( $order = null, $amount = 0.0 ) { return false; } - $order->update_meta_data( self::META_NAME_FEE, $amount ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_FEE, $amount ); } /** @@ -143,7 +159,7 @@ public static function delete_stripe_fee( $order = null ) { return false; } - $order->delete_meta_data( self::META_NAME_FEE ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_FEE ); $order->delete_meta_data( self::LEGACY_META_NAME_FEE ); } @@ -159,7 +175,7 @@ public static function get_stripe_net( $order = null ) { return false; } - $amount = $order->get_meta( self::META_NAME_NET, true ); + $amount = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_NET, true ); // If not found let's check for legacy name. if ( empty( $amount ) ) { @@ -186,7 +202,7 @@ public static function update_stripe_net( $order = null, $amount = 0.0 ) { return false; } - $order->update_meta_data( self::META_NAME_NET, $amount ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_NET, $amount ); } /** @@ -200,7 +216,7 @@ public static function delete_stripe_net( $order = null ) { return false; } - $order->delete_meta_data( self::META_NAME_NET ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_NET ); $order->delete_meta_data( self::LEGACY_META_NAME_NET ); } @@ -877,7 +893,7 @@ public static function get_order_by_source_id( $source_id ) { 'limit' => 1, 'meta_query' => [ [ - 'key' => '_stripe_source_id', + 'key' => WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, 'value' => $source_id, ], ], @@ -885,7 +901,7 @@ public static function get_order_by_source_id( $source_id ) { ); $order_id = current( $orders ) ? current( $orders )->get_id() : false; } else { - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id' ) ); + $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID ) ); } if ( ! empty( $order_id ) ) { @@ -918,7 +934,7 @@ public static function get_order_by_charge_id( $charge_id ) { ); $order_id = current( $orders ) ? current( $orders )->get_id() : false; } else { - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id' ) ); + $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, WC_Stripe_Order_Metas::META_STRIPE_CHARGE_ID ) ); } if ( ! empty( $order_id ) ) { @@ -943,7 +959,7 @@ public static function get_order_by_refund_id( $refund_id ) { 'limit' => 1, 'meta_query' => [ [ - 'key' => '_stripe_refund_id', + 'key' => WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID, 'value' => $refund_id, ], ], @@ -951,7 +967,7 @@ public static function get_order_by_refund_id( $refund_id ) { ); $order_id = current( $orders ) ? current( $orders )->get_id() : false; } else { - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $refund_id, '_stripe_refund_id' ) ); + $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $refund_id, WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID ) ); } if ( ! empty( $order_id ) ) { @@ -977,7 +993,7 @@ public static function get_order_by_intent_id( $intent_id ) { 'limit' => 1, 'meta_query' => [ [ - 'key' => '_stripe_intent_id', + 'key' => WC_Stripe_Order_Metas::META_STRIPE_INTENT_ID, 'value' => $intent_id, ], ], @@ -985,7 +1001,7 @@ public static function get_order_by_intent_id( $intent_id ) { ); $order_id = current( $orders ) ? current( $orders )->get_id() : false; } else { - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_intent_id' ) ); + $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, WC_Stripe_Order_Metas::META_STRIPE_INTENT_ID ) ); } if ( ! empty( $order_id ) ) { @@ -1015,7 +1031,7 @@ public static function get_order_by_setup_intent_id( $intent_id ) { 'limit' => 1, 'meta_query' => [ [ - 'key' => '_stripe_setup_intent', + 'key' => WC_Stripe_Order_Metas::META_STRIPE_SETUP_INTENT, 'value' => $intent_id, ], ], @@ -1023,7 +1039,7 @@ public static function get_order_by_setup_intent_id( $intent_id ) { ); $order_id = current( $orders ) ? current( $orders )->get_id() : false; } else { - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_setup_intent' ) ); + $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, WC_Stripe_Order_Metas::META_STRIPE_SETUP_INTENT ) ); } if ( ! empty( $order_id ) ) { @@ -1269,7 +1285,7 @@ private static function should_load_scripts_for_prb_location( $location ) { */ public static function add_payment_intent_to_order( $payment_intent_id, $order ) { - $old_intent_id = $order->get_meta( '_stripe_intent_id' ); + $old_intent_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_INTENT_ID ); if ( $old_intent_id === $payment_intent_id ) { return; @@ -1283,7 +1299,7 @@ public static function add_payment_intent_to_order( $payment_intent_id, $order ) ) ); - $order->update_meta_data( '_stripe_intent_id', $payment_intent_id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_INTENT_ID, $payment_intent_id ); $order->save(); } @@ -1383,10 +1399,10 @@ public static function get_payment_method_from_intent( $intent ) { * @return string|bool The intent ID if found, false otherwise. */ public static function get_intent_id_from_order( $order ) { - $intent_id = $order->get_meta( '_stripe_intent_id' ); + $intent_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_INTENT_ID ); if ( ! $intent_id ) { - $intent_id = $order->get_meta( '_stripe_setup_intent' ); + $intent_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SETUP_INTENT ); } return $intent_id ?? false; @@ -1516,7 +1532,7 @@ public static function payment_method_allows_manual_capture( string $payment_met */ public static function is_wallet_payment_method( $order ) { wc_deprecated_function( __METHOD__, '8.9.0', 'in_array( $order->get_meta( \'_stripe_upe_payment_type\' ), WC_Stripe_Payment_Methods::WALLET_PAYMENT_METHODS, true )' ); - return in_array( $order->get_meta( '_stripe_upe_payment_type' ), WC_Stripe_Payment_Methods::WALLET_PAYMENT_METHODS, true ); + return in_array( $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE ), WC_Stripe_Payment_Methods::WALLET_PAYMENT_METHODS, true ); } /** diff --git a/includes/class-wc-stripe-intent-controller.php b/includes/class-wc-stripe-intent-controller.php index efea93d579..2b65ab2cd3 100644 --- a/includes/class-wc-stripe-intent-controller.php +++ b/includes/class-wc-stripe-intent-controller.php @@ -483,7 +483,7 @@ public function update_intent( $intent_id = '', $order_id = null, $save_payment_ WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, ]; } - $order->update_meta_data( '_stripe_upe_payment_type', $selected_upe_payment_type ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE, $selected_upe_payment_type ); } if ( ! empty( $customer ) && $customer->get_id() ) { $request['customer'] = $customer->get_id(); @@ -813,7 +813,7 @@ public function create_and_confirm_payment_intent( $payment_information ) { // Only update the payment_type if we have a reference to the payment type the customer selected. if ( '' !== $selected_payment_type ) { - $order->update_meta_data( '_stripe_upe_payment_type', $selected_payment_type ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE, $selected_payment_type ); } return $payment_intent; diff --git a/includes/class-wc-stripe-order-handler.php b/includes/class-wc-stripe-order-handler.php index 81401cf317..ec61e082b1 100644 --- a/includes/class-wc-stripe-order-handler.php +++ b/includes/class-wc-stripe-order-handler.php @@ -60,7 +60,7 @@ public function show_warning_for_uncaptured_orders( $order_id ) { $gateway = WC_Stripe::get_instance()->get_main_stripe_gateway(); // Bail if the order is already captured or if manual capture is disabled. - if ( 'yes' === $order->get_meta( '_stripe_charge_captured', true ) || $gateway->is_automatic_capture_enabled() ) { + if ( 'yes' === $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED, true ) || $gateway->is_automatic_capture_enabled() ) { return; } @@ -167,8 +167,8 @@ public function process_redirect_payment( $order_id, $retry = true, $previous_er if ( ! empty( $response->error ) ) { // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. if ( $this->is_no_such_customer_error( $response->error ) ) { - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); - $order->delete_meta_data( '_stripe_customer_id' ); + delete_user_option( $order->get_customer_id(), WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); $order->save(); } @@ -288,7 +288,7 @@ public function capture_payment( $order_id ) { if ( WC_Stripe_Helper::payment_method_allows_manual_capture( $order->get_payment_method() ) ) { $charge = $order->get_transaction_id(); - $captured = $order->get_meta( '_stripe_charge_captured', true ); + $captured = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED, true ); $is_stripe_captured = false; if ( $charge && 'no' === $captured ) { @@ -361,7 +361,7 @@ public function capture_payment( $order_id ) { if ( $is_stripe_captured ) { /* translators: transaction id */ $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); - $order->update_meta_data( '_stripe_charge_captured', 'yes' ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED, 'yes' ); // Store other data such as fees $order->set_transaction_id( $result->id ); @@ -395,7 +395,7 @@ public function cancel_payment( $order_id ) { $order = wc_get_order( $order_id ); if ( WC_Stripe_Helper::payment_method_allows_manual_capture( $order->get_payment_method() ) ) { - $captured = $order->get_meta( '_stripe_charge_captured', true ); + $captured = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED, true ); if ( 'no' === $captured ) { // To cancel a pre-auth, we need to refund the charge. diff --git a/includes/class-wc-stripe-webhook-handler.php b/includes/class-wc-stripe-webhook-handler.php index 132103d3bc..33a59d6b81 100644 --- a/includes/class-wc-stripe-webhook-handler.php +++ b/includes/class-wc-stripe-webhook-handler.php @@ -300,8 +300,8 @@ public function process_webhook_payment( $notification, $retry = true ) { if ( ! empty( $response->error ) ) { // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. if ( $this->is_no_such_customer_error( $response->error ) ) { - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); - $order->delete_meta_data( '_stripe_customer_id' ); + delete_user_option( $order->get_customer_id(), WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); $order->save(); } @@ -404,7 +404,7 @@ public function process_webhook_dispute( $notification ) { $message = __( 'A dispute was created for this order.', 'woocommerce-gateway-stripe' ); } - if ( ! $order->has_status( OrderStatus::CANCELLED ) && ! $order->get_meta( '_stripe_status_final', false ) ) { + if ( ! $order->has_status( OrderStatus::CANCELLED ) && ! $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_STATUS_FINAL, false ) ) { $order->update_status( OrderStatus::ON_HOLD, $message ); } else { $order->add_order_note( $message ); @@ -444,7 +444,7 @@ public function process_webhook_dispute_closed( $notification ) { if ( apply_filters( 'wc_stripe_webhook_dispute_change_order_status', true, $order, $notification ) ) { // Mark final so that order status is not overridden by out-of-sequence events. - $order->update_meta_data( '_stripe_status_final', true ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_STATUS_FINAL, true ); // Fail order if dispute is lost, or else revert to pre-dispute status. $order_status = 'lost' === $status ? OrderStatus::FAILED : $this->get_stripe_order_status_before_hold( $order ); @@ -485,10 +485,10 @@ public function process_webhook_capture( $notification ) { if ( WC_Stripe_Helper::payment_method_allows_manual_capture( $order->get_payment_method() ) ) { $charge = $order->get_transaction_id(); - $captured = $order->get_meta( '_stripe_charge_captured', true ); + $captured = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED, true ); if ( $charge && 'no' === $captured ) { - $order->update_meta_data( '_stripe_charge_captured', 'yes' ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED, 'yes' ); // Store other data such as fees $order->set_transaction_id( $notification->data->object->id ); @@ -623,7 +623,7 @@ public function process_webhook_charge_failed( $notification ) { } else { $message = __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ); } - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { + if ( ! $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_STATUS_FINAL, false ) ) { $order->update_status( OrderStatus::FAILED, $message ); } else { $order->add_order_note( $message ); @@ -660,7 +660,7 @@ public function process_webhook_source_canceled( $notification ) { } $message = __( 'This payment was cancelled.', 'woocommerce-gateway-stripe' ); - if ( ! $order->has_status( OrderStatus::CANCELLED ) && ! $order->get_meta( '_stripe_status_final', false ) ) { + if ( ! $order->has_status( OrderStatus::CANCELLED ) && ! $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_STATUS_FINAL, false ) ) { $order->update_status( OrderStatus::CANCELLED, $message ); } else { $order->add_order_note( $message ); @@ -694,8 +694,8 @@ public function process_webhook_refund( $notification ) { if ( 'stripe' === substr( (string) $order->get_payment_method(), 0, 6 ) ) { $charge = $order->get_transaction_id(); - $captured = $order->get_meta( '_stripe_charge_captured' ); - $refund_id = $order->get_meta( '_stripe_refund_id' ); + $captured = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED ); + $refund_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID ); $currency = $order->get_currency(); $raw_amount = $refund_object->amount; @@ -743,7 +743,7 @@ public function process_webhook_refund( $notification ) { WC_Stripe_Logger::log( $refund->get_error_message() ); } - $order->update_meta_data( '_stripe_refund_id', $refund_object->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID, $refund_object->id ); if ( isset( $refund_object->balance_transaction ) ) { $this->update_fees( $order, $refund_object->balance_transaction ); @@ -775,7 +775,7 @@ public function process_webhook_refund_updated( $notification ) { if ( 'stripe' === substr( (string) $order->get_payment_method(), 0, 6 ) ) { $charge = $order->get_transaction_id(); - $refund_id = $order->get_meta( '_stripe_refund_id' ); + $refund_id = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_REFUND_ID ); $currency = $order->get_currency(); $raw_amount = $refund_object->amount; @@ -858,7 +858,7 @@ public function process_review_opened( $notification ) { esc_html( $notification->data->object->reason ) ); - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) && ! $order->get_meta( '_stripe_status_final', false ) ) { + if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) && ! $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_STATUS_FINAL, false ) ) { $order->update_status( OrderStatus::ON_HOLD, $message ); } else { $order->add_order_note( $message ); @@ -893,8 +893,8 @@ public function process_review_closed( $notification ) { $message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ); // Only change the status if the charge was captured, status is not final, the order is on-hold and the review was approved. - if ( 'yes' === $order->get_meta( '_stripe_charge_captured' ) && - ! $order->get_meta( '_stripe_status_final', false ) && + if ( 'yes' === $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CHARGE_CAPTURED ) && + ! $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_STATUS_FINAL, false ) && $order->has_status( OrderStatus::ON_HOLD ) && ( ! empty( $notification->data->object->closed_reason ) && 'approved' === $notification->data->object->closed_reason ) && apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) @@ -1012,7 +1012,7 @@ public function process_payment_intent( $notification ) { } $order_id = $order->get_id(); - $payment_type_meta = $order->get_meta( '_stripe_upe_payment_type' ); + $payment_type_meta = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE ); $is_voucher_payment = in_array( $payment_type_meta, WC_Stripe_Payment_Methods::VOUCHER_PAYMENT_METHODS, true ); $is_wallet_payment = in_array( $payment_type_meta, WC_Stripe_Payment_Methods::WALLET_PAYMENT_METHODS, true ); @@ -1040,7 +1040,7 @@ public function process_payment_intent( $notification ) { WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" ); $process_webhook_async = apply_filters( 'wc_stripe_process_payment_intent_webhook_async', true, $order, $intent, $notification ); - $is_awaiting_action = $order->get_meta( '_stripe_upe_waiting_for_redirect' ) ?? false; + $is_awaiting_action = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_WAITING_FOR_REDIRECT ) ?? false; // Process the webhook now if it's for a voucher or wallet payment , or if filtered to process immediately and order is not awaiting action. if ( $is_voucher_payment || $is_wallet_payment || ( ! $process_webhook_async && ! $is_awaiting_action ) ) { @@ -1080,7 +1080,7 @@ public function process_payment_intent( $notification ) { $message = sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ); $status_update = []; - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { + if ( ! $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_STATUS_FINAL, false ) ) { $status_update['from'] = $order->get_status(); $status_update['to'] = OrderStatus::FAILED; $order->update_status( OrderStatus::FAILED, $message ); @@ -1134,7 +1134,7 @@ public function process_setup_intent( $notification ) { $message = sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ); $status_update = []; - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { + if ( ! $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_STATUS_FINAL, false ) ) { $status_update['from'] = $order->get_status(); $status_update['to'] = OrderStatus::FAILED; $order->update_status( OrderStatus::FAILED, $message ); diff --git a/includes/compat/class-wc-stripe-subscriptions-helper.php b/includes/compat/class-wc-stripe-subscriptions-helper.php index d4af69bbf8..d2774e339e 100644 --- a/includes/compat/class-wc-stripe-subscriptions-helper.php +++ b/includes/compat/class-wc-stripe-subscriptions-helper.php @@ -47,13 +47,13 @@ public static function get_some_detached_subscriptions() { $detached_subscriptions = []; foreach ( $subscriptions as $subscription ) { - $source_id = $subscription->get_meta( '_stripe_source_id' ); + $source_id = $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID ); if ( $source_id ) { $payment_method = WC_Stripe_API::get_payment_method( $source_id ); if ( empty( $payment_method->customer ) ) { $detached_subscriptions[] = [ 'id' => $subscription->get_id(), - 'customer_id' => $subscription->get_meta( '_stripe_customer_id' ), + 'customer_id' => $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ), 'change_payment_method_url' => $subscription->get_change_payment_method_url(), ]; if ( count( $detached_subscriptions ) >= 5 ) { diff --git a/includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php b/includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php index b0f8ec4303..ca3a66eb5e 100644 --- a/includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php +++ b/includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php @@ -37,7 +37,7 @@ class WC_Stripe_Subscriptions_Legacy_SEPA_Token_Update { * * @var string */ - const SOURCE_ID_META_KEY = '_stripe_source_id'; + const SOURCE_ID_META_KEY = WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID; /** * Gateway ID for the Updated SEPA payment method. diff --git a/includes/compat/trait-wc-stripe-pre-orders.php b/includes/compat/trait-wc-stripe-pre-orders.php index bc5946abec..c0ce5be6ed 100644 --- a/includes/compat/trait-wc-stripe-pre-orders.php +++ b/includes/compat/trait-wc-stripe-pre-orders.php @@ -173,7 +173,7 @@ class_exists( 'WC_Pre_Orders_Order' ) && * @param object $order */ public function remove_order_source_before_retry( $order ) { - $order->delete_meta_data( '_stripe_source_id' ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID ); $order->delete_meta_data( '_stripe_card_id' ); $order->save(); } diff --git a/includes/compat/trait-wc-stripe-subscriptions.php b/includes/compat/trait-wc-stripe-subscriptions.php index d724ee515e..cbeddbad7e 100644 --- a/includes/compat/trait-wc-stripe-subscriptions.php +++ b/includes/compat/trait-wc-stripe-subscriptions.php @@ -194,8 +194,8 @@ public function handle_upe_add_payment_method_success( $user_id, $payment_method $this->id, [ 'post_meta' => [ - '_stripe_source_id' => [ 'value' => $payment_method_object->id ], - '_stripe_customer_id' => [ 'value' => $stripe_customer->get_id() ], + WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID => [ 'value' => $payment_method_object->id ], + WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID => [ 'value' => $stripe_customer->get_id() ], ], ] ); @@ -612,12 +612,12 @@ public function maybe_update_source_on_subscription_order( $order, $source, $pay } foreach ( $subscriptions as $subscription ) { - $subscription->update_meta_data( '_stripe_customer_id', $source->customer ); + $subscription->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $source->customer ); if ( ! empty( $source->payment_method ) ) { - $subscription->update_meta_data( '_stripe_source_id', $source->payment_method ); + $subscription->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $source->payment_method ); } else { - $subscription->update_meta_data( '_stripe_source_id', $source->source ); + $subscription->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $source->source ); } // Update the payment method. @@ -635,12 +635,12 @@ public function maybe_update_source_on_subscription_order( $order, $source, $pay * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription */ public function delete_resubscribe_meta( $resubscribe_order ) { - $resubscribe_order->delete_meta_data( '_stripe_customer_id' ); - $resubscribe_order->delete_meta_data( '_stripe_source_id' ); + $resubscribe_order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); + $resubscribe_order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID ); // For BW compat will remove in future. $resubscribe_order->delete_meta_data( '_stripe_card_id' ); // Delete payment intent ID. - $resubscribe_order->delete_meta_data( '_stripe_intent_id' ); + $resubscribe_order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_INTENT_ID ); $this->delete_renewal_meta( $resubscribe_order ); $resubscribe_order->save(); } @@ -655,7 +655,7 @@ public function delete_renewal_meta( $renewal_order ) { WC_Stripe_Helper::delete_stripe_net( $renewal_order ); // Delete payment intent ID. - $renewal_order->delete_meta_data( '_stripe_intent_id' ); + $renewal_order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_INTENT_ID ); return $renewal_order; } @@ -669,8 +669,8 @@ public function delete_renewal_meta( $renewal_order ) { * @return void */ public function update_failing_payment_method( $subscription, $renewal_order ) { - $subscription->update_meta_data( '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); - $subscription->update_meta_data( '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); + $subscription->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $renewal_order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, true ) ); + $subscription->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $renewal_order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ) ); $subscription->save(); } @@ -686,25 +686,25 @@ public function update_failing_payment_method( $subscription, $renewal_order ) { */ public function add_subscription_payment_meta( $payment_meta, $subscription ) { $subscription_id = $subscription->get_id(); - $source_id = $subscription->get_meta( '_stripe_source_id', true ); + $source_id = $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ); // For BW compat will remove in future. if ( empty( $source_id ) ) { $source_id = $subscription->get_meta( '_stripe_card_id', true ); // Take this opportunity to update the key name. - $subscription->update_meta_data( '_stripe_source_id', $source_id ); + $subscription->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $source_id ); $subscription->delete_meta_data( '_stripe_card_id' ); $subscription->save(); } $payment_meta[ $this->id ] = [ 'post_meta' => [ - '_stripe_customer_id' => [ - 'value' => $subscription->get_meta( '_stripe_customer_id', true ), + WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID => [ + 'value' => $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, true ), 'label' => 'Stripe Customer ID', ], - '_stripe_source_id' => [ + WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID => [ 'value' => $source_id, 'label' => 'Stripe Payment Method ID', ], @@ -727,21 +727,21 @@ public function add_subscription_payment_meta( $payment_meta, $subscription ) { public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { if ( $this->id === $payment_method_id ) { - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { + if ( ! isset( $payment_meta['post_meta'][ WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ]['value'] ) || empty( $payment_meta['post_meta'][ WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ]['value'] ) ) { // Allow empty stripe customer id during subscription renewal. It will be added when processing payment if required. if ( ! isset( $_POST['wc_order_action'] ) || 'wcs_process_renewal' !== $_POST['wc_order_action'] ) { throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); } - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { + } elseif ( 0 !== strpos( $payment_meta['post_meta'][ WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ]['value'], 'cus_' ) ) { throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); } if ( - ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) && ( - 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'pm_' ) + ! empty( $payment_meta['post_meta'][WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID]['value'] ) && ( + 0 !== strpos( $payment_meta['post_meta'][WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID]['value'], 'card_' ) + && 0 !== strpos( $payment_meta['post_meta'][WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID]['value'], 'src_' ) + && 0 !== strpos( $payment_meta['post_meta'][WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID]['value'], 'pm_' ) ) ) { throw new Exception( __( 'Invalid payment method ID. A valid "Stripe Payment Method ID" must begin with "src_", "pm_", or "card_".', 'woocommerce-gateway-stripe' ) ); @@ -772,7 +772,7 @@ public function add_subscription_information_to_intent( $request, $order, $prepa // when creating the intent? It's called in process_subscription_payment though // so it's probably needed here too? // If we've already created a mandate for this order; use that. - $mandate = $order->get_meta( '_stripe_mandate_id', true ); + $mandate = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_MANDATE_ID, true ); if ( isset( $request['confirm'] ) && filter_var( $request['confirm'], FILTER_VALIDATE_BOOLEAN ) && ! empty( $mandate ) ) { $request['mandate'] = $mandate; unset( $request['setup_future_usage'] ); @@ -828,8 +828,8 @@ private function get_mandate_for_subscription( $order, $payment_method ) { continue; } - $mandate = $renewal_order->get_meta( '_stripe_mandate_id', true ); - $renewal_order_payment_method = $renewal_order->get_meta( '_stripe_source_id', true ); + $mandate = $renewal_order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_MANDATE_ID, true ); + $renewal_order_payment_method = $renewal_order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ); // Return from the most recent renewal order with a valid mandate. Mandate is created against a payment method // in Stripe so the payment method should also match to reuse the mandate. @@ -946,47 +946,47 @@ public function maybe_render_subscription_payment_method( $payment_method_to_dis return $payment_method_to_display; } - $stripe_source_id = $subscription->get_meta( '_stripe_source_id', true ); + $stripe_source_id = $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ); // For BW compat will remove in future. if ( empty( $stripe_source_id ) ) { $stripe_source_id = $subscription->get_meta( '_stripe_card_id', true ); // Take this opportunity to update the key name. - $subscription->update_meta_data( '_stripe_source_id', $stripe_source_id ); + $subscription->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $stripe_source_id ); $subscription->save(); } $stripe_customer = new WC_Stripe_Customer(); - $stripe_customer_id = $subscription->get_meta( '_stripe_customer_id', true ); + $stripe_customer_id = $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, true ); // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { $user_id = $customer_user; - $stripe_customer_id = get_user_option( '_stripe_customer_id', $user_id ); - $stripe_source_id = get_user_option( '_stripe_source_id', $user_id ); + $stripe_customer_id = get_user_option( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $user_id ); + $stripe_source_id = get_user_option( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $user_id ); // For BW compat will remove in future. if ( empty( $stripe_source_id ) ) { $stripe_source_id = get_user_option( '_stripe_card_id', $user_id ); // Take this opportunity to update the key name. - update_user_option( $user_id, '_stripe_source_id', $stripe_source_id, false ); + update_user_option( $user_id, WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $stripe_source_id, false ); } } // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->get_parent() ) { $parent_order = wc_get_order( $subscription->get_parent_id() ); - $stripe_customer_id = $parent_order->get_meta( '_stripe_customer_id', true ); - $stripe_source_id = $parent_order->get_meta( '_stripe_source_id', true ); + $stripe_customer_id = $parent_order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, true ); + $stripe_source_id = $parent_order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, true ); // For BW compat will remove in future. if ( empty( $stripe_source_id ) ) { $stripe_source_id = $parent_order->get_meta( '_stripe_card_id', true ); // Take this opportunity to update the key name. - $parent_order->update_meta_data( '_stripe_source_id', $stripe_source_id ); + $parent_order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $stripe_source_id ); $parent_order->save(); } } @@ -1224,7 +1224,7 @@ public function disable_subscription_edit_for_india( $editable, $order ) { if ( WC_Stripe_Subscriptions_Helper::is_subscriptions_enabled() && $this->is_subscription( $order ) && $parent_order - && ! empty( $parent_order->get_meta( '_stripe_mandate_id', true ) ) ) { + && ! empty( $parent_order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_MANDATE_ID, true ) ) ) { $editable = false; } diff --git a/includes/migrations/class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php b/includes/migrations/class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php index 387246555a..79e7f43914 100644 --- a/includes/migrations/class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php +++ b/includes/migrations/class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php @@ -190,7 +190,7 @@ public function maybe_migrate_before_renewal( $subscription_id ) { // It's possible that the Legacy SEPA gateway ID was updated by the repairing above, but that the Stripe account // hadn't been migrated from src_ to pm_ at the time. // Thus, we keep checking if the associated payment method is a source in subsequent renewals. - $subscription_source = $subscription->get_meta( '_stripe_source_id' ); + $subscription_source = $subscription->get_meta( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID ); if ( 0 === strpos( $subscription_source, 'src_' ) ) { $token_updater = new WC_Stripe_Subscriptions_Legacy_SEPA_Token_Update(); diff --git a/includes/payment-methods/class-wc-gateway-stripe-alipay.php b/includes/payment-methods/class-wc-gateway-stripe-alipay.php index d771d4dbd8..af3493b36e 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-alipay.php +++ b/includes/payment-methods/class-wc-gateway-stripe-alipay.php @@ -277,7 +277,7 @@ public function process_payment( $order_id, $retry = true, $force_save_save = fa throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); } - $order->update_meta_data( '_stripe_source_id', $response->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $response->id ); $order->save(); WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); diff --git a/includes/payment-methods/class-wc-gateway-stripe-bancontact.php b/includes/payment-methods/class-wc-gateway-stripe-bancontact.php index 6ce7d793ca..0a55b6f0cb 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-bancontact.php +++ b/includes/payment-methods/class-wc-gateway-stripe-bancontact.php @@ -265,7 +265,7 @@ public function process_payment( $order_id, $retry = true, $force_save_source = throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); } - $order->update_meta_data( '_stripe_source_id', $response->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $response->id ); $order->save(); WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); diff --git a/includes/payment-methods/class-wc-gateway-stripe-boleto.php b/includes/payment-methods/class-wc-gateway-stripe-boleto.php index 1fc40f4bc4..c024a1e51b 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-boleto.php +++ b/includes/payment-methods/class-wc-gateway-stripe-boleto.php @@ -113,7 +113,7 @@ public function update_unique_settings( WP_REST_Request $request ) { * @return mixed */ public function add_allowed_payment_processing_statuses( $allowed_statuses, $order ) { - if ( $this->stripe_id === $order->get_meta( '_stripe_upe_payment_type' ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses ) ) { + if ( $this->stripe_id === $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses ) ) { $allowed_statuses[] = OrderStatus::ON_HOLD; } diff --git a/includes/payment-methods/class-wc-gateway-stripe-eps.php b/includes/payment-methods/class-wc-gateway-stripe-eps.php index cf878df4c5..b614f1f407 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-eps.php +++ b/includes/payment-methods/class-wc-gateway-stripe-eps.php @@ -264,7 +264,7 @@ public function process_payment( $order_id, $retry = true, $force_save_source = throw new Exception( $response->error->message ); } - $order->update_meta_data( '_stripe_source_id', $response->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $response->id ); $order->save(); WC_Stripe_Logger::log( 'Info: Redirecting to EPS...' ); diff --git a/includes/payment-methods/class-wc-gateway-stripe-giropay.php b/includes/payment-methods/class-wc-gateway-stripe-giropay.php index f2753048e9..064715b3ce 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-giropay.php +++ b/includes/payment-methods/class-wc-gateway-stripe-giropay.php @@ -260,7 +260,7 @@ public function process_payment( $order_id, $retry = true, $force_save_source = throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); } - $order->update_meta_data( '_stripe_source_id', $response->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $response->id ); $order->save(); WC_Stripe_Logger::log( 'Info: Redirecting to giropay...' ); diff --git a/includes/payment-methods/class-wc-gateway-stripe-ideal.php b/includes/payment-methods/class-wc-gateway-stripe-ideal.php index 82d79045cd..ee7b41c5c0 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-ideal.php +++ b/includes/payment-methods/class-wc-gateway-stripe-ideal.php @@ -264,7 +264,7 @@ public function process_payment( $order_id, $retry = true, $force_save_source = throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); } - $order->update_meta_data( '_stripe_source_id', $response->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $response->id ); $order->save(); WC_Stripe_Logger::log( 'Info: Redirecting to iDEAL...' ); diff --git a/includes/payment-methods/class-wc-gateway-stripe-multibanco.php b/includes/payment-methods/class-wc-gateway-stripe-multibanco.php index a502483902..ebe7d22ce3 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-multibanco.php +++ b/includes/payment-methods/class-wc-gateway-stripe-multibanco.php @@ -248,7 +248,7 @@ public function get_instructions( $order, $plain_text = false ) { $order = wc_get_order( $order ); } - $data = $order->get_meta( '_stripe_multibanco' ); + $data = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_MULTIBANCO ); if ( $plain_text ) { esc_html_e( 'MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe' ) . "\n\n"; @@ -299,7 +299,7 @@ public function save_instructions( $order, $source_object ) { $order_id = $order->get_id(); - $order->update_meta_data( '_stripe_multibanco', $data ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_MULTIBANCO, $data ); } /** @@ -364,7 +364,7 @@ public function process_payment( $order_id, $retry = true, $force_save_source = throw new Exception( $response->error->message ); } - $order->update_meta_data( '_stripe_source_id', $response->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $response->id ); $order->save(); $this->save_instructions( $order, $response ); diff --git a/includes/payment-methods/class-wc-gateway-stripe-oxxo.php b/includes/payment-methods/class-wc-gateway-stripe-oxxo.php index b695ed2b0e..c109111aab 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-oxxo.php +++ b/includes/payment-methods/class-wc-gateway-stripe-oxxo.php @@ -67,7 +67,7 @@ public function __construct() { * @return mixed */ public function add_allowed_payment_processing_statuses( $allowed_statuses, $order ) { - if ( $this->stripe_id === $order->get_meta( '_stripe_upe_payment_type' ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses, true ) ) { + if ( $this->stripe_id === $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses, true ) ) { $allowed_statuses[] = OrderStatus::ON_HOLD; } diff --git a/includes/payment-methods/class-wc-gateway-stripe-p24.php b/includes/payment-methods/class-wc-gateway-stripe-p24.php index 8c3eab980a..1dd0b4ba9c 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-p24.php +++ b/includes/payment-methods/class-wc-gateway-stripe-p24.php @@ -261,7 +261,7 @@ public function process_payment( $order_id, $retry = true, $force_save_source = throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); } - $order->update_meta_data( '_stripe_source_id', $response->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $response->id ); $order->save(); WC_Stripe_Logger::log( 'Info: Redirecting to P24...' ); diff --git a/includes/payment-methods/class-wc-gateway-stripe-sepa.php b/includes/payment-methods/class-wc-gateway-stripe-sepa.php index 0b7cd93ae9..8315dc8172 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-sepa.php +++ b/includes/payment-methods/class-wc-gateway-stripe-sepa.php @@ -325,8 +325,8 @@ public function process_payment( $order_id, $retry = true, $force_save_source = if ( ! empty( $response->error ) ) { // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. if ( $this->is_no_such_customer_error( $response->error ) ) { - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); - $order->delete_meta_data( '_stripe_customer_id' ); + delete_user_option( $order->get_customer_id(), WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID ); $order->save(); } diff --git a/includes/payment-methods/class-wc-gateway-stripe-sofort.php b/includes/payment-methods/class-wc-gateway-stripe-sofort.php index c916d5248a..c0e8379054 100644 --- a/includes/payment-methods/class-wc-gateway-stripe-sofort.php +++ b/includes/payment-methods/class-wc-gateway-stripe-sofort.php @@ -277,7 +277,7 @@ public function process_payment( $order_id, $retry = true, $force_save_source = throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); } - $order->update_meta_data( '_stripe_source_id', $response->id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $response->id ); $order->save(); WC_Stripe_Logger::log( 'Info: Redirecting to Sofort...' ); diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php index 68e30e2ce8..c39bf8fad7 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -363,7 +363,7 @@ public function set_cookie_on_current_request( $cookie ) { * @return array|bool */ public function can_refund_order( $order ) { - $upe_payment_type = $order->get_meta( '_stripe_upe_payment_type' ); + $upe_payment_type = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE ); if ( ! $upe_payment_type ) { return true; @@ -949,13 +949,13 @@ public function process_payment( $order_id, $retry = true, $force_save_source = WC_Stripe_Helper::add_payment_intent_to_order( $payment_intent_id, $order ); $order->update_status( OrderStatus::PENDING, __( 'Awaiting payment.', 'woocommerce-gateway-stripe' ) ); - $order->update_meta_data( '_stripe_upe_payment_type', $selected_upe_payment_type ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE, $selected_upe_payment_type ); // TODO: This is a stop-gap to fix a critical issue, see // https://github.com/woocommerce/woocommerce-gateway-stripe/issues/2536. It would // be better if we removed the need for additional meta data in favor of refactoring // this part of the payment processing. - $order->update_meta_data( '_stripe_upe_waiting_for_redirect', true ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_WAITING_FOR_REDIRECT, true ); $order->save(); @@ -1142,7 +1142,7 @@ private function process_payment_with_payment_method( int $order_id ) { WC_Stripe_Helper::set_payment_awaiting_action( $order, false ); // Prevent processing the payment intent webhooks while also processing the redirect payment (also prevents duplicate Stripe meta stored on the order). - $order->update_meta_data( '_stripe_upe_waiting_for_redirect', true ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_WAITING_FOR_REDIRECT, true ); $order->save(); $redirect = $this->get_redirect_url( $this->get_return_url( $order ), $payment_intent, $payment_information, $order, $payment_needed ); @@ -1592,7 +1592,7 @@ public function process_upe_redirect_payment( $order_id, $intent_id, $save_payme return; } - if ( $order->get_meta( '_stripe_upe_redirect_processed', true ) ) { + if ( $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_REDIRECT_PROCESSED, true ) ) { return; } @@ -1693,13 +1693,13 @@ public function process_order_for_confirmed_intent( $order, $intent_id, $save_pa $this->save_intent_to_order( $order, $intent ); $this->set_payment_method_title_for_order( $order, $payment_method_type ); - $order->update_meta_data( '_stripe_upe_redirect_processed', true ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_REDIRECT_PROCESSED, true ); // TODO: This is a stop-gap to fix a critical issue, see // https://github.com/woocommerce/woocommerce-gateway-stripe/issues/2536. It would // be better if we removed the need for additional meta data in favor of refactoring // this part of the payment processing. - $order->delete_meta_data( '_stripe_upe_waiting_for_redirect' ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_WAITING_FOR_REDIRECT ); /** * This meta is to prevent stores with short hold stock settings from cancelling orders while waiting for payment to be finalised by Stripe or the customer (i.e. completing 3DS or payment redirects). @@ -1736,10 +1736,10 @@ public function prepare_payment_method( $payment_method ) { */ public function save_payment_method_to_order( $order, $payment_method ) { if ( $payment_method->customer ) { - $order->update_meta_data( '_stripe_customer_id', $payment_method->customer ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $payment_method->customer ); } // Save the payment method id as `source_id`, because we use both `sources` and `payment_methods` APIs. - $order->update_meta_data( '_stripe_source_id', $payment_method->payment_method ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $payment_method->payment_method ); if ( is_callable( [ $order, 'save' ] ) ) { $order->save(); @@ -2602,7 +2602,7 @@ private function maybe_set_preferred_card_brand_for_order( WC_Order $order, $pay $preferred_brand = $payment_method->card->networks->preferred ?? null; if ( WC_Stripe_Co_Branded_CC_Compatibility::is_wc_supported() && $preferred_brand ) { - $order->update_meta_data( '_stripe_card_brand', $preferred_brand ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CARD_BRAND, $preferred_brand ); $order->save_meta_data(); if ( function_exists( 'wc_admin_record_tracks_event' ) ) { @@ -2765,7 +2765,7 @@ protected function handle_saving_payment_method( WC_Order $order, $payment_metho */ public function set_payment_method_id_for_order( WC_Order $order, string $payment_method_id ) { // Save the payment method id as `source_id`, because we use both `sources` and `payment_methods` APIs. - $order->update_meta_data( '_stripe_source_id', $payment_method_id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $payment_method_id ); $order->save_meta_data(); } @@ -2776,7 +2776,7 @@ public function set_payment_method_id_for_order( WC_Order $order, string $paymen * @param string $payment_method_id The value to be set. */ public function set_payment_method_id_for_subscription( $subscription, string $payment_method_id ) { - $subscription->update_meta_data( '_stripe_source_id', $payment_method_id ); + $subscription->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_SOURCE_ID, $payment_method_id ); $subscription->save_meta_data(); } @@ -2789,7 +2789,7 @@ public function set_payment_method_id_for_subscription( $subscription, string $p * @param string $customer_id The value to be set. */ public function set_customer_id_for_order( WC_Order $order, string $customer_id ) { - $order->update_meta_data( '_stripe_customer_id', $customer_id ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $customer_id ); $order->save_meta_data(); } @@ -2802,7 +2802,7 @@ public function set_customer_id_for_order( WC_Order $order, string $customer_id * @param string $customer_id The value to be set. */ public function set_customer_id_for_subscription( $subscription, string $customer_id ) { - $subscription->update_meta_data( '_stripe_customer_id', $customer_id ); + $subscription->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CUSTOMER_ID, $customer_id ); $subscription->save_meta_data(); } @@ -2813,7 +2813,7 @@ public function set_customer_id_for_subscription( $subscription, string $custome * @param string $selected_payment_type The selected payment type. */ private function set_selected_payment_type_for_order( WC_Order $order, string $selected_payment_type ) { - $order->update_meta_data( '_stripe_upe_payment_type', $selected_payment_type ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE, $selected_payment_type ); $order->save_meta_data(); } /** diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-boleto.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-boleto.php index a4a88328db..30b014d5a2 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-boleto.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-boleto.php @@ -47,7 +47,7 @@ public function __construct() { * @return mixed */ public function add_allowed_payment_processing_statuses( $allowed_statuses, $order ) { - if ( WC_Stripe_Payment_Methods::BOLETO === $order->get_meta( '_stripe_upe_payment_type' ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses, true ) ) { + if ( WC_Stripe_Payment_Methods::BOLETO === $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses, true ) ) { $allowed_statuses[] = OrderStatus::ON_HOLD; } diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-multibanco.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-multibanco.php index 40a746d38e..dc99f52e96 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-multibanco.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-multibanco.php @@ -73,7 +73,7 @@ public function email_instructions( $order, $sent_to_admin, $plain_text = false * @param bool $plain_text */ public function get_instructions( $order, $plain_text = false ) { - $data = $order->get_meta( '_stripe_multibanco' ); + $data = $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_MULTIBANCO ); if ( ! $data ) { return; } @@ -128,7 +128,7 @@ public function save_instructions( $order, $payment_intent ) { 'reference' => $payment_intent->next_action->multibanco_display_details->reference, ]; - $order->update_meta_data( '_stripe_multibanco', $data ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_MULTIBANCO, $data ); } /** @@ -140,7 +140,7 @@ public function save_instructions( $order, $payment_intent ) { * @return mixed */ public function add_allowed_payment_processing_statuses( $allowed_statuses, $order ) { - if ( WC_Stripe_Payment_Methods::MULTIBANCO === $order->get_meta( '_stripe_upe_payment_type' ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses, true ) ) { + if ( WC_Stripe_Payment_Methods::MULTIBANCO === $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses, true ) ) { $allowed_statuses[] = OrderStatus::ON_HOLD; } diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-oxxo.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-oxxo.php index f30b59a8f6..2543eb6ecd 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-oxxo.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-oxxo.php @@ -47,7 +47,7 @@ public function __construct() { * @return mixed */ public function add_allowed_payment_processing_statuses( $allowed_statuses, $order ) { - if ( WC_Stripe_Payment_Methods::OXXO === $order->get_meta( '_stripe_upe_payment_type' ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses, true ) ) { + if ( WC_Stripe_Payment_Methods::OXXO === $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_UPE_PAYMENT_TYPE ) && ! in_array( OrderStatus::ON_HOLD, $allowed_statuses, true ) ) { $allowed_statuses[] = OrderStatus::ON_HOLD; } From 31f46df3af7517b6fa0a02cb9f3781c2efaa341c Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 13 May 2025 10:13:19 -0300 Subject: [PATCH 6/6] Deprecating additional metas from the helper class --- includes/class-wc-stripe-helper.php | 32 ++++++++++++++++------ includes/class-wc-stripe-order-handler.php | 2 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/includes/class-wc-stripe-helper.php b/includes/class-wc-stripe-helper.php index 1c9950c477..6c565e90aa 100644 --- a/includes/class-wc-stripe-helper.php +++ b/includes/class-wc-stripe-helper.php @@ -12,12 +12,28 @@ * @since 4.0.0 */ class WC_Stripe_Helper { - const SETTINGS_OPTION = 'woocommerce_stripe_settings'; - const LEGACY_META_NAME_FEE = 'Stripe Fee'; - const LEGACY_META_NAME_NET = 'Net Revenue From Stripe'; - const META_NAME_STRIPE_CURRENCY = '_stripe_currency'; + const SETTINGS_OPTION = 'woocommerce_stripe_settings'; + const LEGACY_META_NAME_FEE = 'Stripe Fee'; + const LEGACY_META_NAME_NET = 'Net Revenue From Stripe'; + + /** + * Meta key for the Stripe awaiting action identifier. + * + * @var string + * + * @deprecated 9.5.0 Use WC_Stripe_Order_Metas::PAYMENT_AWAITING_ACTION_META instead. + */ const PAYMENT_AWAITING_ACTION_META = '_stripe_payment_awaiting_action'; + /** + * Meta key for the Stripe currency. + * + * @var string + * + * @deprecated 9.5.0 Use WC_Stripe_Order_Metas::META_STRIPE_CURRENCY instead. + */ + const META_NAME_STRIPE_CURRENCY = '_stripe_currency'; + /** * Meta key for the Stripe fee amount. * @@ -88,7 +104,7 @@ public static function get_stripe_currency( $order = null ) { return false; } - return $order->get_meta( self::META_NAME_STRIPE_CURRENCY, true ); + return $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_CURRENCY, true ); } /** @@ -103,7 +119,7 @@ public static function update_stripe_currency( $order, $currency ) { return false; } - $order->update_meta_data( self::META_NAME_STRIPE_CURRENCY, $currency ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_CURRENCY, $currency ); } /** @@ -1437,7 +1453,7 @@ public static function get_stripe_gateway_ids() { * @return void */ public static function set_payment_awaiting_action( $order, $save = true ) { - $order->update_meta_data( self::PAYMENT_AWAITING_ACTION_META, wc_bool_to_string( true ) ); + $order->update_meta_data( WC_Stripe_Order_Metas::META_STRIPE_PAYMENT_AWAITING_ACTION, wc_bool_to_string( true ) ); if ( $save ) { $order->save(); @@ -1453,7 +1469,7 @@ public static function set_payment_awaiting_action( $order, $save = true ) { * @return void */ public static function remove_payment_awaiting_action( $order, $save = true ) { - $order->delete_meta_data( self::PAYMENT_AWAITING_ACTION_META ); + $order->delete_meta_data( WC_Stripe_Order_Metas::META_STRIPE_PAYMENT_AWAITING_ACTION ); if ( $save ) { $order->save(); diff --git a/includes/class-wc-stripe-order-handler.php b/includes/class-wc-stripe-order-handler.php index ec61e082b1..1b6f1eaf2d 100644 --- a/includes/class-wc-stripe-order-handler.php +++ b/includes/class-wc-stripe-order-handler.php @@ -470,7 +470,7 @@ public function prevent_cancelling_orders_awaiting_action( $cancel_order, $order } // If the order is awaiting action and was modified within the last day, don't cancel it. - if ( wc_string_to_bool( $order->get_meta( WC_Stripe_Helper::PAYMENT_AWAITING_ACTION_META, true ) ) && $order->get_date_modified( 'edit' )->getTimestamp() > strtotime( '-1 day' ) ) { + if ( wc_string_to_bool( $order->get_meta( WC_Stripe_Order_Metas::META_STRIPE_PAYMENT_AWAITING_ACTION, true ) ) && $order->get_date_modified( 'edit' )->getTimestamp() > strtotime( '-1 day' ) ) { $cancel_order = false; }