mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
🎨 Code style changes & cleanup
- Remove unused imports - Use state instead of global window-variable (continuationFilled) - Apply codestyle rules (spaces, change one let to const)
This commit is contained in:
parent
643a23c6e0
commit
5891d80f75
1 changed files with 20 additions and 21 deletions
|
@ -19,8 +19,6 @@ import { PayPalScriptProvider, PayPalButtons } from '@paypal/react-paypal-js';
|
||||||
import { normalizeStyleForFundingSource } from '../../../ppcp-button/resources/js/modules/Helper/Style';
|
import { normalizeStyleForFundingSource } from '../../../ppcp-button/resources/js/modules/Helper/Style';
|
||||||
import buttonModuleWatcher from '../../../ppcp-button/resources/js/modules/ButtonModuleWatcher';
|
import buttonModuleWatcher from '../../../ppcp-button/resources/js/modules/ButtonModuleWatcher';
|
||||||
import BlockCheckoutMessagesBootstrap from './Bootstrap/BlockCheckoutMessagesBootstrap';
|
import BlockCheckoutMessagesBootstrap from './Bootstrap/BlockCheckoutMessagesBootstrap';
|
||||||
import { keysToCamelCase } from '../../../ppcp-button/resources/js/modules/Helper/Utils';
|
|
||||||
import { handleShippingOptionsChange } from '../../../ppcp-button/resources/js/modules/Helper/ShippingHandler';
|
|
||||||
const config = wc.wcSettings.getSetting( 'ppcp-gateway_data' );
|
const config = wc.wcSettings.getSetting( 'ppcp-gateway_data' );
|
||||||
|
|
||||||
window.ppcpFundingSource = config.fundingSource;
|
window.ppcpFundingSource = config.fundingSource;
|
||||||
|
@ -46,6 +44,7 @@ const PayPalComponent = ( {
|
||||||
const { responseTypes } = emitResponse;
|
const { responseTypes } = emitResponse;
|
||||||
|
|
||||||
const [ paypalOrder, setPaypalOrder ] = useState( null );
|
const [ paypalOrder, setPaypalOrder ] = useState( null );
|
||||||
|
const [ continuationFilled, setContinuationFilled ] = useState( false );
|
||||||
const [ gotoContinuationOnError, setGotoContinuationOnError ] =
|
const [ gotoContinuationOnError, setGotoContinuationOnError ] =
|
||||||
useState( false );
|
useState( false );
|
||||||
|
|
||||||
|
@ -65,13 +64,10 @@ const PayPalComponent = ( {
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
// fill the form if in continuation (for product or mini-cart buttons)
|
// fill the form if in continuation (for product or mini-cart buttons)
|
||||||
if (
|
if ( continuationFilled || ! config.scriptData.continuation?.order ) {
|
||||||
! config.scriptData.continuation ||
|
|
||||||
! config.scriptData.continuation.order ||
|
|
||||||
window.ppcpContinuationFilled
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const paypalAddresses = paypalOrderToWcAddresses(
|
const paypalAddresses = paypalOrderToWcAddresses(
|
||||||
config.scriptData.continuation.order
|
config.scriptData.continuation.order
|
||||||
|
@ -80,9 +76,11 @@ const PayPalComponent = ( {
|
||||||
.select( 'wc/store/cart' )
|
.select( 'wc/store/cart' )
|
||||||
.getCustomerData();
|
.getCustomerData();
|
||||||
const addresses = mergeWcAddress( wcAddresses, paypalAddresses );
|
const addresses = mergeWcAddress( wcAddresses, paypalAddresses );
|
||||||
|
|
||||||
wp.data
|
wp.data
|
||||||
.dispatch( 'wc/store/cart' )
|
.dispatch( 'wc/store/cart' )
|
||||||
.setBillingAddress( addresses.billingAddress );
|
.setBillingAddress( addresses.billingAddress );
|
||||||
|
|
||||||
if ( shippingData.needsShipping ) {
|
if ( shippingData.needsShipping ) {
|
||||||
wp.data
|
wp.data
|
||||||
.dispatch( 'wc/store/cart' )
|
.dispatch( 'wc/store/cart' )
|
||||||
|
@ -92,9 +90,10 @@ const PayPalComponent = ( {
|
||||||
// sometimes the PayPal address is missing, skip in this case.
|
// sometimes the PayPal address is missing, skip in this case.
|
||||||
console.log( err );
|
console.log( err );
|
||||||
}
|
}
|
||||||
|
|
||||||
// this useEffect should run only once, but adding this in case of some kind of full re-rendering
|
// this useEffect should run only once, but adding this in case of some kind of full re-rendering
|
||||||
window.ppcpContinuationFilled = true;
|
setContinuationFilled( true );
|
||||||
}, [] );
|
}, [ shippingData, continuationFilled ] );
|
||||||
|
|
||||||
const createOrder = async ( data, actions ) => {
|
const createOrder = async ( data, actions ) => {
|
||||||
try {
|
try {
|
||||||
|
@ -364,19 +363,19 @@ const PayPalComponent = ( {
|
||||||
};
|
};
|
||||||
|
|
||||||
const shouldHandleShippingInPayPal = () => {
|
const shouldHandleShippingInPayPal = () => {
|
||||||
return shouldskipFinalConfirmation() && config.needShipping
|
return shouldskipFinalConfirmation() && config.needShipping;
|
||||||
};
|
};
|
||||||
|
|
||||||
const shouldskipFinalConfirmation = () => {
|
const shouldskipFinalConfirmation = () => {
|
||||||
if ( config.finalReviewEnabled ) {
|
if ( config.finalReviewEnabled ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
window.ppcpFundingSource !== 'venmo' ||
|
window.ppcpFundingSource !== 'venmo' ||
|
||||||
! config.scriptData.vaultingEnabled
|
! config.scriptData.vaultingEnabled
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let handleShippingOptionsChange = null;
|
let handleShippingOptionsChange = null;
|
||||||
let handleShippingAddressChange = null;
|
let handleShippingAddressChange = null;
|
||||||
|
@ -610,11 +609,11 @@ const PayPalComponent = ( {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( data, actions ) => {
|
return ( data, actions ) => {
|
||||||
let shippingAddressChange = shouldHandleShippingInPayPal()
|
const shippingAddressChange = shouldHandleShippingInPayPal()
|
||||||
? handleShippingAddressChange( data, actions )
|
? handleShippingAddressChange( data, actions )
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return shippingAddressChange;
|
return shippingAddressChange;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue