Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c2565ec
Show payment methods without currency support at the end of the payme…
daledupreez Jul 24, 2025
dcaba9a
Add JSDoc
daledupreez Jul 24, 2025
7e0455d
Merge branch 'develop' into try/relevance-sort-in-payment-method-page
daledupreez Jul 24, 2025
7377fbf
Memoize and refactor sorting
daledupreez Jul 24, 2025
b3956c5
Fix JS unit tests
daledupreez Jul 24, 2025
4b1506e
Merge branch 'develop' into try/relevance-sort-in-payment-method-page
daledupreez Jul 31, 2025
bf373e3
Add changelog
daledupreez Jul 31, 2025
f1b8d38
Use getSetting() instead of global reference; rename variable
daledupreez Jul 31, 2025
c966d88
Update unit tests to mock getSetting() and centralise currency mocking
daledupreez Jul 31, 2025
9f3e05e
Return early when UPE is disabled; update notes
daledupreez Jul 31, 2025
a0f6d46
Merge branch 'develop' into try/relevance-sort-in-payment-method-page
daledupreez Aug 14, 2025
f3a981a
Refactor logic into central helper function
daledupreez Aug 15, 2025
28c4eb3
Merge branch 'develop' into try/relevance-sort-in-payment-method-page
daledupreez Aug 15, 2025
a2230e5
Update unit tests
daledupreez Aug 15, 2025
3089fce
Add tests for getPaymentMethodUnavailableReason
daledupreez Aug 15, 2025
a13b5c6
Sort plugin conflicts before currency issues
daledupreez Aug 18, 2025
8416544
Merge branch 'develop' into try/relevance-sort-in-payment-method-page
daledupreez Aug 18, 2025
0e5a1fe
Merge branch 'develop' into try/relevance-sort-in-payment-method-page
daledupreez Aug 19, 2025
f74b2bf
Fix changelog entry location
daledupreez Aug 19, 2025
3c6c016
Merge branch 'develop' into try/relevance-sort-in-payment-method-page
daledupreez Aug 19, 2025
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