Skip to content

Commit

Permalink
Fix legacy method names in order meta (#2934)
Browse files Browse the repository at this point in the history
* revert subscription check in multibanco

* add gateways to the WC gateways list as before.
- they were removed in PR#2839

* hide other stripe methods from payment settings page with css

* fix ordering in checkout page

* rename file and ignore css lint

* Use a separate method for deciding whether to include Multibanco in the gateways

* Don't include multibanco through the available gateways filter for UPE

---------

Co-authored-by: Danae Millan <[email protected]>
  • Loading branch information
Mayisha and a-danae authored Feb 25, 2024
1 parent 412e10c commit 8f0db94
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ assets/css/stripe-styles.css
assets/css/stripe-styles.scss
assets/css/stripe-link.css
assets/css/stripe-link.scss
assets/css/payment-methods-styles.css
assets/css/payment-methods-styles.scss
1 change: 1 addition & 0 deletions assets/css/payment-methods-styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/css/payment-methods-styles.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions assets/css/payment-methods-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
table.wc_gateways {
tr[data-gateway_id="stripe_alipay"],
tr[data-gateway_id="stripe_bancontact"],
tr[data-gateway_id="stripe_boleto"],
tr[data-gateway_id="stripe_eps"],
tr[data-gateway_id="stripe_giropay"],
tr[data-gateway_id="stripe_ideal"],
tr[data-gateway_id="stripe_multibanco"],
tr[data-gateway_id="stripe_oxxo"],
tr[data-gateway_id="stripe_p24"],
tr[data-gateway_id="stripe_sofort"],
tr[data-gateway_id="stripe_sepa"] {
display: none;
}
}
19 changes: 16 additions & 3 deletions includes/class-wc-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function __construct() {
}

// Hooks.
add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'payment_scripts' ] );
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] );
add_action( 'woocommerce_admin_order_totals_after_total', [ $this, 'display_order_fee' ] );
Expand All @@ -139,6 +140,15 @@ public function __construct() {
add_action( 'admin_notices', [ $this, 'display_errors' ], 9999 );
}

/**
* Load admin scripts.
*/
public function admin_scripts() {
wp_register_style( 'payment-methods-styles', plugins_url( 'assets/css/payment-methods-styles.css', WC_STRIPE_MAIN_FILE ), [], WC_STRIPE_VERSION );
wp_enqueue_style( 'payment-methods-styles' );

}

/**
* Checks if gateway should be available to use.
*
Expand Down Expand Up @@ -657,9 +667,12 @@ public function prepare_order_pay_page( $gateways ) {
* @return WC_Payment_Gateway[] The same list if UPE is disabled or a list including the available legacy payment methods.
*/
public function get_available_payment_gateways( $gateways ) {
// We need to include the payment methods when UPE is disabled, return the same list when UPE is enabled.
if ( WC_Stripe_Feature_Flags::is_upe_checkout_enabled() ) {
return $gateways;
// Unset the stripe methods from the array first, then place it in the correct position below
// as set in `stripe_ordered_payment_method_ids`.
foreach ( $gateways as $key => $gateway ) {
if ( 0 === strpos( $key, 'stripe_' ) ) {
unset( $gateways[ $key ] );
}
}

$legacy_enabled_gateways = WC_Stripe_Helper::get_legacy_enabled_payment_methods();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ public function is_available() {
return false;
}

// If cart contains a subscription or pre-order item, don't show Multibanco on checkout.
if ( $this->is_subscription_item_in_cart() || $this->is_pre_order_item_in_cart() ) {
return false;
}

return parent::is_available();
}

Expand Down
29 changes: 1 addition & 28 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function __construct() {
}

add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );

// This is an ActionScheduler action.
add_action( self::UPDATE_SAVED_PAYMENT_METHOD, [ $this, 'update_saved_payment_method' ], 10, 2 );
Expand All @@ -201,34 +202,6 @@ public function __construct() {

// Update the current request logged_in cookie after a guest user is created to avoid nonce inconsistencies.
add_action( 'set_logged_in_cookie', [ $this, 'set_cookie_on_current_request' ] );

add_filter( 'woocommerce_available_payment_gateways', [ $this, 'get_available_payment_gateways' ] );
}

/**
* Include Multibanco in the list of payment methods.
* As we are not registering Multibanco to show in the payment settings page and Multibanco is not a UPE payment method,
* we need to include it here separately so that it's available in the checkout, pay for order, add payment method etc. pages.
*
* @param WC_Payment_Gateway[] $gateways A list of all available gateways on the payments settings page.
* @return WC_Payment_Gateway[] The same list if Multibanco is disabled or a list including the Multibanco method.
*/
public function get_available_payment_gateways( $gateways ) {
$stripe_index = array_search( 'stripe', array_keys( $gateways ), true );
$gateways_upto_stripe = array_slice( $gateways, 0, $stripe_index + 1 );
$gateways_after_stripe = array_slice( $gateways, $stripe_index + 1 );

$multibanco_gateway = WC_Stripe_Helper::get_legacy_payment_method( 'stripe_multibanco' );
$gateway_to_add = [];
if ( $multibanco_gateway && $multibanco_gateway->is_available() ) {
if ( ! is_add_payment_method_page() ) {
$gateway_to_add[ $multibanco_gateway->id ] = $multibanco_gateway;
} elseif ( $gateway->supports( 'add_payment_method' ) || $gateway->supports( 'tokenization' ) ) {
$gateway_to_add[ $multibanco_gateway->id ] = $multibanco_gateway;
}
}

return array_merge( $gateways_upto_stripe, $gateway_to_add, $gateways_after_stripe );
}

/**
Expand Down
24 changes: 23 additions & 1 deletion woocommerce-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public function plugin_row_meta( $links, $file ) {
}

/**
* Add the main Stripe gateway to WooCommerce.
* Add the gateways to WooCommerce.
*
* @since 1.0.0
* @version 5.6.0
Expand All @@ -392,8 +392,30 @@ public function add_gateways( $methods ) {
unset( $upe_payment_methods['card'] );

$methods = array_merge( $methods, $upe_payment_methods );
} else {
// These payment gateways will not be included in the gateway list when UPE is enabled:
$methods[] = WC_Gateway_Stripe_Alipay::class;
$methods[] = WC_Gateway_Stripe_Sepa::class;
$methods[] = WC_Gateway_Stripe_Giropay::class;
$methods[] = WC_Gateway_Stripe_Ideal::class;
$methods[] = WC_Gateway_Stripe_Bancontact::class;
$methods[] = WC_Gateway_Stripe_Eps::class;
$methods[] = WC_Gateway_Stripe_P24::class;
$methods[] = WC_Gateway_Stripe_Boleto::class;
$methods[] = WC_Gateway_Stripe_Oxxo::class;

/** Show Sofort if it's already enabled. Hide from the new merchants and keep it for the old ones who are already using this gateway, until we remove it completely.
* Stripe is deprecating Sofort https://support.stripe.com/questions/sofort-is-being-deprecated-as-a-standalone-payment-method.
*/
$sofort_settings = get_option( 'woocommerce_stripe_sofort_settings', [] );
if ( isset( $sofort_settings['enabled'] ) && 'yes' === $sofort_settings['enabled'] ) {
$methods[] = WC_Gateway_Stripe_Sofort::class;
}
}

// Multibanco will always be added to the gateway list, regardless if UPE is enabled or disabled:
$methods[] = WC_Gateway_Stripe_Multibanco::class;

return $methods;
}

Expand Down

0 comments on commit 8f0db94

Please sign in to comment.