From ccb598fc05f13c621b43bb8bc24463ab0bcd7ddc Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 06:41:21 -0700 Subject: [PATCH] Fix PayPal Submit staying disabled after a cancelled pop-up onCancel() never released the order createOrder() counted in `running`, so enableSubmit() returned early when Credit Card became valid. Release it (guarded, since subscription and Apple Pay cancels start no order) and refresh the submit button for the selected method. Co-Authored-By: Claude Sonnet 5.5 --- paypal/js/frontend.js | 9 +++++++ tests/js/paypalBootstrap.test.mjs | 45 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/paypal/js/frontend.js b/paypal/js/frontend.js index 423d010539..39b5f95adb 100644 --- a/paypal/js/frontend.js +++ b/paypal/js/frontend.js @@ -1618,8 +1618,17 @@ } function onCancel() { + // Wallet cancels (subscriptions, Apple Pay) never started an order, so only release one that exists. + if ( running > 0 ) { + running--; + } + thisForm.classList.add( 'frm_loading_form' ); frmFrontForm.removeSubmitLoading( jQuery( thisForm ), 'disable', 0 ); + + if ( running === 0 && selectedMethod ) { + updateSubmitButtonVisibility( selectedMethod ); + } } // ---- Submit Button Helpers ---- diff --git a/tests/js/paypalBootstrap.test.mjs b/tests/js/paypalBootstrap.test.mjs index 3756778ec9..c6c4ba37dc 100644 --- a/tests/js/paypalBootstrap.test.mjs +++ b/tests/js/paypalBootstrap.test.mjs @@ -155,3 +155,48 @@ test( 'a page change before the PayPal SDK loads leaves initialization to the bo runInNewContext( `let thisForm, cardElementContainer, isRecurring;${ source.slice( start, end ) }`, context ); await context.paypalInit(); } ); + +/** + * Run the real onCancel() with the given in-flight order count and selected method. + * + * @param {number} running The number of orders in flight when the pop-up closes. + * @param {string|null} selected The selected payment method key. + * + * @return {Object} The remaining count and the keys passed to updateSubmitButtonVisibility(). + */ +function cancelWith( running, selected ) { + const start = source.indexOf( '\tfunction onCancel()' ); + const end = source.indexOf( '\n\t// ---- Submit Button Helpers ----', start ); + assert.ok( start >= 0 && end > start, 'onCancel boundaries must exist.' ); + const updated = []; + const context = { + thisForm: { classList: { add() {} } }, + frmFrontForm: { removeSubmitLoading() {} }, + jQuery: value => value, + updateSubmitButtonVisibility: key => updated.push( key ), + }; + runInNewContext( `let running = ${ running }; let selectedMethod = ${ JSON.stringify( selected ) };${ source.slice( start, end ) }; function getRunning() { return running; }`, context ); + context.onCancel(); + + return { running: context.getRunning(), updated }; +} + +test( 'closing the PayPal pop-up releases the order it started so Credit Card can enable Submit', () => { + const result = cancelWith( 1, 'paypal' ); + + assert.equal( result.running, 0 ); + assert.deepEqual( result.updated, [ 'paypal' ] ); +} ); + +test( 'cancelling without an order in flight does not push the order count below zero', () => { + const result = cancelWith( 0, 'paypal' ); + + assert.equal( result.running, 0 ); +} ); + +test( 'cancelling while another order is still in flight leaves Submit state alone', () => { + const result = cancelWith( 2, 'card' ); + + assert.equal( result.running, 1 ); + assert.deepEqual( result.updated, [] ); +} );