Skip to content

Commit

Permalink
🔀 Merge branch 'trunk'
Browse files Browse the repository at this point in the history
# Conflicts:
#	modules/ppcp-settings/resources/js/Components/App.js
#	modules/ppcp-settings/resources/js/Components/Screens/tabs.js
  • Loading branch information
stracker-phil committed Jan 13, 2025
2 parents 1c33c42 + e4a6213 commit 2c3bb50
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

namespace WooCommerce\PayPalCommerce\PayLaterConfigurator;

use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\GetConfig;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
Expand Down Expand Up @@ -68,8 +70,9 @@ static function () use ( $c ) {
$current_page_id = $c->get( 'wcgateway.current-ppcp-settings-page-id' );
$is_wc_settings_page = $c->get( 'wcgateway.is-wc-settings-page' );
$messaging_locations = $c->get( 'paylater-configurator.messaging-locations' );
$onboarding_profile = $c->get( 'settings.data.onboarding' );

self::add_paylater_update_notice( $messaging_locations, $is_wc_settings_page, $current_page_id );
self::add_paylater_update_notice( $messaging_locations, $is_wc_settings_page, $current_page_id, $onboarding_profile );

$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
Expand Down Expand Up @@ -159,13 +162,19 @@ static function () use ( $c ) {
* The notice appears on any PayPal-Settings page, except for the Pay-Later settings page,
* when no Pay-Later messaging is used yet.
*
* @param array $message_locations PayLater messaging locations.
* @param bool $is_settings_page Whether the current page is a WC settings page.
* @param string $current_page_id ID of current settings page tab.
* @param array $message_locations PayLater messaging locations.
* @param bool $is_settings_page Whether the current page is a WC settings page.
* @param string $current_page_id ID of current settings page tab.
* @param OnboardingProfile $onboarding_profile Onboarding profile.
*
* @return void
*/
private static function add_paylater_update_notice( array $message_locations, bool $is_settings_page, string $current_page_id ) : void {
private static function add_paylater_update_notice( array $message_locations, bool $is_settings_page, string $current_page_id, OnboardingProfile $onboarding_profile ) : void {
// Don't display the notice if the user has not completed the onboarding process.
if ( $onboarding_profile->get_completed() !== true ) {
return;
}

// The message must be registered on any WC-Settings page, except for the Pay Later page.
if ( ! $is_settings_page || Settings::PAY_LATER_TAB_ID === $current_page_id ) {
return;
Expand Down
20 changes: 17 additions & 3 deletions modules/ppcp-settings/resources/js/Components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { useEffect, useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import classNames from 'classnames';

import { OnboardingHooks } from '../data';
import { OnboardingHooks, CommonHooks } from '../data';
import SpinnerOverlay from './ReusableComponents/SpinnerOverlay';
import SendOnlyMessage from './Screens/SendOnlyMessage';
import OnboardingScreen from './Screens/Onboarding';
import SettingsScreen from './Screens/Settings';

const SettingsApp = () => {
const onboardingProgress = OnboardingHooks.useSteps();
const {
isReady: merchantIsReady,
merchant: { isSendOnlyCountry },
} = CommonHooks.useMerchantInfo();

// Disable the "Changes you made might not be saved" browser warning.
useEffect( () => {
Expand All @@ -29,20 +34,29 @@ const SettingsApp = () => {
} );

const Content = useMemo( () => {
if ( ! onboardingProgress.isReady ) {
if ( ! onboardingProgress.isReady || ! merchantIsReady ) {
return (
<SpinnerOverlay
message={ __( 'Loading…', 'woocommerce-paypal-payments' ) }
/>
);
}

if ( isSendOnlyCountry ) {
return <SendOnlyMessage />;
}

if ( ! onboardingProgress.completed ) {
return <OnboardingScreen />;
}

return <SettingsScreen />;
}, [ onboardingProgress ] );
}, [
isSendOnlyCountry,
merchantIsReady,
onboardingProgress.completed,
onboardingProgress.isReady,
] );

return <div className={ wrapperClass }>{ Content }</div>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const FeatureSettingsBlock = ( { title, description, ...props } ) => {
<Button
className={ button.class ? button.class : '' }
key={ button.text }
isBusy={ props.actionProps?.isBusy }
variant={ button.type }
onClick={ button.onClick }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState, useMemo } from '@wordpress/element';
import { Button, Icon } from '@wordpress/components';
import { useDispatch } from '@wordpress/data';
import { reusableBlock } from '@wordpress/icons';
import { store as noticesStore } from '@wordpress/notices';

import SettingsCard from '../../ReusableComponents/SettingsCard';
import TodoSettingsBlock from '../../ReusableComponents/SettingsBlocks/TodoSettingsBlock';
Expand All @@ -12,13 +13,19 @@ import { useMerchantInfo } from '../../../data/common/hooks';
import { STORE_NAME } from '../../../data/common';
import Features from './TabSettingsElements/Blocks/Features';
import { todosData } from '../../../data/settings/tab-overview-todos-data';
import {
NOTIFICATION_ERROR,
NOTIFICATION_SUCCESS,
} from '../../ReusableComponents/Icons';

const TabOverview = () => {
const [ isRefreshing, setIsRefreshing ] = useState( false );

const { merchant, merchantFeatures } = useMerchantInfo();
const { refreshFeatureStatuses, setActiveModal } =
useDispatch( STORE_NAME );
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );

// Get the features data with access to setActiveModal
const featuresData = useMemo(
Expand All @@ -42,11 +49,35 @@ const TabOverview = () => {
try {
const result = await refreshFeatureStatuses();
if ( result && ! result.success ) {
console.error(
'Failed to refresh features:',
result.message || 'Unknown error'
);
}
const errorMessage = sprintf(
/* translators: %s: error message */
__(
'Operation failed: %s Check WooCommerce logs for more details.',
'woocommerce-paypal-payments'
),
result.message ||
__( 'Unknown error', 'woocommerce-paypal-payments' )
);

createErrorNotice( errorMessage, {
icon: NOTIFICATION_ERROR,
} );
console.error(
'Failed to refresh features:',
result.message || 'Unknown error'
);
} else {
createSuccessNotice(
__(
'Features refreshed successfully.',
'woocommerce-paypal-payments'
),
{
icon: NOTIFICATION_SUCCESS,
}
);
console.log( 'Features refreshed successfully.' );
}
} finally {
setIsRefreshing( false );
}
Expand Down Expand Up @@ -130,6 +161,7 @@ const TabOverview = () => {
: button.urls.live
: button.url,
} ) ),
isBusy: isRefreshing,
enabled: feature.enabled,
notes: feature.notes,
badge: feature.enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const TabPayLaterMessaging = () => {
return <div className="ppcp-r-pay-later-messaging"></div>;
};

export default TabPayLaterMessaging;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { __, sprintf } from '@wordpress/i18n';

import Container from '../ReusableComponents/Container';
import SettingsCard from '../ReusableComponents/SettingsCard';
import SettingsNavigation from './SettingsNavigation';

const SendOnlyMessage = () => {
const settingsPageUrl = '/wp-admin/admin.php?page=wc-settings';

return (
<>
<SettingsNavigation />
<Container page="settings">
<SettingsCard
title={ __(
'"Send-only" Country',
'woocommerce-paypal-payments'
) }
description={ __(
'Sellers in your country are unable to receive payments via PayPal',
'woocommerce-paypal-payments'
) }
>
<p>
{ __(
'Your current WooCommerce store location is in a "send-only" country, according to PayPal\'s policies',
'woocommerce-paypal-payments'
) }
</p>
<p>
{ __(
'Since receiving payments is essential for using the PayPal Payments extension, you are unable to connect your PayPal account while operating from a "send-only" country.',
'woocommerce-paypal-payments'
) }
</p>
<p
dangerouslySetInnerHTML={ {
__html: sprintf(
/* translators: 1: URL to the WooCommerce store location settings */
__(
'To activate PayPal, please update your <a href="%1$s">WooCommerce store location</a> to a supported region and connect a PayPal account eligible for receiving payments.',
'woocommerce-paypal-payments'
),
settingsPageUrl
),
} }
/>
</SettingsCard>
</Container>
</>
);
};

export default SendOnlyMessage;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TabOverview from '../../Overview/TabOverview';
import TabPaymentMethods from '../../Overview/TabPaymentMethods';
import TabSettings from '../../Overview/TabSettings';
import TabStyling from '../../Overview/TabStyling';
import TabPayLaterMessaging from '../../Overview/TabPayLaterMessaging';

/**
* List of all default settings tabs.
Expand Down Expand Up @@ -33,6 +34,11 @@ const DEFAULT_TABS = [
title: __( 'Styling', 'woocommerce-paypal-payments' ),
Component: <TabStyling />,
},
{
name: 'pay-later-messaging',
title: __( 'Pay Later Messaging', 'woocommerce-paypal-payments' ),
Component: <TabPayLaterMessaging />,
},
];

export const getSettingsTabs = () => {
Expand Down
3 changes: 2 additions & 1 deletion modules/ppcp-settings/resources/js/data/common/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const useWebhooks = () => {
};
};
export const useMerchantInfo = () => {
const { merchant, features } = useHooks();
const { isReady, merchant, features } = useHooks();
const { refreshMerchantData } = useDispatch( STORE_NAME );

const verifyLoginStatus = useCallback( async () => {
Expand All @@ -159,6 +159,7 @@ export const useMerchantInfo = () => {
}, [ refreshMerchantData, merchant ] );

return {
isReady,
merchant, // Merchant details
features, // Eligible merchant features
verifyLoginStatus, // Callback
Expand Down
1 change: 1 addition & 0 deletions modules/ppcp-settings/resources/js/utils/tabSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const TAB_IDS = {
PAYMENT_METHODS: 'tab-panel-0-payment-methods',
SETTINGS: 'tab-panel-0-settings',
STYLING: 'tab-panel-0-styling',
PAY_LATER_MESSAGING: 'tab-panel-0-pay-later-messaging',
};

/**
Expand Down
1 change: 1 addition & 0 deletions modules/ppcp-settings/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
return new GeneralSettings(
$container->get( 'api.shop.country' ),
$container->get( 'api.shop.currency.getter' )->get(),
$container->get( 'wcgateway.is-send-only-country' )
);
},
'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint {
Expand Down
12 changes: 8 additions & 4 deletions modules/ppcp-settings/src/Data/GeneralSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ class GeneralSettings extends AbstractDataModel {
/**
* Constructor.
*
* @param string $country WooCommerce store country.
* @param string $currency WooCommerce store currency.
* @param string $country WooCommerce store country.
* @param string $currency WooCommerce store currency.
* @param bool $is_send_only_country Whether the store's country is classified as a send-only
* country.
*
* @throws RuntimeException When forgetting to define the OPTION_KEY in this class.
*/
public function __construct( string $country, string $currency ) {
public function __construct( string $country, string $currency, bool $is_send_only_country ) {
parent::__construct();

$this->woo_settings['country'] = $country;
$this->woo_settings['currency'] = $currency;

$this->data['merchant_connected'] = $this->is_merchant_connected();
$this->data['is_send_only_country'] = $is_send_only_country;
$this->data['merchant_connected'] = $this->is_merchant_connected();
}

/**
Expand All @@ -63,6 +66,7 @@ protected function get_defaults() : array {
return array(
'use_sandbox' => false, // UI state, not a connection detail.
'use_manual_connection' => false, // UI state, not a connection detail.
'is_send_only_country' => false, // Read-only flag.

// Details about connected merchant account.
'merchant_connected' => false,
Expand Down
Loading

0 comments on commit 2c3bb50

Please sign in to comment.