mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Merge branch 'fastlane' of github.com:woocommerce/woocommerce-paypal-payments into axo-blocks-additional-minor-code-cleanup-refactor
This commit is contained in:
commit
9a041f68f1
10 changed files with 96 additions and 22 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { createElement } from '@wordpress/element';
|
import { createElement } from '@wordpress/element';
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
|
||||||
const CardChangeButton = ( { onChangeButtonClick } ) =>
|
const CardChangeButton = ( { onChangeButtonClick } ) =>
|
||||||
createElement(
|
createElement(
|
||||||
|
@ -12,7 +13,7 @@ const CardChangeButton = ( { onChangeButtonClick } ) =>
|
||||||
onChangeButtonClick();
|
onChangeButtonClick();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'Choose a different card'
|
__( 'Choose a different card', 'woocommerce-paypal-payments' )
|
||||||
);
|
);
|
||||||
|
|
||||||
export default CardChangeButton;
|
export default CardChangeButton;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { STORE_NAME } from '../../stores/axoStore';
|
import { STORE_NAME } from '../../stores/axoStore';
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useSelect } from '@wordpress/data';
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
|
||||||
const EmailButton = ( { handleSubmit } ) => {
|
const EmailButton = ( { handleSubmit } ) => {
|
||||||
const { isGuest, isAxoActive, isEmailSubmitted } = useSelect(
|
const { isGuest, isAxoActive, isEmailSubmitted } = useSelect(
|
||||||
|
@ -29,7 +30,7 @@ const EmailButton = ( { handleSubmit } ) => {
|
||||||
visibility: isEmailSubmitted ? 'hidden' : 'visible',
|
visibility: isEmailSubmitted ? 'hidden' : 'visible',
|
||||||
} }
|
} }
|
||||||
>
|
>
|
||||||
Continue
|
{ __( 'Continue', 'woocommerce-paypal-payments' ) }
|
||||||
</span>
|
</span>
|
||||||
{ isEmailSubmitted && (
|
{ isEmailSubmitted && (
|
||||||
<span
|
<span
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { useEffect, useCallback } from '@wordpress/element';
|
import { useEffect, useCallback, useState } from '@wordpress/element';
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useSelect } from '@wordpress/data';
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
import { Card } from '../Card';
|
import { Card } from '../Card';
|
||||||
import { STORE_NAME } from '../../stores/axoStore';
|
import { STORE_NAME } from '../../stores/axoStore';
|
||||||
|
|
||||||
export const Payment = ( { fastlaneSdk, onPaymentLoad } ) => {
|
export const Payment = ( { fastlaneSdk, onPaymentLoad } ) => {
|
||||||
|
const [ isCardElementReady, setIsCardElementReady ] = useState( false );
|
||||||
const { isGuest, isEmailLookupCompleted } = useSelect(
|
const { isGuest, isEmailLookupCompleted } = useSelect(
|
||||||
( select ) => ( {
|
( select ) => ( {
|
||||||
isGuest: select( STORE_NAME ).getIsGuest(),
|
isGuest: select( STORE_NAME ).getIsGuest(),
|
||||||
|
@ -14,14 +16,26 @@ export const Payment = ( { fastlaneSdk, onPaymentLoad } ) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const loadPaymentComponent = useCallback( async () => {
|
const loadPaymentComponent = useCallback( async () => {
|
||||||
if ( isGuest && isEmailLookupCompleted ) {
|
if ( isGuest && isEmailLookupCompleted && isCardElementReady ) {
|
||||||
const paymentComponent = await fastlaneSdk.FastlaneCardComponent(
|
const paymentComponent = await fastlaneSdk.FastlaneCardComponent(
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
paymentComponent.render( `#fastlane-card` );
|
paymentComponent.render( `#fastlane-card` );
|
||||||
onPaymentLoad( paymentComponent );
|
onPaymentLoad( paymentComponent );
|
||||||
}
|
}
|
||||||
}, [ isGuest, isEmailLookupCompleted, fastlaneSdk, onPaymentLoad ] );
|
}, [
|
||||||
|
isGuest,
|
||||||
|
isEmailLookupCompleted,
|
||||||
|
isCardElementReady,
|
||||||
|
fastlaneSdk,
|
||||||
|
onPaymentLoad,
|
||||||
|
] );
|
||||||
|
|
||||||
|
useEffect( () => {
|
||||||
|
if ( isGuest && isEmailLookupCompleted ) {
|
||||||
|
setIsCardElementReady( true );
|
||||||
|
}
|
||||||
|
}, [ isGuest, isEmailLookupCompleted ] );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
loadPaymentComponent();
|
loadPaymentComponent();
|
||||||
|
@ -33,7 +47,10 @@ export const Payment = ( { fastlaneSdk, onPaymentLoad } ) => {
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div id="ppcp-axo-block-radio-content">
|
<div id="ppcp-axo-block-radio-content">
|
||||||
Enter your email address above to continue.
|
{ __(
|
||||||
|
'Enter your email address above to continue.',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
) }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
|
||||||
const ShippingChangeButton = ( { onChangeShippingAddressClick } ) => (
|
const ShippingChangeButton = ( { onChangeShippingAddressClick } ) => (
|
||||||
<a
|
<a
|
||||||
className="wc-block-axo-change-link"
|
className="wc-block-axo-change-link"
|
||||||
|
@ -7,7 +9,10 @@ const ShippingChangeButton = ( { onChangeShippingAddressClick } ) => (
|
||||||
onChangeShippingAddressClick();
|
onChangeShippingAddressClick();
|
||||||
} }
|
} }
|
||||||
>
|
>
|
||||||
Choose a different shipping address
|
{ __(
|
||||||
|
'Choose a different shipping address',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
) }
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -83,10 +83,16 @@ export const populateWooFields = (
|
||||||
profileData
|
profileData
|
||||||
);
|
);
|
||||||
|
|
||||||
// Disable the 'Use same address for billing' checkbox
|
const checkoutDispatch = dispatch( CHECKOUT_STORE_KEY );
|
||||||
dispatch( CHECKOUT_STORE_KEY ).__internalSetUseShippingAsBilling( false );
|
|
||||||
|
|
||||||
// Save shipping address
|
// Uncheck the 'Use same address for billing' checkbox if the method exists.
|
||||||
|
if (
|
||||||
|
typeof checkoutDispatch.__internalSetUseShippingAsBilling === 'function'
|
||||||
|
) {
|
||||||
|
checkoutDispatch.__internalSetUseShippingAsBilling( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save shipping address.
|
||||||
const { address, name, phoneNumber } = profileData.shippingAddress;
|
const { address, name, phoneNumber } = profileData.shippingAddress;
|
||||||
|
|
||||||
const shippingAddress = {
|
const shippingAddress = {
|
||||||
|
@ -104,7 +110,7 @@ export const populateWooFields = (
|
||||||
console.log( 'Setting WooCommerce shipping address:', shippingAddress );
|
console.log( 'Setting WooCommerce shipping address:', shippingAddress );
|
||||||
setWooShippingAddress( shippingAddress );
|
setWooShippingAddress( shippingAddress );
|
||||||
|
|
||||||
// Save billing address
|
// Save billing address.
|
||||||
const billingData = profileData.card.paymentSource.card.billingAddress;
|
const billingData = profileData.card.paymentSource.card.billingAddress;
|
||||||
|
|
||||||
const billingAddress = {
|
const billingAddress = {
|
||||||
|
@ -121,6 +127,13 @@ export const populateWooFields = (
|
||||||
console.log( 'Setting WooCommerce billing address:', billingAddress );
|
console.log( 'Setting WooCommerce billing address:', billingAddress );
|
||||||
setWooBillingAddress( billingAddress );
|
setWooBillingAddress( billingAddress );
|
||||||
|
|
||||||
dispatch( CHECKOUT_STORE_KEY ).setEditingShippingAddress( false );
|
// Collapse shipping address input fields into the card view.
|
||||||
dispatch( CHECKOUT_STORE_KEY ).setEditingBillingAddress( false );
|
if ( typeof checkoutDispatch.setEditingShippingAddress === 'function' ) {
|
||||||
|
checkoutDispatch.setEditingShippingAddress( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collapse billing address input fields into the card view.
|
||||||
|
if ( typeof checkoutDispatch.setEditingBillingAddress === 'function' ) {
|
||||||
|
checkoutDispatch.setEditingBillingAddress( false );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,14 +24,18 @@ export const useAddressEditing = () => {
|
||||||
|
|
||||||
const setShippingAddressEditing = useCallback(
|
const setShippingAddressEditing = useCallback(
|
||||||
( isEditing ) => {
|
( isEditing ) => {
|
||||||
|
if ( typeof setEditingShippingAddress === 'function' ) {
|
||||||
setEditingShippingAddress( isEditing );
|
setEditingShippingAddress( isEditing );
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[ setEditingShippingAddress ]
|
[ setEditingShippingAddress ]
|
||||||
);
|
);
|
||||||
|
|
||||||
const setBillingAddressEditing = useCallback(
|
const setBillingAddressEditing = useCallback(
|
||||||
( isEditing ) => {
|
( isEditing ) => {
|
||||||
|
if ( typeof setEditingBillingAddress === 'function' ) {
|
||||||
setEditingBillingAddress( isEditing );
|
setEditingBillingAddress( isEditing );
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[ setEditingBillingAddress ]
|
[ setEditingBillingAddress ]
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { useCallback } from '@wordpress/element';
|
||||||
|
|
||||||
|
const isObject = ( value ) => typeof value === 'object' && value !== null;
|
||||||
|
const isNonEmptyString = ( value ) => value !== '';
|
||||||
|
|
||||||
|
const removeEmptyValues = ( obj ) => {
|
||||||
|
if ( ! isObject( obj ) ) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries( obj )
|
||||||
|
.map( ( [ key, value ] ) => [
|
||||||
|
key,
|
||||||
|
isObject( value ) ? removeEmptyValues( value ) : value,
|
||||||
|
] )
|
||||||
|
.filter( ( [ _, value ] ) =>
|
||||||
|
isObject( value )
|
||||||
|
? Object.keys( value ).length > 0
|
||||||
|
: isNonEmptyString( value )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDeleteEmptyKeys = () => {
|
||||||
|
return useCallback( removeEmptyValues, [] );
|
||||||
|
};
|
|
@ -1,11 +1,17 @@
|
||||||
import { useEffect, useRef, useState } from '@wordpress/element';
|
import { useEffect, useRef, useState, useMemo } from '@wordpress/element';
|
||||||
import Fastlane from '../../../../ppcp-axo/resources/js/Connection/Fastlane';
|
import Fastlane from '../../../../ppcp-axo/resources/js/Connection/Fastlane';
|
||||||
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||||
|
import { useDeleteEmptyKeys } from './useDeleteEmptyKeys';
|
||||||
|
|
||||||
const useFastlaneSdk = ( axoConfig, ppcpConfig ) => {
|
const useFastlaneSdk = ( axoConfig, ppcpConfig ) => {
|
||||||
const [ fastlaneSdk, setFastlaneSdk ] = useState( null );
|
const [ fastlaneSdk, setFastlaneSdk ] = useState( null );
|
||||||
const initializingRef = useRef( false );
|
const initializingRef = useRef( false );
|
||||||
const configRef = useRef( { axoConfig, ppcpConfig } );
|
const configRef = useRef( { axoConfig, ppcpConfig } );
|
||||||
|
const deleteEmptyKeys = useDeleteEmptyKeys();
|
||||||
|
|
||||||
|
const styleOptions = useMemo( () => {
|
||||||
|
return deleteEmptyKeys( configRef.current.axoConfig.style_options );
|
||||||
|
}, [ deleteEmptyKeys ] );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
const initFastlane = async () => {
|
const initFastlane = async () => {
|
||||||
|
@ -25,7 +31,7 @@ const useFastlaneSdk = ( axoConfig, ppcpConfig ) => {
|
||||||
|
|
||||||
await fastlane.connect( {
|
await fastlane.connect( {
|
||||||
locale: configRef.current.ppcpConfig.locale,
|
locale: configRef.current.ppcpConfig.locale,
|
||||||
styles: configRef.current.ppcpConfig.styles,
|
styles: styleOptions,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
fastlane.setLocale( 'en_us' );
|
fastlane.setLocale( 'en_us' );
|
||||||
|
@ -39,7 +45,7 @@ const useFastlaneSdk = ( axoConfig, ppcpConfig ) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
initFastlane();
|
initFastlane();
|
||||||
}, [] );
|
}, [ fastlaneSdk, styleOptions ] );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
configRef.current = { axoConfig, ppcpConfig };
|
configRef.current = { axoConfig, ppcpConfig };
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useState } from '@wordpress/element';
|
import { useState, createElement } from '@wordpress/element';
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
|
@ -50,7 +51,7 @@ const Axo = ( props ) => {
|
||||||
onPaymentLoad={ handlePaymentLoad }
|
onPaymentLoad={ handlePaymentLoad }
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div>Loading Fastlane...</div>
|
<>{ __( 'Loading Fastlane…', 'woocommerce-paypal-payments' ) }</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ registerPaymentMethod( {
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
content: <Axo />,
|
content: <Axo />,
|
||||||
edit: <h1>This is Axo Blocks in the editor</h1>,
|
edit: createElement( ppcpConfig.title ),
|
||||||
ariaLabel: ppcpConfig.title,
|
ariaLabel: ppcpConfig.title,
|
||||||
canMakePayment: () => true,
|
canMakePayment: () => true,
|
||||||
supports: {
|
supports: {
|
||||||
|
|
|
@ -243,7 +243,6 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
||||||
),
|
),
|
||||||
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
|
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
|
||||||
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
||||||
'billing_email_button_text' => __( 'Continue', 'woocommerce-paypal-payments' ),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue