Skip to content

Commit

Permalink
Move Alipay and Multibanco inside Stripe settings when UPE is disabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayisha authored Feb 1, 2024
1 parent b02fd9f commit be061a2
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 30 deletions.
1 change: 1 addition & 0 deletions client/payment-method-icons/alipay/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions client/payment-method-icons/alipay/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import styled from '@emotion/styled';
import IconWithShell from '../styles/icon-with-shell';
import icon from './icon.svg';

const Wrapper = styled( IconWithShell )`
padding-top: 4px;
padding-bottom: 4px;
`;

const AlipayIcon = ( props ) => <Wrapper { ...props } src={ icon } />;

export default AlipayIcon;
1 change: 1 addition & 0 deletions client/payment-method-icons/multibanco/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions client/payment-method-icons/multibanco/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import styled from '@emotion/styled';
import IconWithShell from '../styles/icon-with-shell';
import icon from './icon.svg';

const Wrapper = styled( IconWithShell )`
padding-top: 4px;
padding-bottom: 4px;
`;

const MultibancoIcon = ( props ) => <Wrapper { ...props } src={ icon } />;

export default MultibancoIcon;
6 changes: 4 additions & 2 deletions client/payment-methods-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import IdealIcon from './payment-method-icons/ideal';
import P24Icon from './payment-method-icons/p24';
import BoletoIcon from './payment-method-icons/boleto';
import OxxoIcon from './payment-method-icons/oxxo';
import AlipayIcon from './payment-method-icons/alipay';
import MultibancoIcon from './payment-method-icons/multibanco';

export default {
card: {
Expand Down Expand Up @@ -140,7 +142,7 @@ export default {
'Alipay is a popular wallet in China, operated by Ant Financial Services Group, a financial services provider affiliated with Alibaba.',
'woocommerce-gateway-stripe'
),
Icon: () => null,
Icon: AlipayIcon,
currencies: [
'AUD',
'CAD',
Expand All @@ -162,7 +164,7 @@ export default {
'Multibanco is an interbank network that links the ATMs of all major banks in Portugal, allowing customers to pay through either their ATM or online banking environment.',
'woocommerce-gateway-stripe'
),
Icon: () => null,
Icon: MultibancoIcon,
currencies: [ 'EUR' ],
capability: undefined,
},
Expand Down
22 changes: 9 additions & 13 deletions includes/class-wc-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,19 +663,15 @@ public function get_available_payment_gateways( $gateways ) {
}

$legacy_enabled_gateways = WC_Stripe_Helper::get_legacy_enabled_payment_methods();
$stripe_ordered_payment_method_ids = $this->get_option( 'stripe_legacy_method_order', [] );

// If the legacy method order is not set, consider the default order.
if ( empty( $stripe_ordered_payment_method_ids ) ) {
$payment_method_classes = WC_Stripe_Helper::get_legacy_payment_method_classes();
$stripe_ordered_payment_method_ids = array_map(
function( $payment_method_class ) {
return $payment_method_class::ID;
},
$payment_method_classes
);
$stripe_ordered_payment_method_ids = array_merge( [ 'stripe' ], $stripe_ordered_payment_method_ids );
}
$stripe_ordered_payment_method_ids = WC_Stripe_Helper::get_legacy_available_payment_method_ids();

// Map the IDs of the Stripe payment methods to match the ones expected in the $gateways array.
$stripe_ordered_payment_method_ids = array_map(
function( $id ) {
return 'card' === $id ? 'stripe' : 'stripe_' . $id;
},
$stripe_ordered_payment_method_ids
);

// If Stripe is not found in the $gateways array, but other legacy methods are enabled,
// they will be placed on the top in their saved order, followed by other gateways.
Expand Down
33 changes: 25 additions & 8 deletions includes/class-wc-stripe-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,16 @@ public static function get_settings( $method = null, $setting = null ) {
*/
public static function get_legacy_payment_method_classes() {
$payment_method_classes = [
WC_Gateway_Stripe_Alipay::class,
WC_Gateway_Stripe_Bancontact::class,
WC_Gateway_Stripe_Boleto::class,
WC_Gateway_Stripe_EPS::class,
WC_Gateway_Stripe_Giropay::class,
WC_Gateway_Stripe_Ideal::class,
WC_Gateway_Stripe_Multibanco::class,
WC_Gateway_Stripe_Oxxo::class,
WC_Gateway_Stripe_p24::class,
WC_Gateway_Stripe_Sepa::class,
WC_Gateway_Stripe_Boleto::class,
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.
Expand Down Expand Up @@ -419,29 +421,44 @@ public static function get_legacy_payment_method( $id ) {
*/
public static function get_legacy_available_payment_method_ids() {
$stripe_settings = get_option( 'woocommerce_stripe_settings', [] );
$payment_method_classes = self::get_legacy_payment_method_classes();
$ordered_payment_method_ids = isset( $stripe_settings['stripe_legacy_method_order'] ) ? $stripe_settings['stripe_legacy_method_order'] : [];

// If the legacy method order is not set, return the default order.
if ( ! empty( $ordered_payment_method_ids ) ) {
$payment_method_ids = array_map(
function( $payment_method_class ) {
if ( 'stripe' === $payment_method_class ) {
function( $payment_method_id ) {
if ( 'stripe' === $payment_method_id ) {
return 'card';
} else {
return str_replace( 'stripe_', '', $payment_method_class );
return str_replace( 'stripe_', '', $payment_method_id );
}
},
$ordered_payment_method_ids
);

// Cover the edge case when new Stripe payment methods are added to the plugin which do not exist in
// the `stripe_legacy_method_order` option.
if ( count( $payment_method_ids ) - 1 !== count( $payment_method_classes ) ) {
foreach ( $payment_method_classes as $payment_method_class ) {
$id = str_replace( 'stripe_', '', $payment_method_class::ID );
if ( ! in_array( $id, $payment_method_ids, true ) ) {
$payment_method_ids[] = $id;
}
}

// Update the `stripe_legacy_method_order` option with the new order including missing payment methods from the option.
$stripe_settings['stripe_legacy_method_order'] = $payment_method_ids;
update_option( 'woocommerce_stripe_settings', $stripe_settings );
}
} else {
$payment_method_classes = self::get_legacy_payment_method_classes();
$payment_method_ids = array_map(
$payment_method_ids = array_map(
function( $payment_method_class ) {
return str_replace( 'stripe_', '', $payment_method_class::ID );
},
$payment_method_classes
);
$payment_method_ids = array_merge( [ 'card' ], $payment_method_ids );
$payment_method_ids = array_merge( [ 'card' ], $payment_method_ids );
}

return $payment_method_ids;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* @since 4.1.0
*/
class WC_Gateway_Stripe_Multibanco extends WC_Stripe_Payment_Gateway {

const ID = 'stripe_multibanco';

/**
* Notices (array)
*
Expand Down Expand Up @@ -57,7 +60,7 @@ class WC_Gateway_Stripe_Multibanco extends WC_Stripe_Payment_Gateway {
* Constructor
*/
public function __construct() {
$this->id = 'stripe_multibanco';
$this->id = self::ID;
$this->method_title = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' );
$this->method_description = sprintf(
/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@ class WC_REST_Stripe_Payment_Gateway_Controller_Test extends WP_UnitTestCase {
*/
private $gateway;

/**
* @var UPE_Test_Helper
*/
private $upe_helper;

/**
* Pre-test setup
*/
public function set_up() {
parent::set_up();

// As this settings is available for Alipay and Multibanco when UPE is enabled.
$this->upe_helper = new UPE_Test_Helper();
$this->upe_helper->enable_upe_feature_flag();
update_option( 'woocommerce_stripe_settings', [ 'upe_checkout_experience_enabled' => 'yes' ] );
$this->upe_helper->reload_payment_gateways();

$this->gateway = WC()->payment_gateways()->payment_gateways()[ WC_Gateway_Stripe_Alipay::ID ];

if ( version_compare( WC_VERSION, '3.4.0', '<' ) ) {
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/test-wc-stripe-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ public function test_get_payment_method_from_intent() {

public function test_get_legacy_payment_methods() {
$result = WC_Stripe_Helper::get_legacy_payment_methods();
$this->assertEquals( [ 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_p24', 'stripe_sepa', 'stripe_boleto', 'stripe_oxxo' ], array_keys( $result ) );
$this->assertEquals( [ 'stripe_alipay', 'stripe_bancontact', 'stripe_boleto', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_oxxo', 'stripe_p24', 'stripe_sepa' ], array_keys( $result ) );
}

public function test_get_legacy_available_payment_method_ids() {
$result = WC_Stripe_Helper::get_legacy_available_payment_method_ids();
$this->assertEquals( [ 'card', 'bancontact', 'eps', 'giropay', 'ideal', 'p24', 'sepa', 'boleto', 'oxxo' ], $result );
$this->assertEquals( [ 'card', 'alipay', 'bancontact', 'boleto', 'eps', 'giropay', 'ideal', 'multibanco', 'oxxo', 'p24', 'sepa' ], $result );
}

public function test_get_legacy_enabled_payment_methods() {
Expand Down
10 changes: 6 additions & 4 deletions woocommerce-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,19 @@ public function plugin_row_meta( $links, $file ) {
}

/**
* Add the gateways to WooCommerce.
* Add the main Stripe gateway to WooCommerce.
*
* @since 1.0.0
* @version 5.6.0
*/
public function add_gateways( $methods ) {
$methods[] = $this->get_main_stripe_gateway();

// These payment gateways will always be visible, regardless if UPE is enabled or disabled:
$methods[] = WC_Gateway_Stripe_Alipay::class;
$methods[] = WC_Gateway_Stripe_Multibanco::class;
// These payment gateways will be visible in the main settings page, if UPE enabled.
if ( WC_Stripe_Feature_Flags::is_upe_checkout_enabled() ) {
$methods[] = WC_Gateway_Stripe_Alipay::class;
$methods[] = WC_Gateway_Stripe_Multibanco::class;
}

return $methods;
}
Expand Down

0 comments on commit be061a2

Please sign in to comment.