diff --git a/paypal/js/frontend.js b/paypal/js/frontend.js index 39b5f95adb..83b3cbdad3 100644 --- a/paypal/js/frontend.js +++ b/paypal/js/frontend.js @@ -147,7 +147,7 @@ isRecurring = 'single' !== settings.one; const { paypalLayout: layout } = settings; const cardFieldsAreSupported = layout !== 'checkout_only' && 'function' === typeof window.paypal.CardFields; - const buttonsAreEnabled = layout !== 'card_only' && 'function' === typeof window.paypal.Buttons; + const buttonsAreEnabled = ( isRecurring || layout !== 'card_only' ) && 'function' === typeof window.paypal.Buttons; const runId = ++initRunId; diff --git a/tests/js/paypalBootstrap.test.mjs b/tests/js/paypalBootstrap.test.mjs index c6c4ba37dc..01f3457558 100644 --- a/tests/js/paypalBootstrap.test.mjs +++ b/tests/js/paypalBootstrap.test.mjs @@ -92,12 +92,16 @@ async function checkOverlappingInitialization() { querySelector: () => element, createElement: () => ( { classList: { add() {} }, append() {} } ), }, - getPayPalSettings: () => [ { one: 'single', paypalLayout: 'checkout_only' } ], + getPayPalSettings: () => [ { one: 'recurring', paypalLayout: 'card_only' } ], waitForVisiblePaymentField: async () => {}, listenForFieldMutations() {}, listenForSubmitButtonMutations() {}, paymentMethods: methods, - discoverPaymentMethods: async () => methods.set( 'paypal', { eligible: true, render: async () => {} } ), + discoverPaymentMethods: async ( { buttonsAreEnabled } ) => { + if ( buttonsAreEnabled ) { + methods.set( 'paypal', { eligible: true, render: async () => {} } ); + } + }, discoverDeferredPaymentMethods: () => { waiting++; return gate; }, @@ -123,7 +127,7 @@ async function checkOverlappingInitialization() { assert.equal( selectorCount, 1, 'Only the latest run should render the payment selector.' ); } -test( 'PayPal renders only the latest initialization after asynchronous discovery', checkOverlappingInitialization ); +test( 'PayPal renders only the latest subscription buttons with a saved Card only layout', checkOverlappingInitialization ); test( 'superseded wallet discovery does not register methods in the current run', async () => { const start = source.indexOf( '\tasync function discoverDeferredPaymentMethods(' );