mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge branch 'trunk' of github.com:woocommerce/woocommerce-paypal-payments into PCP-3770-fastlane-implement-insights-sdk-for-block-checkout-ver2
This commit is contained in:
commit
1dfcc13da4
182 changed files with 33627 additions and 71261 deletions
7142
modules/ppcp-axo-block/package-lock.json
generated
7142
modules/ppcp-axo-block/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -12,22 +12,22 @@
|
|||
"dependencies": {
|
||||
"@paypal/paypal-js": "^8.1.1",
|
||||
"@paypal/react-paypal-js": "^8.5.0",
|
||||
"core-js": "^3.25.0",
|
||||
"react": "^17.0.0",
|
||||
"react-dom": "^17.0.0"
|
||||
"core-js": "^3.39",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.19",
|
||||
"@babel/preset-env": "^7.19",
|
||||
"@babel/preset-react": "^7.18.6",
|
||||
"@babel/core": "^7.26",
|
||||
"@babel/preset-env": "^7.26",
|
||||
"@babel/preset-react": "^7.25",
|
||||
"@woocommerce/dependency-extraction-webpack-plugin": "2.2.0",
|
||||
"babel-loader": "^8.2",
|
||||
"babel-loader": "^9.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"file-loader": "^6.2.0",
|
||||
"sass": "^1.42.1",
|
||||
"sass-loader": "^12.1.0",
|
||||
"webpack": "^5.76",
|
||||
"webpack-cli": "^4.10"
|
||||
"sass": "^1.80",
|
||||
"sass-loader": "^16",
|
||||
"webpack": "^5.96",
|
||||
"webpack-cli": "^5"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import { useMemo } from '@wordpress/element';
|
||||
|
||||
/**
|
||||
* Custom hook returning the allowed shipping locations based on configuration.
|
||||
*
|
||||
* @param {Object} axoConfig - The AXO configuration object.
|
||||
* @param {Array|undefined} axoConfig.enabled_shipping_locations - The list of enabled shipping locations.
|
||||
* @return {Array} The final list of allowed shipping locations.
|
||||
*/
|
||||
const useAllowedLocations = ( axoConfig ) => {
|
||||
return useMemo( () => {
|
||||
const enabledShippingLocations =
|
||||
axoConfig.enabled_shipping_locations || [];
|
||||
|
||||
return Array.isArray( enabledShippingLocations )
|
||||
? enabledShippingLocations
|
||||
: [];
|
||||
}, [ axoConfig.enabled_shipping_locations ] );
|
||||
};
|
||||
|
||||
export default useAllowedLocations;
|
|
@ -3,6 +3,7 @@ import { useSelect } from '@wordpress/data';
|
|||
import Fastlane from '../../../../ppcp-axo/resources/js/Connection/Fastlane';
|
||||
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||
import { useDeleteEmptyKeys } from './useDeleteEmptyKeys';
|
||||
import useAllowedLocations from './useAllowedLocations';
|
||||
import { STORE_NAME } from '../stores/axoStore';
|
||||
|
||||
/**
|
||||
|
@ -30,6 +31,8 @@ const useFastlaneSdk = ( namespace, axoConfig, ppcpConfig ) => {
|
|||
return deleteEmptyKeys( configRef.current.axoConfig.style_options );
|
||||
}, [ deleteEmptyKeys ] );
|
||||
|
||||
const allowedLocations = useAllowedLocations( axoConfig );
|
||||
|
||||
// Effect to initialize Fastlane SDK
|
||||
useEffect( () => {
|
||||
const initFastlane = async () => {
|
||||
|
@ -52,6 +55,9 @@ const useFastlaneSdk = ( namespace, axoConfig, ppcpConfig ) => {
|
|||
await fastlane.connect( {
|
||||
locale: configRef.current.ppcpConfig.locale,
|
||||
styles: styleOptions,
|
||||
shippingAddressOptions: {
|
||||
allowedLocations,
|
||||
},
|
||||
} );
|
||||
|
||||
// Set locale (hardcoded to 'en_us' for now)
|
||||
|
@ -66,7 +72,13 @@ const useFastlaneSdk = ( namespace, axoConfig, ppcpConfig ) => {
|
|||
};
|
||||
|
||||
initFastlane();
|
||||
}, [ fastlaneSdk, styleOptions, isPayPalLoaded, namespace ] );
|
||||
}, [
|
||||
fastlaneSdk,
|
||||
styleOptions,
|
||||
isPayPalLoaded,
|
||||
namespace,
|
||||
allowedLocations,
|
||||
] );
|
||||
|
||||
// Effect to update the config ref when configs change
|
||||
useEffect( () => {
|
||||
|
|
|
@ -38,7 +38,8 @@ return array(
|
|||
$container->get( 'wcgateway.configuration.dcc' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'axo.payment_method_selected_map' ),
|
||||
$container->get( 'wcgateway.url' )
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'axo.shipping-wc-enabled-locations' )
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -86,6 +86,13 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
*/
|
||||
private $wcgateway_module_url;
|
||||
|
||||
/**
|
||||
* The list of WooCommerce enabled shipping locations.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $enabled_shipping_locations;
|
||||
|
||||
/**
|
||||
* AdvancedCardPaymentMethod constructor.
|
||||
*
|
||||
|
@ -99,6 +106,7 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
* @param Environment $environment The environment object.
|
||||
* @param array $payment_method_selected_map Mapping of payment methods to the PayPal Insights 'payment_method_selected' types.
|
||||
* @param string $wcgateway_module_url The WcGateway module URL.
|
||||
* @param array $enabled_shipping_locations The list of WooCommerce enabled shipping locations.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
|
@ -108,20 +116,21 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
Settings $settings,
|
||||
DCCGatewayConfiguration $dcc_configuration,
|
||||
Environment $environment,
|
||||
string $wcgateway_module_url,
|
||||
array $payment_method_selected_map,
|
||||
string $wcgateway_module_url
|
||||
array $enabled_shipping_locations
|
||||
) {
|
||||
$this->name = AxoGateway::ID;
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->gateway = $gateway;
|
||||
$this->smart_button = $smart_button;
|
||||
$this->settings = $settings;
|
||||
$this->dcc_configuration = $dcc_configuration;
|
||||
$this->environment = $environment;
|
||||
$this->name = AxoGateway::ID;
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->gateway = $gateway;
|
||||
$this->smart_button = $smart_button;
|
||||
$this->settings = $settings;
|
||||
$this->dcc_configuration = $dcc_configuration;
|
||||
$this->environment = $environment;
|
||||
$this->wcgateway_module_url = $wcgateway_module_url;
|
||||
$this->payment_method_selected_map = $payment_method_selected_map;
|
||||
$this->wcgateway_module_url = $wcgateway_module_url;
|
||||
|
||||
$this->enabled_shipping_locations = $enabled_shipping_locations;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,10 +206,10 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
}
|
||||
|
||||
return array(
|
||||
'environment' => array(
|
||||
'environment' => array(
|
||||
'is_sandbox' => $this->environment->current_environment() === 'sandbox',
|
||||
),
|
||||
'widgets' => array(
|
||||
'widgets' => array(
|
||||
'email' => 'render',
|
||||
),
|
||||
'insights' => array(
|
||||
|
@ -218,7 +227,8 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
),
|
||||
'payment_method_selected_map' => $this->payment_method_selected_map,
|
||||
),
|
||||
'style_options' => array(
|
||||
'enabled_shipping_locations' => $this->enabled_shipping_locations,
|
||||
'style_options' => array(
|
||||
'root' => array(
|
||||
'backgroundColor' => $this->settings->has( 'axo_style_root_bg_color' ) ? $this->settings->get( 'axo_style_root_bg_color' ) : '',
|
||||
'errorColor' => $this->settings->has( 'axo_style_root_error_color' ) ? $this->settings->get( 'axo_style_root_error_color' ) : '',
|
||||
|
@ -237,23 +247,23 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
'focusBorderColor' => $this->settings->has( 'axo_style_input_focus_border_color' ) ? $this->settings->get( 'axo_style_input_focus_border_color' ) : '',
|
||||
),
|
||||
),
|
||||
'name_on_card' => $this->dcc_configuration->show_name_on_card(),
|
||||
'woocommerce' => array(
|
||||
'name_on_card' => $this->dcc_configuration->show_name_on_card(),
|
||||
'woocommerce' => array(
|
||||
'states' => array(
|
||||
'US' => WC()->countries->get_states( 'US' ),
|
||||
'CA' => WC()->countries->get_states( 'CA' ),
|
||||
),
|
||||
),
|
||||
'icons_directory' => esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/',
|
||||
'module_url' => untrailingslashit( $this->module_url ),
|
||||
'ajax' => array(
|
||||
'icons_directory' => esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/',
|
||||
'module_url' => untrailingslashit( $this->module_url ),
|
||||
'ajax' => array(
|
||||
'frontend_logger' => array(
|
||||
'endpoint' => \WC_AJAX::get_endpoint( FrontendLoggerEndpoint::ENDPOINT ),
|
||||
'nonce' => wp_create_nonce( FrontendLoggerEndpoint::nonce() ),
|
||||
),
|
||||
),
|
||||
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
|
||||
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
||||
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
|
||||
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue