Skip to content

Commit c63c58a

Browse files
committed
Merge release/5.5.1 into trunk
2 parents 9d07725 + 21b53c7 commit c63c58a

15 files changed

+226
-69
lines changed

changelog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
*** WooCommerce Payments Changelog ***
22

3+
= 5.5.1 - 2023-03-01 =
4+
* Add - When enabling WooPay, if legacy UPE is enabled, upgrades feature flag to split UPE instead.
5+
* Fix - Avoid rendering save cards checkbox for logged out users
6+
* Fix - Fix get woopay available countries return type
7+
* Fix - Fix handling saved tokens for payment gateways while using shortcode checkout
8+
* Fix - Fix subscription renewal creating multiple charges with UPE.
9+
* Fix - Fix WooPay settings notice visibility
10+
311
= 5.5.0 - 2023-02-22 =
412
* Add - Added learn more link to deposits page
513
* Add - Added tracking for the split UPE feature flag.

changelog/fix-save-card-checkbox-appearance

Lines changed: 0 additions & 4 deletions
This file was deleted.

changelog/fix-upe-renewal-multi-charges

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
import { isUsingSavedPaymentMethod } from '../upe-split';
5+
6+
describe( 'isUsingSavedPaymentMethod', () => {
7+
let container;
8+
9+
beforeAll( () => {
10+
container = document.createElement( 'div' );
11+
container.innerHTML = `
12+
<label>
13+
<input type="radio" id="wc-woocommerce_payments-payment-token-new" value="new">
14+
Use a new payment method
15+
</label>
16+
<label>
17+
<input type="radio" id="wc-woocommerce_payments_sepa_debit-payment-token-new" value="new">
18+
Use a new payment method
19+
</label>
20+
`;
21+
document.body.appendChild( container );
22+
} );
23+
24+
afterAll( () => {
25+
document.body.removeChild( container );
26+
container = null;
27+
} );
28+
29+
test( 'new CC is selected', () => {
30+
const input = document.querySelector(
31+
'#wc-woocommerce_payments-payment-token-new'
32+
);
33+
input.checked = true;
34+
const paymentMethodType = 'card';
35+
36+
expect( isUsingSavedPaymentMethod( paymentMethodType ) ).toBe( false );
37+
} );
38+
39+
test( 'saved CC is selected', () => {
40+
const input = document.querySelector(
41+
'#wc-woocommerce_payments-payment-token-new'
42+
);
43+
input.checked = false;
44+
const paymentMethodType = 'card';
45+
46+
expect( isUsingSavedPaymentMethod( paymentMethodType ) ).toBe( true );
47+
} );
48+
49+
test( 'new SEPA is selected', () => {
50+
const input = document.querySelector(
51+
'#wc-woocommerce_payments_sepa_debit-payment-token-new'
52+
);
53+
input.checked = true;
54+
const paymentMethodType = 'sepa_debit';
55+
56+
expect( isUsingSavedPaymentMethod( paymentMethodType ) ).toBe( false );
57+
} );
58+
59+
test( 'saved SEPA is selected', () => {
60+
const input = document.querySelector(
61+
'#wc-woocommerce_payments_sepa_debit-payment-token-new'
62+
);
63+
input.checked = false;
64+
const paymentMethodType = 'sepa_debit';
65+
66+
expect( isUsingSavedPaymentMethod( paymentMethodType ) ).toBe( true );
67+
} );
68+
69+
test( 'non-tokenized payment gateway is selected', () => {
70+
const paymentMethodType = 'sofort';
71+
72+
expect( isUsingSavedPaymentMethod( paymentMethodType ) ).toBe( false );
73+
} );
74+
} );

client/checkout/classic/upe-split.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -699,20 +699,6 @@ jQuery( function ( $ ) {
699699
} );
700700
};
701701

702-
/**
703-
* Checks if the customer is using a saved payment method.
704-
*
705-
* @return {boolean} Boolean indicating whether or not a saved payment method is being used.
706-
*/
707-
function isUsingSavedPaymentMethod() {
708-
const paymentMethodSelector =
709-
'#wc-woocommerce_payments-payment-token-new';
710-
return (
711-
$( paymentMethodSelector ).length &&
712-
! $( paymentMethodSelector ).is( ':checked' )
713-
);
714-
}
715-
716702
/**
717703
* Returns the cached setup intent.
718704
*
@@ -766,7 +752,7 @@ jQuery( function ( $ ) {
766752
.join( ' ' );
767753
$( 'form.checkout' ).on( checkoutEvents, function () {
768754
const paymentMethodType = getSelectedUPEGatewayPaymentMethod();
769-
if ( ! isUsingSavedPaymentMethod() ) {
755+
if ( ! isUsingSavedPaymentMethod( paymentMethodType ) ) {
770756
const paymentIntentId =
771757
gatewayUPEComponents[ paymentMethodType ].paymentIntentId;
772758
if ( isUPEEnabled && paymentIntentId ) {
@@ -803,7 +789,11 @@ jQuery( function ( $ ) {
803789

804790
// Handle the Pay for Order form if WooCommerce Payments is chosen.
805791
$( '#order_review' ).on( 'submit', () => {
806-
if ( ! isUsingSavedPaymentMethod() && isWCPayChosen() ) {
792+
const paymentMethodType = getSelectedUPEGatewayPaymentMethod();
793+
if (
794+
! isUsingSavedPaymentMethod( paymentMethodType ) &&
795+
isWCPayChosen()
796+
) {
807797
if ( isChangingPayment ) {
808798
handleUPEAddPayment( $( '#order_review' ) );
809799
return false;
@@ -848,3 +838,23 @@ jQuery( function ( $ ) {
848838
}
849839
} );
850840
} );
841+
842+
/**
843+
* Checks if the customer is using a saved payment method.
844+
*
845+
* @param {string} paymentMethodType Stripe payment method type ID.
846+
* @return {boolean} Boolean indicating whether a saved payment method is being used.
847+
*/
848+
export function isUsingSavedPaymentMethod( paymentMethodType ) {
849+
const prefix = '#wc-woocommerce_payments';
850+
const suffix = '-payment-token-new';
851+
const savedPaymentSelector =
852+
'card' === paymentMethodType
853+
? prefix + suffix
854+
: prefix + '_' + paymentMethodType + suffix;
855+
856+
return (
857+
null !== document.querySelector( savedPaymentSelector ) &&
858+
! document.querySelector( savedPaymentSelector ).checked
859+
);
860+
}

client/settings/express-checkout-settings/general-payment-request-button-settings.js

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { __, sprintf } from '@wordpress/i18n';
77
import { RadioControl, Notice } from '@wordpress/components';
88
import { Elements } from '@stripe/react-stripe-js';
99
import { loadStripe } from '@stripe/stripe-js';
10+
import { useContext } from '@wordpress/element';
1011

1112
/**
1213
* Internal dependencies
@@ -16,10 +17,13 @@ import PaymentRequestButtonPreview from './payment-request-button-preview';
1617
import NoticeOutlineIcon from 'gridicons/dist/notice-outline';
1718
import interpolateComponents from 'interpolate-components';
1819
import { getPaymentRequestData } from '../../payment-request/utils';
20+
import WCPaySettingsContext from '../wcpay-settings-context';
1921
import {
2022
usePaymentRequestButtonType,
2123
usePaymentRequestButtonSize,
2224
usePaymentRequestButtonTheme,
25+
usePaymentRequestEnabledSettings,
26+
usePlatformCheckoutEnabledSettings,
2327
} from 'wcpay/data';
2428

2529
const makeButtonSizeText = ( string ) =>
@@ -126,6 +130,13 @@ const GeneralPaymentRequestButtonSettings = ( { type } ) => {
126130
const [ buttonType, setButtonType ] = usePaymentRequestButtonType();
127131
const [ size, setSize ] = usePaymentRequestButtonSize();
128132
const [ theme, setTheme ] = usePaymentRequestButtonTheme();
133+
const [ isPlatformCheckoutEnabled ] = usePlatformCheckoutEnabledSettings();
134+
const [ isPaymentRequestEnabled ] = usePaymentRequestEnabledSettings();
135+
const {
136+
featureFlags: {
137+
platformCheckout: isPlatformCheckoutFeatureFlagEnabled,
138+
},
139+
} = useContext( WCPaySettingsContext );
129140

130141
const stripePromise = useMemo( () => {
131142
const stripeSettings = getPaymentRequestData( 'stripe' );
@@ -136,34 +147,44 @@ const GeneralPaymentRequestButtonSettings = ( { type } ) => {
136147
}, [] );
137148

138149
const otherButtons =
139-
'woopay' === type ? 'Apple Pay / Google Pay' : 'WooPay';
150+
'woopay' === type
151+
? __( 'Apple Pay / Google Pay buttons', 'woocommerce-payments' )
152+
: __( 'WooPay button', 'woocommerce-payments' );
153+
154+
const showWarning =
155+
isPlatformCheckoutEnabled &&
156+
isPaymentRequestEnabled &&
157+
isPlatformCheckoutFeatureFlagEnabled;
140158

141159
return (
142160
<CardBody>
143-
<Notice
144-
status="warning"
145-
isDismissible={ false }
146-
className="express-checkout__notice"
147-
>
148-
<span>
149-
<NoticeOutlineIcon
150-
style={ {
151-
color: '#BD8600',
152-
fill: 'currentColor',
153-
marginBottom: '-5px',
154-
marginRight: '16px',
155-
} }
156-
size={ 20 }
157-
/>
158-
{ sprintf(
159-
__(
160-
'These settings will also apply to the %s buttons on your store.',
161-
'woocommerce-payments'
162-
),
163-
otherButtons
164-
) }
165-
</span>
166-
</Notice>
161+
{ showWarning && (
162+
<Notice
163+
status="warning"
164+
isDismissible={ false }
165+
className="express-checkout__notice"
166+
>
167+
<span>
168+
<NoticeOutlineIcon
169+
style={ {
170+
color: '#BD8600',
171+
fill: 'currentColor',
172+
marginBottom: '-5px',
173+
marginRight: '16px',
174+
} }
175+
size={ 20 }
176+
/>
177+
{ sprintf(
178+
/* translators: %s type of button to which the settings will be applied */
179+
__(
180+
'These settings will also apply to the %s on your store.',
181+
'woocommerce-payments'
182+
),
183+
otherButtons
184+
) }
185+
</span>
186+
</Notice>
187+
) }
167188
<h4>{ __( 'Call to action', 'woocommerce-payments' ) }</h4>
168189
<RadioControl
169190
className="payment-method-settings__cta-selection"

client/settings/express-checkout-settings/test/payment-request-settings.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
usePaymentRequestButtonType,
1818
usePaymentRequestButtonSize,
1919
usePaymentRequestButtonTheme,
20+
usePlatformCheckoutEnabledSettings,
2021
} from '../../../data';
2122

2223
jest.mock( '../../../data', () => ( {
@@ -25,6 +26,7 @@ jest.mock( '../../../data', () => ( {
2526
usePaymentRequestButtonType: jest.fn().mockReturnValue( [ 'buy' ] ),
2627
usePaymentRequestButtonSize: jest.fn().mockReturnValue( [ 'default' ] ),
2728
usePaymentRequestButtonTheme: jest.fn().mockReturnValue( [ 'dark' ] ),
29+
usePlatformCheckoutEnabledSettings: jest.fn(),
2830
} ) );
2931

3032
jest.mock( '../payment-request-button-preview' );
@@ -43,6 +45,8 @@ const getMockPaymentRequestEnabledSettings = (
4345
updateIsPaymentRequestEnabledHandler
4446
) => [ isEnabled, updateIsPaymentRequestEnabledHandler ];
4547

48+
const getMockPlatformCheckoutEnabledSettings = ( isEnabled ) => [ isEnabled ];
49+
4650
const getMockPaymentRequestLocations = (
4751
isCheckoutEnabled,
4852
isProductPageEnabled,
@@ -66,6 +70,10 @@ describe( 'PaymentRequestSettings', () => {
6670
usePaymentRequestLocations.mockReturnValue(
6771
getMockPaymentRequestLocations( true, true, true, jest.fn() )
6872
);
73+
74+
usePlatformCheckoutEnabledSettings.mockReturnValue(
75+
getMockPlatformCheckoutEnabledSettings( true )
76+
);
6977
} );
7078

7179
it( 'renders enable settings with defaults', () => {

client/settings/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ if ( expressCheckoutSettingsContainer ) {
3838
const methodId = expressCheckoutSettingsContainer.dataset.methodId;
3939

4040
ReactDOM.render(
41-
<ErrorBoundary>
42-
<ExpressCheckoutSettings methodId={ methodId } />
43-
</ErrorBoundary>,
41+
<WCPaySettingsContext.Provider value={ wcpaySettings }>
42+
<ErrorBoundary>
43+
<ExpressCheckoutSettings methodId={ methodId } />
44+
</ErrorBoundary>
45+
,
46+
</WCPaySettingsContext.Provider>,
4447
expressCheckoutSettingsContainer
4548
);
4649
}

includes/class-wc-payment-gateway-wcpay.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,13 @@ public function update_is_platform_checkout_enabled( $is_platform_checkout_enabl
17561756
$this->update_option( 'platform_checkout', $is_platform_checkout_enabled ? 'yes' : 'no' );
17571757
if ( ! $is_platform_checkout_enabled ) {
17581758
Platform_Checkout_Order_Status_Sync::remove_webhook();
1759+
} elseif ( WC_Payments_Features::is_upe_legacy_enabled() ) {
1760+
update_option( WC_Payments_Features::UPE_FLAG_NAME, '0' );
1761+
update_option( WC_Payments_Features::UPE_SPLIT_FLAG_NAME, '1' );
1762+
1763+
if ( function_exists( 'wc_admin_record_tracks_event' ) ) {
1764+
wc_admin_record_tracks_event( 'wcpay_split_upe_enabled' );
1765+
}
17591766
}
17601767
}
17611768
}

0 commit comments

Comments
 (0)