Skip to content

Commit e29a8ac

Browse files
authored
Fix Link availability when OC is enabled (#4615)
* Fix Link availability when OC is enabled * Readme and changelog entries * Fix tests * Unit test
1 parent 41e360d commit e29a8ac

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.9.0 - xxxx-xx-xx =
4+
* Fix - The availability of the Link payment method when the Optimized Checkout is enabled
45
* Dev - Update Javascript unit tests for compatibility with Node 20
56
* Dev - Replaces some payment method instantiation logic for the Optimized Checkout with calls to the `get_payment_method_instance` method
67
* Dev - Multiple lint fixes in preparation for the Node 20 upgrade

client/settings/payment-request-section/__tests__/index.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useGetAvailablePaymentMethodIds,
66
usePaymentRequestEnabledSettings,
77
useAmazonPayEnabledSettings,
8+
useIsOCEnabled,
89
} from 'wcstripe/data';
910
import {
1011
PAYMENT_METHOD_CARD,
@@ -17,6 +18,7 @@ jest.mock( 'wcstripe/data', () => ( {
1718
useGetAvailablePaymentMethodIds: jest.fn(),
1819
useEnabledPaymentMethodIds: jest.fn(),
1920
useAmazonPayEnabledSettings: jest.fn(),
21+
useIsOCEnabled: jest.fn(),
2022
} ) );
2123

2224
const getMockPaymentRequestEnabledSettings = (
@@ -41,6 +43,7 @@ describe( 'PaymentRequestSection', () => {
4143
PAYMENT_METHOD_AMAZON_PAY,
4244
] );
4345
useAmazonPayEnabledSettings.mockReturnValue( [ false, jest.fn() ] );
46+
useIsOCEnabled.mockReturnValue( [ false, jest.fn() ] );
4447
global.wc_stripe_settings_params = {
4548
...globalValues,
4649
is_amazon_pay_available: true,
@@ -59,7 +62,7 @@ describe( 'PaymentRequestSection', () => {
5962
expect( label ).toBeInTheDocument();
6063
} );
6164

62-
it( 'hide link payment if card payment method is inactive', () => {
65+
it( 'hide link payment if card payment method is inactive (OC disabled)', () => {
6366
useGetAvailablePaymentMethodIds.mockReturnValue( [
6467
PAYMENT_METHOD_LINK,
6568
PAYMENT_METHOD_CARD,
@@ -73,7 +76,7 @@ describe( 'PaymentRequestSection', () => {
7376
expect( screen.queryByText( 'Link by Stripe' ) ).toBeNull();
7477
} );
7578

76-
it( 'show link payment if card payment method is active', () => {
79+
it( 'show link payment if card payment method is active (OC disabled)', () => {
7780
useGetAvailablePaymentMethodIds.mockReturnValue( [
7881
PAYMENT_METHOD_LINK,
7982
PAYMENT_METHOD_CARD,
@@ -87,6 +90,21 @@ describe( 'PaymentRequestSection', () => {
8790
expect( screen.queryByText( 'Link by Stripe' ) ).toBeInTheDocument();
8891
} );
8992

93+
it( 'show link payment if card payment method is inactive (OC enabled)', () => {
94+
useGetAvailablePaymentMethodIds.mockReturnValue( [
95+
PAYMENT_METHOD_LINK,
96+
PAYMENT_METHOD_CARD,
97+
] );
98+
useEnabledPaymentMethodIds.mockReturnValue( [
99+
[ PAYMENT_METHOD_LINK ],
100+
] );
101+
useIsOCEnabled.mockReturnValue( [ true, jest.fn() ] );
102+
103+
render( <PaymentRequestSection /> );
104+
105+
expect( screen.queryByText( 'Link by Stripe' ) ).toBeInTheDocument();
106+
} );
107+
90108
it( 'test stripe link checkbox checked', () => {
91109
useGetAvailablePaymentMethodIds.mockReturnValue( [
92110
PAYMENT_METHOD_LINK,

client/settings/payment-request-section/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
useAmazonPayEnabledSettings,
1414
useEnabledPaymentMethodIds,
1515
useGetAvailablePaymentMethodIds,
16+
useIsOCEnabled,
1617
} from '../../data';
1718
import './styles.scss';
1819
import AmazonPayIcon from '../../payment-method-icons/amazon-pay';
@@ -41,6 +42,8 @@ const PaymentRequestSection = () => {
4142
updateEnabledMethodIds,
4243
] = useEnabledPaymentMethodIds();
4344

45+
const [ isOCEnabled ] = useIsOCEnabled();
46+
4447
const updateStripeLinkCheckout = ( isEnabled ) => {
4548
// Add/remove Stripe Link from the list of enabled payment methods.
4649
if ( isEnabled ) {
@@ -61,7 +64,7 @@ const PaymentRequestSection = () => {
6164
PAYMENT_METHOD_CARD
6265
);
6366
const displayLinkPaymentMethod =
64-
enabledMethodIds.includes( PAYMENT_METHOD_CARD ) &&
67+
( enabledMethodIds.includes( PAYMENT_METHOD_CARD ) || isOCEnabled ) &&
6568
availablePaymentMethodIds.includes( PAYMENT_METHOD_LINK );
6669
const isStripeLinkEnabled = enabledMethodIds.includes(
6770
PAYMENT_METHOD_LINK
@@ -96,6 +99,17 @@ const PaymentRequestSection = () => {
9699
</div>
97100
</li>
98101
) }
102+
{ ! displayExpressPaymentMethods &&
103+
displayLinkPaymentMethod && (
104+
<li className="express-checkout">
105+
<div>
106+
{ __(
107+
'Credit card / debit card must be enabled as a payment method in order to use Google Pay and Apple Pay.',
108+
'woocommerce-gateway-stripe'
109+
) }
110+
</div>
111+
</li>
112+
) }
99113
{ displayExpressPaymentMethods && (
100114
<li className="express-checkout has-icon-border">
101115
<div className="express-checkout__checkbox">

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 9.9.0 - xxxx-xx-xx =
114+
* Fix - The availability of the Link payment method when the Optimized Checkout is enabled
114115
* Dev - Update Javascript unit tests for compatibility with Node 20
115116
* Dev - Replaces some payment method instantiation logic for the Optimized Checkout with calls to the `get_payment_method_instance` method
116117
* Dev - Multiple lint fixes in preparation for the Node 20 upgrade

0 commit comments

Comments
 (0)