Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/PCP-4093-real-data
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Jan 13, 2025

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
2 parents 8b88eae + e4a6213 commit b65ed2b
Showing 12 changed files with 136 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -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;
@@ -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 );
@@ -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;
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;
19 changes: 17 additions & 2 deletions modules/ppcp-settings/resources/js/Components/Screens/Settings.js
Original file line number Diff line number Diff line change
@@ -7,9 +7,15 @@ import SpinnerOverlay from '../ReusableComponents/SpinnerOverlay';

import Onboarding from './Onboarding/Onboarding';
import SettingsScreen from './SettingsScreen';
import { useMerchantInfo } from '../../data/common/hooks';
import SendOnlyMessage from './SendOnlyMessage';

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

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

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 <Onboarding />;
}

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

return <div className={ wrapperClass }>{ Content }</div>;
};
7 changes: 7 additions & 0 deletions modules/ppcp-settings/resources/js/Components/Screens/tabs.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,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';

export const getSettingsTabs = () => {
const tabs = [];
@@ -31,5 +32,11 @@ export const getSettingsTabs = () => {
component: <TabStyling />,
} );

tabs.push( {
name: 'pay-later-messaging',
title: __( 'Pay Later Messaging', 'woocommerce-paypal-payments' ),
component: <TabPayLaterMessaging />,
} );

return tabs;
};
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
@@ -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 () => {
@@ -159,6 +159,7 @@ export const useMerchantInfo = () => {
}, [ refreshMerchantData, merchant ] );

return {
isReady,
merchant, // Merchant details
features, // Eligible merchant features
verifyLoginStatus, // Callback
1 change: 1 addition & 0 deletions modules/ppcp-settings/resources/js/utils/tabSelector.js
Original file line number Diff line number Diff line change
@@ -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',
};

/**
1 change: 1 addition & 0 deletions modules/ppcp-settings/services.php
Original file line number Diff line number Diff line change
@@ -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 {
12 changes: 8 additions & 4 deletions modules/ppcp-settings/src/Data/GeneralSettings.php
Original file line number Diff line number Diff line change
@@ -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();
}

/**
@@ -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,
56 changes: 10 additions & 46 deletions modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
Original file line number Diff line number Diff line change
@@ -61,24 +61,27 @@ class CommonRestEndpoint extends RestEndpoint {
* @var array
*/
private array $merchant_info_map = array(
'merchant_connected' => array(
'merchant_connected' => array(
'js_name' => 'isConnected',
),
'sandbox_merchant' => array(
'sandbox_merchant' => array(
'js_name' => 'isSandbox',
),
'merchant_id' => array(
'merchant_id' => array(
'js_name' => 'id',
),
'merchant_email' => array(
'merchant_email' => array(
'js_name' => 'email',
),
'client_id' => array(
'client_id' => array(
'js_name' => 'clientId',
),
'client_secret' => array(
'client_secret' => array(
'js_name' => 'clientSecret',
),
'is_send_only_country' => array(
'js_name' => 'isSendOnlyCountry',
),
);

/**
@@ -187,40 +190,6 @@ public function get_merchant_details() : WP_REST_Response {
return $this->return_success( $js_data, $extra_data );
}

/**
* Returns mocked merchant data until real data fetching is implemented.
*
* @return array Mocked merchant details including connection status, features, etc.
*/
protected function get_mocked_merchant_data(): array {
return array(
'isConnected' => true,
'isSandbox' => false,
'id' => '',
'email' => '',
'features' => array(
'save_paypal_and_venmo' => array(
'enabled' => true,
),
'advanced_credit_and_debit_cards' => array(
'enabled' => true,
),
'alternative_payment_methods' => array(
'enabled' => true,
),
'google_pay' => array(
'enabled' => true,
),
'apple_pay' => array(
'enabled' => true,
),
'pay_later_messaging' => array(
'enabled' => true,
),
),
);
}

/**
* Appends the "merchant" attribute to the extra_data collection, which
* contains details about the merchant's PayPal account, like the merchant ID.
@@ -229,7 +198,7 @@ protected function get_mocked_merchant_data(): array {
*
* @return array Updated extra_data collection.
*/
protected function add_merchant_info( array $extra_data ): array {
protected function add_merchant_info( array $extra_data ) : array {
$extra_data['merchant'] = $this->sanitize_for_javascript(
$this->settings->to_array(),
$this->merchant_info_map
@@ -242,11 +211,6 @@ protected function add_merchant_info( array $extra_data ): array {
);
}

// If no real data is available yet, use mock data.
if ( empty( $extra_data['merchant'] ) || ( empty( $extra_data['merchant']['id'] ) && empty( $extra_data['merchant']['email'] ) ) ) {
$extra_data['merchant'] = $this->get_mocked_merchant_data();
}

return $extra_data;
}

7 changes: 4 additions & 3 deletions modules/ppcp-wc-gateway/services.php
Original file line number Diff line number Diff line change
@@ -343,9 +343,10 @@ static function ( ContainerInterface $container ): Settings {
}
),
'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice {
$state = $container->get( 'onboarding.state' );
$settings = $container->get( 'wcgateway.settings' );
return new ConnectAdminNotice( $state, $settings );
$state = $container->get( 'onboarding.state' );
$settings = $container->get( 'wcgateway.settings' );
$is_current_country_send_only = $container->get( 'wcgateway.is-send-only-country' );
return new ConnectAdminNotice( $state, $settings, $is_current_country_send_only );
},
'wcgateway.notice.currency-unsupported' => static function ( ContainerInterface $container ): UnsupportedCurrencyAdminNotice {
$state = $container->get( 'onboarding.state' );
17 changes: 13 additions & 4 deletions modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php
Original file line number Diff line number Diff line change
@@ -33,15 +33,24 @@ class ConnectAdminNotice {
*/
private $settings;

/**
* Whether the current store's country is classified as a send-only country..
*
* @var bool
*/
private bool $is_current_country_send_only;

/**
* ConnectAdminNotice constructor.
*
* @param State $state The state.
* @param ContainerInterface $settings The settings.
* @param bool $is_current_country_send_only Whether the current store's country is classified as a send-only country.
*/
public function __construct( State $state, ContainerInterface $settings ) {
$this->state = $state;
$this->settings = $settings;
public function __construct( State $state, ContainerInterface $settings, bool $is_current_country_send_only ) {
$this->state = $state;
$this->settings = $settings;
$this->is_current_country_send_only = $is_current_country_send_only;
}

/**
@@ -71,6 +80,6 @@ public function connect_message() {
* @return bool
*/
protected function should_display(): bool {
return $this->state->current_state() !== State::STATE_ONBOARDED;
return $this->state->current_state() !== State::STATE_ONBOARDED && $this->is_current_country_send_only === false;
}
}

0 comments on commit b65ed2b

Please sign in to comment.