Skip to content

Show unsupported payment methods at the end of the payment method list #4523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Tweak - Small improvements to e2e tests
* Fix - Prevent the PMC migration to run when the plugin is not connected to Stripe
* Fix - Fixes a fatal error in the OC inbox note when the new checkout is disabled
* Update - Show all available payment methods before unavailable payment methods

= 9.8.0 - 2025-08-11 =
* Add - Adds the current setting value for the Optimized Checkout to the Stripe System Status Report data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import { screen, render } from '@testing-library/react';
import PaymentMethodMissingCurrencyPill from '..';
import { usePaymentMethodCurrencies } from 'utils/use-payment-method-currencies';
import usePaymentMethodUnavailableReason from 'utils/use-payment-method-unavailable-reason';
import { PAYMENT_METHOD_UNAVAILABLE_REASONS } from 'wcstripe/stripe-utils/constants';

jest.mock( '../../../payment-methods-map', () => ( {
card: { currencies: [] },
Expand All @@ -12,34 +14,33 @@ jest.mock( 'utils/use-payment-method-currencies', () => ( {
usePaymentMethodCurrencies: jest.fn(),
} ) );

jest.mock( 'utils/use-payment-method-unavailable-reason' );

describe( 'PaymentMethodMissingCurrencyPill', () => {
beforeEach( () => {
global.wcSettings = { currency: { code: 'USD' } };
usePaymentMethodCurrencies.mockReturnValue( [ 'EUR' ] );
} );

it( 'should render the "Requires currency" text', () => {
it( 'should render the "Requires currency" text when currency is not supported', () => {
usePaymentMethodUnavailableReason.mockReturnValue(
PAYMENT_METHOD_UNAVAILABLE_REASONS.UNSUPPORTED_CURRENCY
);

render(
<PaymentMethodMissingCurrencyPill id="giropay" label="giropay" />
);

expect( screen.queryByText( 'Requires currency' ) ).toBeInTheDocument();
} );

it( 'should not render when currency matches', () => {
global.wcSettings = { currency: { code: 'EUR' } };
it( 'should not render when currency is supported', () => {
usePaymentMethodUnavailableReason.mockReturnValue( null );

const { container } = render(
<PaymentMethodMissingCurrencyPill id="giropay" label="giropay" />
);

expect( container.firstChild ).toBeNull();
} );

it( 'should render when currency differs', () => {
render(
<PaymentMethodMissingCurrencyPill id="giropay" label="giropay" />
);

expect( screen.queryByText( 'Requires currency' ) ).toBeInTheDocument();
} );
} );
75 changes: 38 additions & 37 deletions client/components/payment-method-missing-currency-pill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import interpolateComponents from 'interpolate-components';
import { Icon, info } from '@wordpress/icons';
import Popover from 'wcstripe/components/popover';
import { usePaymentMethodCurrencies } from 'utils/use-payment-method-currencies';
import { PAYMENT_METHOD_CARD } from 'wcstripe/stripe-utils/constants';
import usePaymentMethodUnavailableReason from 'utils/use-payment-method-unavailable-reason';
import { PAYMENT_METHOD_UNAVAILABLE_REASONS } from 'wcstripe/stripe-utils/constants';

const StyledPill = styled.span`
display: inline-flex;
Expand Down Expand Up @@ -47,47 +48,47 @@ const IconComponent = ( { children, ...props } ) => (

const PaymentMethodMissingCurrencyPill = ( { id, label } ) => {
const paymentMethodCurrencies = usePaymentMethodCurrencies( id );
const storeCurrency = window?.wcSettings?.currency?.code;
const unavailableReason = usePaymentMethodUnavailableReason( id );

if (
id !== PAYMENT_METHOD_CARD &&
! paymentMethodCurrencies.includes( storeCurrency )
unavailableReason !==
PAYMENT_METHOD_UNAVAILABLE_REASONS.UNSUPPORTED_CURRENCY
) {
return (
<StyledPill>
{ __( 'Requires currency', 'woocommerce-gateway-stripe' ) }
<Popover
BaseComponent={ IconComponent }
content={ interpolateComponents( {
mixedString: sprintf(
/* translators: $1: a payment method name. %2: Currency(ies). */
__(
'%1$s requires store currency to be set to %2$s. {{currencySettingsLink}}Set currency{{/currencySettingsLink}}',
'woocommerce-gateway-stripe'
),
label,
paymentMethodCurrencies.join( ', ' )
),
components: {
currencySettingsLink: (
<StyledLink
href="/wp-admin/admin.php?page=wc-settings&tab=general"
target="_blank"
rel="noreferrer"
onClick={ ( ev ) => {
// Stop propagation is necessary so it doesn't trigger the tooltip click event.
ev.stopPropagation();
} }
/>
),
},
} ) }
/>
</StyledPill>
);
return null;
}

return null;
return (
<StyledPill>
{ __( 'Requires currency', 'woocommerce-gateway-stripe' ) }
<Popover
BaseComponent={ IconComponent }
content={ interpolateComponents( {
mixedString: sprintf(
/* translators: $1: a payment method name. %2: Currency(ies). */
__(
'%1$s requires store currency to be set to %2$s. {{currencySettingsLink}}Set currency{{/currencySettingsLink}}',
'woocommerce-gateway-stripe'
),
label,
paymentMethodCurrencies.join( ', ' )
),
components: {
currencySettingsLink: (
<StyledLink
href="/wp-admin/admin.php?page=wc-settings&tab=general"
target="_blank"
rel="noreferrer"
onClick={ ( ev ) => {
// Stop propagation is necessary so it doesn't trigger the tooltip click event.
ev.stopPropagation();
} }
/>
),
},
} ) }
/>
</StyledPill>
);
};

export default PaymentMethodMissingCurrencyPill;
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/* global wc_stripe_settings_params */
import { __, sprintf } from '@wordpress/i18n';
import React from 'react';
import styled from '@emotion/styled';
import interpolateComponents from 'interpolate-components';
import { Icon, info } from '@wordpress/icons';
import usePaymentMethodUnavailableReason from 'utils/use-payment-method-unavailable-reason';
import Popover from 'wcstripe/components/popover';
import {
PAYMENT_METHOD_AFFIRM,
PAYMENT_METHOD_KLARNA,
} from 'wcstripe/stripe-utils/constants';
import { PAYMENT_METHOD_UNAVAILABLE_REASONS } from 'wcstripe/stripe-utils/constants';

const StyledPill = styled.span`
display: inline-flex;
Expand Down Expand Up @@ -49,48 +46,45 @@ const IconComponent = ( { children, ...props } ) => (
);

const PaymentMethodUnavailableDueConflictPill = ( { id, label } ) => {
const unavailableReason = usePaymentMethodUnavailableReason( id );

if (
( id === PAYMENT_METHOD_AFFIRM &&
// eslint-disable-next-line camelcase
wc_stripe_settings_params.has_affirm_gateway_plugin ) ||
( id === PAYMENT_METHOD_KLARNA &&
// eslint-disable-next-line camelcase
wc_stripe_settings_params.has_klarna_gateway_plugin )
unavailableReason !==
PAYMENT_METHOD_UNAVAILABLE_REASONS.OFFICIAL_PLUGIN_CONFLICT
) {
return (
<StyledPill>
{ __( 'Has plugin conflict', 'woocommerce-gateway-stripe' ) }
<Popover
BaseComponent={ IconComponent }
content={ interpolateComponents( {
mixedString: sprintf(
/* translators: $1: a payment method name */
__(
'%1$s is unavailable due to another official plugin being active.',
'woocommerce-gateway-stripe'
),
label
),
components: {
currencySettingsLink: (
<StyledLink
href="/wp-admin/admin.php?page=wc-settings&tab=general"
target="_blank"
rel="noreferrer"
onClick={ ( ev ) => {
// Stop propagation is necessary so it doesn't trigger the tooltip click event.
ev.stopPropagation();
} }
/>
),
},
} ) }
/>
</StyledPill>
);
return null;
}

return null;
return (
<StyledPill>
{ __( 'Has plugin conflict', 'woocommerce-gateway-stripe' ) }
<Popover
BaseComponent={ IconComponent }
content={ interpolateComponents( {
mixedString: sprintf(
/* translators: $1: a payment method name */
__(
'%1$s is unavailable due to another official plugin being active.',
'woocommerce-gateway-stripe'
),
label
),
components: {
currencySettingsLink: (
<StyledLink
href="/wp-admin/admin.php?page=wc-settings&tab=general"
target="_blank"
rel="noreferrer"
onClick={ ( ev ) => {
// Stop propagation is necessary so it doesn't trigger the tooltip click event.
ev.stopPropagation();
} }
/>
),
},
} ) }
/>
</StyledPill>
);
};

export default PaymentMethodUnavailableDueConflictPill;
Loading
Loading