Skip to content

Commit

Permalink
Merge branch 'develop' into update/6320-rule-card-behavior-if-affecte…
Browse files Browse the repository at this point in the history
…d-by-other-config
  • Loading branch information
allie500 authored Dec 5, 2023
2 parents 2c9afd5 + e6f80ba commit ede42f0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
4 changes: 4 additions & 0 deletions changelog/revert-prefetch-session-for-button
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Revemoved pre-fretch session for button to prevent draft order creation
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe( 'WoopayExpressCheckoutButton', () => {
).toBeInTheDocument();
} );

test( 'prefetch session data by default', async () => {
test( 'does not prefetch session data by default', async () => {
getConfig.mockImplementation( ( v ) => {
switch ( v ) {
case 'wcAjaxUrl':
Expand All @@ -104,14 +104,12 @@ describe( 'WoopayExpressCheckoutButton', () => {
);

await waitFor( () => {
expect( request ).toHaveBeenCalledWith( 'woopay.url', {
_ajax_nonce: 'sessionnonce',
} );
expect( request ).not.toHaveBeenCalled();
expect( expressCheckoutIframe ).not.toHaveBeenCalled();
} );
} );

test( 'request session data on button click', async () => {
test( 'should not request session data on button click', async () => {
getConfig.mockImplementation( ( v ) => {
switch ( v ) {
case 'wcAjaxUrl':
Expand All @@ -138,9 +136,7 @@ describe( 'WoopayExpressCheckoutButton', () => {
userEvent.click( expressButton );

await waitFor( () => {
expect( request ).toHaveBeenCalledWith( 'woopay.url', {
_ajax_nonce: 'sessionnonce',
} );
expect( request ).not.toHaveBeenCalled();
expect( expressCheckoutIframe ).not.toHaveBeenCalled();
} );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const WoopayExpressCheckoutButton = ( {
narrow: 'narrow',
wide: 'wide',
};
const sessionDataPromiseRef = useRef( null );
const initWoopayRef = useRef( null );
const buttonRef = useRef( null );
const initialOnClickEventRef = useRef( null );
Expand Down Expand Up @@ -305,9 +304,16 @@ export const WoopayExpressCheckoutButton = ( {
} );
} );
} else {
// Non-product pages already have pre-fetched session data.
sessionDataPromiseRef.current
?.then( ( response ) => {
request(
buildAjaxURL(
getConfig( 'wcAjaxUrl' ),
'get_woopay_session'
),
{
_ajax_nonce: getConfig( 'woopaySessionNonce' ),
}
)
.then( ( response ) => {
iframe.contentWindow.postMessage(
{
action: 'setPreemptiveSessionData',
Expand Down Expand Up @@ -349,16 +355,6 @@ export const WoopayExpressCheckoutButton = ( {
return;
}

if ( ! isProductPage ) {
// Start to pre-fetch session data for non-product pages.
sessionDataPromiseRef.current = request(
buildAjaxURL( getConfig( 'wcAjaxUrl' ), 'get_woopay_session' ),
{
_ajax_nonce: getConfig( 'woopaySessionNonce' ),
}
).then( ( response ) => response );
}

buttonRef.current.parentElement.style.position = 'relative';
buttonRef.current.parentElement.appendChild( newIframe() );

Expand Down

0 comments on commit ede42f0

Please sign in to comment.