mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Axo Blocks: Migrate console logs to the Axo log function
This commit is contained in:
parent
b44dd0a8d9
commit
70676468b8
15 changed files with 82 additions and 94 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { createElement, createRoot } from '@wordpress/element';
|
import { createElement, createRoot } from '@wordpress/element';
|
||||||
|
import { log } from '../../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
import { STORE_NAME } from '../../stores/axoStore';
|
import { STORE_NAME } from '../../stores/axoStore';
|
||||||
import EmailButton from './EmailButton';
|
import EmailButton from './EmailButton';
|
||||||
|
|
||||||
|
@ -20,8 +21,9 @@ const getEmailInput = () => {
|
||||||
export const setupEmailFunctionality = ( onEmailSubmit ) => {
|
export const setupEmailFunctionality = ( onEmailSubmit ) => {
|
||||||
const input = getEmailInput();
|
const input = getEmailInput();
|
||||||
if ( ! input ) {
|
if ( ! input ) {
|
||||||
console.warn(
|
log(
|
||||||
'Email input element not found. Functionality not added.'
|
'Email input element not found. Functionality not added.',
|
||||||
|
'warn'
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +43,7 @@ export const setupEmailFunctionality = ( onEmailSubmit ) => {
|
||||||
try {
|
try {
|
||||||
await onEmailSubmit( input.value );
|
await onEmailSubmit( input.value );
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error( 'Error during email submission:', error );
|
log( `Error during email submission: ${ error }`, 'error' );
|
||||||
} finally {
|
} finally {
|
||||||
wp.data.dispatch( STORE_NAME ).setIsEmailSubmitted( false );
|
wp.data.dispatch( STORE_NAME ).setIsEmailSubmitted( false );
|
||||||
renderButton();
|
renderButton();
|
||||||
|
|
|
@ -14,10 +14,6 @@ export const injectShippingChangeButton = ( onChangeShippingAddressClick ) => {
|
||||||
onChangeShippingAddressClick={ onChangeShippingAddressClick }
|
onChangeShippingAddressClick={ onChangeShippingAddressClick }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
'Shipping change button already exists. Skipping injection.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useEffect, useRef } from '@wordpress/element';
|
import { useEffect, useRef } from '@wordpress/element';
|
||||||
|
import { log } from '../../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
|
|
||||||
const Watermark = ( {
|
const Watermark = ( {
|
||||||
fastlaneSdk,
|
fastlaneSdk,
|
||||||
|
@ -27,7 +28,7 @@ const Watermark = ( {
|
||||||
watermarkRef.current = watermark;
|
watermarkRef.current = watermark;
|
||||||
watermark.render( `#${ name }` );
|
watermark.render( `#${ name }` );
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error( 'Error rendering watermark:', error );
|
log( `Error rendering watermark: ${ error }`, 'error' );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,7 @@ import {
|
||||||
updateWatermarkContent,
|
updateWatermarkContent,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
console.log( 'WatermarkManager module loaded' );
|
|
||||||
|
|
||||||
const WatermarkManager = ( { fastlaneSdk } ) => {
|
const WatermarkManager = ( { fastlaneSdk } ) => {
|
||||||
console.log( 'WatermarkManager rendering', { fastlaneSdk } );
|
|
||||||
|
|
||||||
const isGuest = useSelect( ( select ) =>
|
const isGuest = useSelect( ( select ) =>
|
||||||
select( STORE_NAME ).getIsGuest()
|
select( STORE_NAME ).getIsGuest()
|
||||||
);
|
);
|
||||||
|
@ -22,17 +18,8 @@ const WatermarkManager = ( { fastlaneSdk } ) => {
|
||||||
select( STORE_NAME ).getIsAxoScriptLoaded()
|
select( STORE_NAME ).getIsAxoScriptLoaded()
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log( 'WatermarkManager state', {
|
|
||||||
isGuest,
|
|
||||||
isAxoActive,
|
|
||||||
isAxoScriptLoaded,
|
|
||||||
} );
|
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
console.log( 'WatermarkManager useEffect triggered' );
|
|
||||||
|
|
||||||
if ( isAxoActive || ( ! isAxoActive && ! isAxoScriptLoaded ) ) {
|
if ( isAxoActive || ( ! isAxoActive && ! isAxoScriptLoaded ) ) {
|
||||||
console.log( 'Conditions met, creating watermark' );
|
|
||||||
createWatermarkContainer();
|
createWatermarkContainer();
|
||||||
updateWatermarkContent( {
|
updateWatermarkContent( {
|
||||||
isAxoActive,
|
isAxoActive,
|
||||||
|
@ -41,7 +28,6 @@ const WatermarkManager = ( { fastlaneSdk } ) => {
|
||||||
isGuest,
|
isGuest,
|
||||||
} );
|
} );
|
||||||
} else {
|
} else {
|
||||||
console.log( 'Conditions not met, removing watermark' );
|
|
||||||
removeWatermark();
|
removeWatermark();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,20 +7,15 @@ const watermarkReference = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createWatermarkContainer = () => {
|
export const createWatermarkContainer = () => {
|
||||||
console.log( 'Creating watermark container' );
|
|
||||||
const textInputContainer = document.querySelector(
|
const textInputContainer = document.querySelector(
|
||||||
'.wp-block-woocommerce-checkout-contact-information-block .wc-block-components-text-input'
|
'.wp-block-woocommerce-checkout-contact-information-block .wc-block-components-text-input'
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( textInputContainer && ! watermarkReference.container ) {
|
if ( textInputContainer && ! watermarkReference.container ) {
|
||||||
console.log(
|
|
||||||
'Text input container found, creating watermark container'
|
|
||||||
);
|
|
||||||
const emailInput =
|
const emailInput =
|
||||||
textInputContainer.querySelector( 'input[id="email"]' );
|
textInputContainer.querySelector( 'input[id="email"]' );
|
||||||
|
|
||||||
if ( emailInput ) {
|
if ( emailInput ) {
|
||||||
console.log( 'Email input found, setting up watermark' );
|
|
||||||
watermarkReference.container = document.createElement( 'div' );
|
watermarkReference.container = document.createElement( 'div' );
|
||||||
watermarkReference.container.setAttribute(
|
watermarkReference.container.setAttribute(
|
||||||
'class',
|
'class',
|
||||||
|
@ -47,14 +42,12 @@ export const createWatermarkContainer = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setupWatermark = ( fastlaneSdk ) => {
|
export const setupWatermark = ( fastlaneSdk ) => {
|
||||||
console.log( 'Setting up watermark', { fastlaneSdk } );
|
|
||||||
const container = document.createElement( 'div' );
|
const container = document.createElement( 'div' );
|
||||||
document.body.appendChild( container );
|
document.body.appendChild( container );
|
||||||
const root = createRoot( container );
|
const root = createRoot( container );
|
||||||
root.render( createElement( WatermarkManager, { fastlaneSdk } ) );
|
root.render( createElement( WatermarkManager, { fastlaneSdk } ) );
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
console.log( 'Cleaning up watermark setup' );
|
|
||||||
root.unmount();
|
root.unmount();
|
||||||
if ( container && container.parentNode ) {
|
if ( container && container.parentNode ) {
|
||||||
container.parentNode.removeChild( container );
|
container.parentNode.removeChild( container );
|
||||||
|
@ -63,7 +56,6 @@ export const setupWatermark = ( fastlaneSdk ) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeWatermark = () => {
|
export const removeWatermark = () => {
|
||||||
console.log( 'Removing watermark' );
|
|
||||||
if ( watermarkReference.root ) {
|
if ( watermarkReference.root ) {
|
||||||
watermarkReference.root.unmount();
|
watermarkReference.root.unmount();
|
||||||
}
|
}
|
||||||
|
@ -82,12 +74,10 @@ export const removeWatermark = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object.assign( watermarkReference, { container: null, root: null } );
|
Object.assign( watermarkReference, { container: null, root: null } );
|
||||||
console.log( 'Watermark removed' );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const renderWatermarkContent = ( content ) => {
|
export const renderWatermarkContent = ( content ) => {
|
||||||
if ( watermarkReference.root ) {
|
if ( watermarkReference.root ) {
|
||||||
console.log( 'Rendering watermark content' );
|
|
||||||
watermarkReference.root.render( content );
|
watermarkReference.root.render( content );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -99,7 +89,6 @@ export const updateWatermarkContent = ( {
|
||||||
isGuest,
|
isGuest,
|
||||||
} ) => {
|
} ) => {
|
||||||
if ( ! isAxoActive && ! isAxoScriptLoaded ) {
|
if ( ! isAxoActive && ! isAxoScriptLoaded ) {
|
||||||
console.log( 'Rendering spinner' );
|
|
||||||
renderWatermarkContent(
|
renderWatermarkContent(
|
||||||
createElement( 'span', {
|
createElement( 'span', {
|
||||||
className: 'wc-block-components-spinner',
|
className: 'wc-block-components-spinner',
|
||||||
|
@ -107,7 +96,6 @@ export const updateWatermarkContent = ( {
|
||||||
} )
|
} )
|
||||||
);
|
);
|
||||||
} else if ( isAxoActive ) {
|
} else if ( isAxoActive ) {
|
||||||
console.log( 'Rendering FastlaneWatermark' );
|
|
||||||
renderWatermarkContent(
|
renderWatermarkContent(
|
||||||
createElement( Watermark, {
|
createElement( Watermark, {
|
||||||
fastlaneSdk,
|
fastlaneSdk,
|
||||||
|
@ -116,7 +104,6 @@ export const updateWatermarkContent = ( {
|
||||||
} )
|
} )
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log( 'Rendering null content' );
|
|
||||||
renderWatermarkContent( null );
|
renderWatermarkContent( null );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
import { populateWooFields } from '../helpers/fieldHelpers';
|
import { populateWooFields } from '../helpers/fieldHelpers';
|
||||||
import { injectShippingChangeButton } from '../components/Shipping';
|
import { injectShippingChangeButton } from '../components/Shipping';
|
||||||
import { injectCardChangeButton } from '../components/Card';
|
import { injectCardChangeButton } from '../components/Card';
|
||||||
|
@ -17,7 +18,7 @@ export const createEmailLookupHandler = (
|
||||||
) => {
|
) => {
|
||||||
return async ( email ) => {
|
return async ( email ) => {
|
||||||
try {
|
try {
|
||||||
console.log( 'Email value being looked up:', email );
|
log( `Email value being looked up: ${ email }` );
|
||||||
|
|
||||||
if ( ! fastlaneSdk ) {
|
if ( ! fastlaneSdk ) {
|
||||||
throw new Error( 'FastlaneSDK is not initialized' );
|
throw new Error( 'FastlaneSDK is not initialized' );
|
||||||
|
@ -32,7 +33,7 @@ export const createEmailLookupHandler = (
|
||||||
const lookup =
|
const lookup =
|
||||||
await fastlaneSdk.identity.lookupCustomerByEmail( email );
|
await fastlaneSdk.identity.lookupCustomerByEmail( email );
|
||||||
|
|
||||||
console.log( 'Lookup response:', lookup );
|
log( `Lookup response: ${ JSON.stringify( lookup ) }` );
|
||||||
|
|
||||||
// Gary flow
|
// Gary flow
|
||||||
if ( lookup && lookup.customerContextId === '' ) {
|
if ( lookup && lookup.customerContextId === '' ) {
|
||||||
|
@ -40,7 +41,7 @@ export const createEmailLookupHandler = (
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! lookup || ! lookup.customerContextId ) {
|
if ( ! lookup || ! lookup.customerContextId ) {
|
||||||
console.warn( 'No customerContextId found in the response' );
|
log( 'No customerContextId found in the response', 'warn' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ export const createEmailLookupHandler = (
|
||||||
setCardDetails( profileData.card );
|
setCardDetails( profileData.card );
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log( 'Profile Data:', profileData );
|
log( `Profile Data: ${ JSON.stringify( profileData ) }` );
|
||||||
|
|
||||||
populateWooFields(
|
populateWooFields(
|
||||||
profileData,
|
profileData,
|
||||||
|
@ -82,12 +83,12 @@ export const createEmailLookupHandler = (
|
||||||
injectShippingChangeButton( onChangeShippingAddressClick );
|
injectShippingChangeButton( onChangeShippingAddressClick );
|
||||||
injectCardChangeButton( onChangeCardButtonClick );
|
injectCardChangeButton( onChangeCardButtonClick );
|
||||||
} else {
|
} else {
|
||||||
console.warn( 'Authentication failed or did not succeed' );
|
log( 'Authentication failed or did not succeed', 'warn' );
|
||||||
}
|
}
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error(
|
log(
|
||||||
'Error during email lookup or authentication:',
|
`Error during email lookup or authentication:
|
||||||
error
|
${ error }`
|
||||||
);
|
);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { select, subscribe } from '@wordpress/data';
|
import { select, subscribe } from '@wordpress/data';
|
||||||
|
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
import { STORE_NAME } from '../stores/axoStore';
|
import { STORE_NAME } from '../stores/axoStore';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,7 +14,10 @@ export const setupAuthenticationClassToggle = () => {
|
||||||
const updateAuthenticationClass = () => {
|
const updateAuthenticationClass = () => {
|
||||||
const targetElement = document.querySelector( targetSelector );
|
const targetElement = document.querySelector( targetSelector );
|
||||||
if ( ! targetElement ) {
|
if ( ! targetElement ) {
|
||||||
console.warn( `Target element not found: ${ targetSelector }` );
|
log(
|
||||||
|
`Authentication class target element not found: ${ targetSelector }`,
|
||||||
|
'warn'
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +48,10 @@ export const setupEmailLookupCompletedClassToggle = () => {
|
||||||
const updateEmailLookupCompletedClass = () => {
|
const updateEmailLookupCompletedClass = () => {
|
||||||
const targetElement = document.querySelector( targetSelector );
|
const targetElement = document.querySelector( targetSelector );
|
||||||
if ( ! targetElement ) {
|
if ( ! targetElement ) {
|
||||||
console.warn( `Target element not found: ${ targetSelector }` );
|
log(
|
||||||
|
`Email lookup completed class target element not found: ${ targetSelector }`,
|
||||||
|
'warn'
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +89,10 @@ export const setupCheckoutBlockClassToggles = () => {
|
||||||
const updateCheckoutBlockClassToggles = () => {
|
const updateCheckoutBlockClassToggles = () => {
|
||||||
const targetElement = document.querySelector( targetSelector );
|
const targetElement = document.querySelector( targetSelector );
|
||||||
if ( ! targetElement ) {
|
if ( ! targetElement ) {
|
||||||
console.warn( `Target element not found: ${ targetSelector }` );
|
log(
|
||||||
|
`Checkout block class target element not found: ${ targetSelector }`,
|
||||||
|
'warn'
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,26 @@
|
||||||
import { dispatch } from '@wordpress/data';
|
import { dispatch } from '@wordpress/data';
|
||||||
|
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
|
|
||||||
export const snapshotFields = ( shippingAddress, billingAddress ) => {
|
export const snapshotFields = ( shippingAddress, billingAddress ) => {
|
||||||
console.log( 'Attempting to snapshot fields' );
|
|
||||||
if ( ! shippingAddress || ! billingAddress ) {
|
if ( ! shippingAddress || ! billingAddress ) {
|
||||||
console.warn( 'Shipping or billing address is missing:', {
|
log(
|
||||||
shippingAddress,
|
`Shipping or billing address is missing: ${ JSON.stringify( {
|
||||||
billingAddress,
|
shippingAddress,
|
||||||
} );
|
billingAddress,
|
||||||
|
} ) }`,
|
||||||
|
'warn'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalData = { shippingAddress, billingAddress };
|
const originalData = { shippingAddress, billingAddress };
|
||||||
console.log( 'Snapshot data:', originalData );
|
log( `Snapshot data: ${ JSON.stringify( originalData ) }` );
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
'axoOriginalCheckoutFields',
|
'axoOriginalCheckoutFields',
|
||||||
JSON.stringify( originalData )
|
JSON.stringify( originalData )
|
||||||
);
|
);
|
||||||
console.log( 'Original fields saved to localStorage', originalData );
|
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error( 'Error saving to localStorage:', error );
|
log( `Error saving to localStorage: ${ error }`, 'error' );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,47 +28,41 @@ export const restoreOriginalFields = (
|
||||||
updateShippingAddress,
|
updateShippingAddress,
|
||||||
updateBillingAddress
|
updateBillingAddress
|
||||||
) => {
|
) => {
|
||||||
console.log( 'Attempting to restore original fields' );
|
log( 'Attempting to restore original fields' );
|
||||||
let savedData;
|
let savedData;
|
||||||
try {
|
try {
|
||||||
savedData = localStorage.getItem( 'axoOriginalCheckoutFields' );
|
savedData = localStorage.getItem( 'axoOriginalCheckoutFields' );
|
||||||
console.log( 'Data retrieved from localStorage:', savedData );
|
log(
|
||||||
|
`Data retrieved from localStorage: ${ JSON.stringify( savedData ) }`
|
||||||
|
);
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error( 'Error retrieving from localStorage:', error );
|
log( `Error retrieving from localStorage: ${ error }`, 'error' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( savedData ) {
|
if ( savedData ) {
|
||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse( savedData );
|
const parsedData = JSON.parse( savedData );
|
||||||
console.log( 'Parsed data:', parsedData );
|
|
||||||
if ( parsedData.shippingAddress ) {
|
if ( parsedData.shippingAddress ) {
|
||||||
console.log(
|
|
||||||
'Restoring shipping address:',
|
|
||||||
parsedData.shippingAddress
|
|
||||||
);
|
|
||||||
updateShippingAddress( parsedData.shippingAddress );
|
updateShippingAddress( parsedData.shippingAddress );
|
||||||
} else {
|
} else {
|
||||||
console.warn( 'No shipping address found in saved data' );
|
log( `No shipping address found in saved data`, 'warn' );
|
||||||
}
|
}
|
||||||
if ( parsedData.billingAddress ) {
|
if ( parsedData.billingAddress ) {
|
||||||
console.log(
|
log(
|
||||||
'Restoring billing address:',
|
`Restoring billing address:
|
||||||
parsedData.billingAddress
|
${ JSON.stringify( parsedData.billingAddress ) }`
|
||||||
);
|
);
|
||||||
updateBillingAddress( parsedData.billingAddress );
|
updateBillingAddress( parsedData.billingAddress );
|
||||||
} else {
|
} else {
|
||||||
console.warn( 'No billing address found in saved data' );
|
log( 'No billing address found in saved data', 'warn' );
|
||||||
}
|
}
|
||||||
console.log(
|
|
||||||
'Original fields restored from localStorage',
|
|
||||||
parsedData
|
|
||||||
);
|
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error( 'Error parsing saved data:', error );
|
log( `Error parsing saved data: ${ error }` );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn(
|
log(
|
||||||
'No data found in localStorage under axoOriginalCheckoutFields'
|
'No data found in localStorage under axoOriginalCheckoutFields',
|
||||||
|
'warn'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -78,9 +74,10 @@ export const populateWooFields = (
|
||||||
) => {
|
) => {
|
||||||
const CHECKOUT_STORE_KEY = 'wc/store/checkout';
|
const CHECKOUT_STORE_KEY = 'wc/store/checkout';
|
||||||
|
|
||||||
console.log(
|
log(
|
||||||
'Populating WooCommerce fields with profile data:',
|
`Populating WooCommerce fields with profile data: ${ JSON.stringify(
|
||||||
profileData
|
profileData
|
||||||
|
) }`
|
||||||
);
|
);
|
||||||
|
|
||||||
const checkoutDispatch = dispatch( CHECKOUT_STORE_KEY );
|
const checkoutDispatch = dispatch( CHECKOUT_STORE_KEY );
|
||||||
|
@ -107,7 +104,11 @@ export const populateWooFields = (
|
||||||
phone: phoneNumber.nationalNumber,
|
phone: phoneNumber.nationalNumber,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log( 'Setting WooCommerce shipping address:', shippingAddress );
|
log(
|
||||||
|
`Setting WooCommerce shipping address: ${ JSON.stringify(
|
||||||
|
shippingAddress
|
||||||
|
) }`
|
||||||
|
);
|
||||||
setWooShippingAddress( shippingAddress );
|
setWooShippingAddress( shippingAddress );
|
||||||
|
|
||||||
// Save billing address.
|
// Save billing address.
|
||||||
|
@ -124,7 +125,11 @@ export const populateWooFields = (
|
||||||
country: billingData.countryCode,
|
country: billingData.countryCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log( 'Setting WooCommerce billing address:', billingAddress );
|
log(
|
||||||
|
`Setting WooCommerce billing address: ${ JSON.stringify(
|
||||||
|
billingAddress
|
||||||
|
) }`
|
||||||
|
);
|
||||||
setWooBillingAddress( billingAddress );
|
setWooBillingAddress( billingAddress );
|
||||||
|
|
||||||
// Collapse shipping address input fields into the card view.
|
// Collapse shipping address input fields into the card view.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { useEffect } from '@wordpress/element';
|
import { useEffect } from '@wordpress/element';
|
||||||
import { useDispatch } from '@wordpress/data';
|
import { useDispatch } from '@wordpress/data';
|
||||||
|
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
import { STORE_NAME } from '../stores/axoStore';
|
import { STORE_NAME } from '../stores/axoStore';
|
||||||
import { removeShippingChangeButton } from '../components/Shipping';
|
import { removeShippingChangeButton } from '../components/Shipping';
|
||||||
import { removeCardChangeButton } from '../components/Card';
|
import { removeCardChangeButton } from '../components/Card';
|
||||||
|
@ -19,9 +20,8 @@ const useAxoCleanup = () => {
|
||||||
} = useCustomerData();
|
} = useCustomerData();
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
console.log( 'Setting up cleanup for WooCommerce fields' );
|
|
||||||
return () => {
|
return () => {
|
||||||
console.log( 'Cleaning up: Restoring WooCommerce fields' );
|
log( 'Cleaning up: Restoring WooCommerce fields' );
|
||||||
restoreOriginalFields(
|
restoreOriginalFields(
|
||||||
updateWooShippingAddress,
|
updateWooShippingAddress,
|
||||||
updateWooBillingAddress
|
updateWooBillingAddress
|
||||||
|
@ -30,16 +30,15 @@ const useAxoCleanup = () => {
|
||||||
}, [ updateWooShippingAddress, updateWooBillingAddress ] );
|
}, [ updateWooShippingAddress, updateWooBillingAddress ] );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
console.log( 'Setting up cleanup for Axo component' );
|
|
||||||
return () => {
|
return () => {
|
||||||
console.log( 'Cleaning up Axo component' );
|
log( 'Cleaning up Axo component' );
|
||||||
setIsAxoActive( false );
|
setIsAxoActive( false );
|
||||||
setIsGuest( true );
|
setIsGuest( true );
|
||||||
removeShippingChangeButton();
|
removeShippingChangeButton();
|
||||||
removeCardChangeButton();
|
removeCardChangeButton();
|
||||||
removeWatermark();
|
removeWatermark();
|
||||||
if ( isEmailFunctionalitySetup() ) {
|
if ( isEmailFunctionalitySetup() ) {
|
||||||
console.log( 'Removing email functionality' );
|
log( 'Removing email functionality' );
|
||||||
removeEmailFunctionality();
|
removeEmailFunctionality();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,17 +36,12 @@ const useAxoSetup = ( ppcpConfig, fastlaneSdk, paymentComponent ) => {
|
||||||
usePhoneSyncHandler( paymentComponent );
|
usePhoneSyncHandler( paymentComponent );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
console.log( 'Initializing class toggles' );
|
|
||||||
initializeClassToggles();
|
initializeClassToggles();
|
||||||
}, [] );
|
}, [] );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
console.log( 'Setting up Axo functionality' );
|
|
||||||
setupWatermark( fastlaneSdk );
|
setupWatermark( fastlaneSdk );
|
||||||
if ( paypalLoaded && fastlaneSdk ) {
|
if ( paypalLoaded && fastlaneSdk ) {
|
||||||
console.log(
|
|
||||||
'PayPal loaded and FastlaneSDK available, setting up email functionality'
|
|
||||||
);
|
|
||||||
setIsAxoScriptLoaded( true );
|
setIsAxoScriptLoaded( true );
|
||||||
setIsAxoActive( true );
|
setIsAxoActive( true );
|
||||||
const emailLookupHandler = createEmailLookupHandler(
|
const emailLookupHandler = createEmailLookupHandler(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { useCallback } from '@wordpress/element';
|
import { useCallback } from '@wordpress/element';
|
||||||
import { useDispatch } from '@wordpress/data';
|
import { useDispatch } from '@wordpress/data';
|
||||||
|
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
import { useAddressEditing } from './useAddressEditing';
|
import { useAddressEditing } from './useAddressEditing';
|
||||||
import useCustomerData from './useCustomerData';
|
import useCustomerData from './useCustomerData';
|
||||||
import { STORE_NAME } from '../stores/axoStore';
|
import { STORE_NAME } from '../stores/axoStore';
|
||||||
|
@ -60,7 +61,7 @@ export const useCardChange = ( fastlaneSdk ) => {
|
||||||
} ),
|
} ),
|
||||||
] );
|
] );
|
||||||
} else {
|
} else {
|
||||||
console.error( 'Selected card or billing address is missing.' );
|
log( 'Selected card or billing address is missing.', 'error' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
|
|
|
@ -38,7 +38,7 @@ const useFastlaneSdk = ( axoConfig, ppcpConfig ) => {
|
||||||
|
|
||||||
setFastlaneSdk( fastlane );
|
setFastlaneSdk( fastlane );
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error( 'Failed to initialize Fastlane:', error );
|
log( `Failed to initialize Fastlane: ${ error }`, 'error' );
|
||||||
} finally {
|
} finally {
|
||||||
initializingRef.current = false;
|
initializingRef.current = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useState, useEffect } from '@wordpress/element';
|
import { useState, useEffect } from '@wordpress/element';
|
||||||
|
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
import { loadPaypalScript } from '../../../../ppcp-button/resources/js/modules/Helper/ScriptLoading';
|
import { loadPaypalScript } from '../../../../ppcp-button/resources/js/modules/Helper/ScriptLoading';
|
||||||
|
|
||||||
const usePayPalScript = ( ppcpConfig ) => {
|
const usePayPalScript = ( ppcpConfig ) => {
|
||||||
|
@ -6,9 +7,9 @@ const usePayPalScript = ( ppcpConfig ) => {
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
if ( ! isLoaded ) {
|
if ( ! isLoaded ) {
|
||||||
console.log( 'Loading PayPal script' );
|
log( 'Loading PayPal script' );
|
||||||
loadPaypalScript( ppcpConfig, () => {
|
loadPaypalScript( ppcpConfig, () => {
|
||||||
console.log( 'PayPal script loaded' );
|
log( 'PayPal script loaded' );
|
||||||
setIsLoaded( true );
|
setIsLoaded( true );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { useEffect, useRef, useCallback } from '@wordpress/element';
|
import { useEffect, useRef, useCallback } from '@wordpress/element';
|
||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
|
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
import { debounce } from '../../../../ppcp-blocks/resources/js/Helper/debounce';
|
import { debounce } from '../../../../ppcp-blocks/resources/js/Helper/debounce';
|
||||||
import { STORE_NAME } from '../stores/axoStore';
|
import { STORE_NAME } from '../stores/axoStore';
|
||||||
import useCustomerData from './useCustomerData';
|
import useCustomerData from './useCustomerData';
|
||||||
|
@ -26,7 +27,7 @@ const sanitizePhoneNumber = ( phoneNumber = '' ) => {
|
||||||
* @param {string} phoneNumber - The new phone number to prefill.
|
* @param {string} phoneNumber - The new phone number to prefill.
|
||||||
*/
|
*/
|
||||||
const updatePrefills = ( paymentComponent, phoneNumber ) => {
|
const updatePrefills = ( paymentComponent, phoneNumber ) => {
|
||||||
console.log( 'Update the phone prefill value', phoneNumber );
|
log( `Update the phone prefill value: ${ phoneNumber }` );
|
||||||
paymentComponent.updatePrefills( { phoneNumber } );
|
paymentComponent.updatePrefills( { phoneNumber } );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@ export function log( message, level = 'info' ) {
|
||||||
case 'error':
|
case 'error':
|
||||||
console.error( `[AXO] ${ message }` );
|
console.error( `[AXO] ${ message }` );
|
||||||
break;
|
break;
|
||||||
|
case 'warn':
|
||||||
|
console.warn( `[AXO] ${ message }` );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.log( `[AXO] ${ message }` );
|
console.log( `[AXO] ${ message }` );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue