mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Merge branch 'refs/heads/trunk' into PCP-4210-features-refactor-to-use-rest-endpoints
This commit is contained in:
commit
7b8c3b0bc6
20 changed files with 523 additions and 214 deletions
|
@ -24,6 +24,10 @@
|
||||||
padding-top: var(--block-separator-gap, 32px);
|
padding-top: var(--block-separator-gap, 32px);
|
||||||
border-top: var(--block-separator-size, 1px) solid var(--block-separator-color);
|
border-top: var(--block-separator-size, 1px) solid var(--block-separator-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.ppcp--pull-right {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ppcp-r-settings-block {
|
.ppcp-r-settings-block {
|
||||||
|
|
|
@ -70,16 +70,33 @@ $width_gap: 24px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ .ppcp-r-settings-card {
|
||||||
|
margin-top: $card-vertical-gap;
|
||||||
|
padding-top: $card-vertical-gap;
|
||||||
|
border-top: 1px solid $color-gray-200;
|
||||||
|
}
|
||||||
|
|
||||||
.ppcp--card-actions {
|
.ppcp--card-actions {
|
||||||
opacity: 0.5;
|
|
||||||
transition: opacity 0.3s;
|
transition: opacity 0.3s;
|
||||||
|
|
||||||
|
&.ppcp--dimmed {
|
||||||
|
opacity: 0.5;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.components-button.is-tertiary:first-child {
|
.components-button.is-tertiary {
|
||||||
|
transition: color 0.3s, background 0.3s;
|
||||||
|
|
||||||
|
&:first-child {
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
svg {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,3 @@
|
||||||
padding-bottom: 36px;
|
padding-bottom: 36px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ppcp-r-settings {
|
|
||||||
> * {
|
|
||||||
margin-bottom: $card-vertical-gap;
|
|
||||||
}
|
|
||||||
|
|
||||||
> *:not(:last-child) {
|
|
||||||
padding-bottom: $card-vertical-gap;
|
|
||||||
border-bottom: 1px solid $color-gray-200;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -227,11 +227,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Payment Methods
|
// Payment Methods
|
||||||
.ppcp-r-payment-methods {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 48px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ppcp-highlight {
|
.ppcp-highlight {
|
||||||
animation: ppcp-highlight-fade 2s cubic-bezier(0.4, 0, 0.2, 1);
|
animation: ppcp-highlight-fade 2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#configurator-eligibleContainer.css-4nclxm.e1vy3g880 {
|
#configurator-eligibleContainer.css-4nclxm.e1vy3g880 {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
padding: 48px 0px 48px 48px;
|
padding: 16px 0px 16px 16px;
|
||||||
|
|
||||||
#configurator-controlPanelContainer.css-5urmrq.e1vy3g880 {
|
#configurator-controlPanelContainer.css-5urmrq.e1vy3g880 {
|
||||||
width: 374px;
|
width: 374px;
|
||||||
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
.css-7xkxom, .css-8tvj6u {
|
.css-7xkxom, .css-8tvj6u {
|
||||||
height: auto;
|
height: auto;
|
||||||
|
width: 1.2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.css-10nkerk.ej6n7t60 {
|
.css-10nkerk.ej6n7t60 {
|
||||||
|
@ -37,14 +38,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.css-1vc34jy-handler {
|
.css-1vc34jy-handler {
|
||||||
height: 1.6rem;
|
height: 1.7em;
|
||||||
width: 1.6rem;
|
width: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.css-8vwtr6-state {
|
.css-8vwtr6-state {
|
||||||
height: 1.6rem;
|
height: 1.4rem;
|
||||||
|
width: 3rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.css-1s8clkf.etu8a6w2 {
|
||||||
|
width: 374px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__subheader, #configurator-controlPanelSubHeader {
|
&__subheader, #configurator-controlPanelSubHeader {
|
||||||
|
@ -68,6 +74,7 @@
|
||||||
|
|
||||||
.css-rok10q, .css-dfgbdq-text_body_strong {
|
.css-rok10q, .css-dfgbdq-text_body_strong {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__publish-button {
|
&__publish-button {
|
||||||
|
@ -110,4 +117,30 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.css-n4cwz8 {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.css-1ce6bcu-container {
|
||||||
|
width: 3rem;
|
||||||
|
height: 1.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#configurator-previewSectionSubHeaderText {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.css-zcyvrz.ej6n7t60 {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
|
||||||
|
.css-3xbhoy-svg-size_md-icon {
|
||||||
|
width: 1.5rem;
|
||||||
|
height: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.css-7i5kpm-icon-button_base-size_xl-size_sm-secondary {
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
--block-separator-gap: 24px;
|
--block-separator-gap: 24px;
|
||||||
--block-header-gap: 18px;
|
--block-header-gap: 18px;
|
||||||
--panel-width: 422px;
|
--panel-width: 422px;
|
||||||
--sticky-offset-top: 92px; // 32px admin-bar + 60px TopNavigation height
|
--sticky-offset-top: 132px; // 32px admin-bar + 100px TopNavigation height
|
||||||
--preview-height-reduction: 236px; // 32px admin-bar + 60px TopNavigation height + 48px TopNavigation margin + 48px TabList height + 48px TabList margin
|
--preview-height-reduction: 276px; // 32px admin-bar + 100px TopNavigation height + 48px TopNavigation margin + 48px TabList height + 48px TabList margin
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
border: 1px solid var(--color-separators);
|
border: 1px solid var(--color-separators);
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
const CardActions = ( { isDimmed = false, children } ) => {
|
||||||
|
const className = classNames( 'ppcp--card-actions', {
|
||||||
|
'ppcp--dimmed': isDimmed,
|
||||||
|
} );
|
||||||
|
|
||||||
|
return <div className={ className }>{ children }</div>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CardActions;
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { default as Action } from './Action';
|
export { default as Action } from './Action';
|
||||||
|
export { default as CardActions } from './CardActions';
|
||||||
export { default as Content } from './Content';
|
export { default as Content } from './Content';
|
||||||
export { default as ContentWrapper } from './ContentWrapper';
|
export { default as ContentWrapper } from './ContentWrapper';
|
||||||
export { default as Description } from './Description';
|
export { default as Description } from './Description';
|
||||||
|
|
|
@ -11,7 +11,7 @@ const PricingDescription = () => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastDate = 'October 25th, 2024'; // TODO -- needs to be the last plugin update date.
|
const lastDate = 'February 1st, 2025'; // TODO -- needs to be the last plugin update date.
|
||||||
const countryLinks = learnMoreLinks[ storeCountry ] || learnMoreLinks.US;
|
const countryLinks = learnMoreLinks[ storeCountry ] || learnMoreLinks.US;
|
||||||
|
|
||||||
const label = sprintf(
|
const label = sprintf(
|
||||||
|
|
|
@ -76,7 +76,17 @@ const StepProducts = () => {
|
||||||
'woocommerce-paypal-payments'
|
'woocommerce-paypal-payments'
|
||||||
),
|
),
|
||||||
isDisabled: isCasualSeller,
|
isDisabled: isCasualSeller,
|
||||||
contents: <DetailsSubscriptions showNotice={ isCasualSeller } />,
|
contents: (
|
||||||
|
/*
|
||||||
|
* Note: The link should be only displayed if the subscriptions plugin is not installed.
|
||||||
|
* But when the plugin is not active, this option is completely hidden;
|
||||||
|
* This means: In the current configuration, we never show the link.
|
||||||
|
*/
|
||||||
|
<DetailsSubscriptions
|
||||||
|
showLink={ false }
|
||||||
|
showNotice={ isCasualSeller }
|
||||||
|
/>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
return (
|
return (
|
||||||
|
@ -117,14 +127,19 @@ const DetailsPhysical = () => (
|
||||||
</ul>
|
</ul>
|
||||||
);
|
);
|
||||||
|
|
||||||
const DetailsSubscriptions = ( { showNotice } ) => (
|
const DetailsSubscriptions = ( { showLink, showNotice } ) => (
|
||||||
<>
|
<>
|
||||||
|
{ showLink && (
|
||||||
<a
|
<a
|
||||||
target="__blank"
|
target="__blank"
|
||||||
href="https://woocommerce.com/document/woocommerce-paypal-payments/#subscriptions-faq"
|
href="https://woocommerce.com/document/woocommerce-paypal-payments/#subscriptions-faq"
|
||||||
>
|
>
|
||||||
{ __( 'WooCommerce Subscriptions', 'woocommerce-paypal-payments' ) }
|
{ __(
|
||||||
|
'WooCommerce Subscriptions',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
) }
|
||||||
</a>
|
</a>
|
||||||
|
) }
|
||||||
{ showNotice && (
|
{ showNotice && (
|
||||||
<p>
|
<p>
|
||||||
{ __(
|
{ __(
|
||||||
|
|
|
@ -7,6 +7,7 @@ import ConnectionStatusBadge from './Parts/ConnectionStatusBadge';
|
||||||
import DisconnectButton from './Parts/DisconnectButton';
|
import DisconnectButton from './Parts/DisconnectButton';
|
||||||
import SettingsBlock from '../../../../ReusableComponents/SettingsBlock';
|
import SettingsBlock from '../../../../ReusableComponents/SettingsBlock';
|
||||||
import { ControlStaticValue } from '../../../../ReusableComponents/Controls';
|
import { ControlStaticValue } from '../../../../ReusableComponents/Controls';
|
||||||
|
import { CardActions } from '../../../../ReusableComponents/Elements';
|
||||||
|
|
||||||
const ConnectionStatus = () => {
|
const ConnectionStatus = () => {
|
||||||
const merchant = CommonHooks.useMerchant();
|
const merchant = CommonHooks.useMerchant();
|
||||||
|
@ -21,18 +22,20 @@ const ConnectionStatus = () => {
|
||||||
title={ __( 'Connection status', 'woocommerce-paypal-payments' ) }
|
title={ __( 'Connection status', 'woocommerce-paypal-payments' ) }
|
||||||
description={ <ConnectionDescription /> }
|
description={ <ConnectionDescription /> }
|
||||||
>
|
>
|
||||||
<SettingsBlock>
|
<SettingsBlock className="ppcp--pull-right">
|
||||||
<ControlStaticValue
|
<ControlStaticValue
|
||||||
value={
|
value={
|
||||||
<ConnectionStatusBadge
|
<ConnectionStatusBadge
|
||||||
isActive={ merchant.isConnected }
|
isActive={ merchant.isConnected }
|
||||||
isSandbox={ merchant.isSandbox }
|
isSandbox={ merchant.isSandbox }
|
||||||
|
isBusinessSeller={ merchant.isBusinessSeller }
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</SettingsBlock>
|
</SettingsBlock>
|
||||||
<SettingsBlock
|
<SettingsBlock
|
||||||
title={ __( 'Merchant ID', 'woocommerce-paypal-payments' ) }
|
title={ __( 'Merchant ID', 'woocommerce-paypal-payments' ) }
|
||||||
|
className="ppcp--no-gap"
|
||||||
>
|
>
|
||||||
<ControlStaticValue value={ merchant.id } />
|
<ControlStaticValue value={ merchant.id } />
|
||||||
</SettingsBlock>
|
</SettingsBlock>
|
||||||
|
@ -59,9 +62,9 @@ const ConnectionDescription = () => {
|
||||||
'Your PayPal account connection details.',
|
'Your PayPal account connection details.',
|
||||||
'woocommerce-paypal-payments'
|
'woocommerce-paypal-payments'
|
||||||
) }
|
) }
|
||||||
<div className="ppcp--card-actions">
|
<CardActions isDimmed={ true }>
|
||||||
<DisconnectButton />
|
<DisconnectButton />
|
||||||
</div>
|
</CardActions>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
Content,
|
Content,
|
||||||
ContentWrapper,
|
ContentWrapper,
|
||||||
} from '../../../../ReusableComponents/Elements';
|
} from '../../../../ReusableComponents/Elements';
|
||||||
import ConnectionDetails from './Blocks/ConnectionDetails';
|
|
||||||
import Troubleshooting from './Blocks/Troubleshooting';
|
import Troubleshooting from './Blocks/Troubleshooting';
|
||||||
import PaypalSettings from './Blocks/PaypalSettings';
|
import PaypalSettings from './Blocks/PaypalSettings';
|
||||||
import OtherSettings from './Blocks/OtherSettings';
|
import OtherSettings from './Blocks/OtherSettings';
|
||||||
|
@ -29,12 +28,12 @@ const ExpertSettings = () => {
|
||||||
contentContainer={ false }
|
contentContainer={ false }
|
||||||
>
|
>
|
||||||
<ContentWrapper>
|
<ContentWrapper>
|
||||||
<Content>
|
{ /*<Content>
|
||||||
<ConnectionDetails
|
<ConnectionDetails
|
||||||
updateFormValue={ updateFormValue }
|
updateFormValue={ updateFormValue }
|
||||||
settings={ settings }
|
settings={ settings }
|
||||||
/>
|
/>
|
||||||
</Content>
|
</Content>*/ }
|
||||||
|
|
||||||
<Content>
|
<Content>
|
||||||
<Troubleshooting
|
<Troubleshooting
|
||||||
|
|
|
@ -5,11 +5,19 @@ import TitleBadge, {
|
||||||
TITLE_BADGE_POSITIVE,
|
TITLE_BADGE_POSITIVE,
|
||||||
} from '../../../../../ReusableComponents/TitleBadge';
|
} from '../../../../../ReusableComponents/TitleBadge';
|
||||||
|
|
||||||
const ConnectionStatusBadge = ( { isActive, isSandbox } ) => {
|
const ConnectionStatusBadge = ( { isActive, isSandbox, isBusinessSeller } ) => {
|
||||||
if ( isActive ) {
|
if ( isActive ) {
|
||||||
const label = isSandbox
|
let label;
|
||||||
? __( 'Sandbox Mode', 'woocommerce-paypal-payments' )
|
|
||||||
|
if ( isBusinessSeller ) {
|
||||||
|
label = isSandbox
|
||||||
|
? __( 'Business | Sandbox', 'woocommerce-paypal-payments' )
|
||||||
|
: __( 'Business | Live', 'woocommerce-paypal-payments' );
|
||||||
|
} else {
|
||||||
|
label = isSandbox
|
||||||
|
? __( 'Sandbox', 'woocommerce-paypal-payments' )
|
||||||
: __( 'Active', 'woocommerce-paypal-payments' );
|
: __( 'Active', 'woocommerce-paypal-payments' );
|
||||||
|
}
|
||||||
|
|
||||||
return <TitleBadge type={ TITLE_BADGE_POSITIVE } text={ label } />;
|
return <TitleBadge type={ TITLE_BADGE_POSITIVE } text={ label } />;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,11 @@ import {
|
||||||
TodoSettingsBlock,
|
TodoSettingsBlock,
|
||||||
FeatureSettingsBlock,
|
FeatureSettingsBlock,
|
||||||
} from '../../../ReusableComponents/SettingsBlocks';
|
} from '../../../ReusableComponents/SettingsBlocks';
|
||||||
import { Content, ContentWrapper } from '../../../ReusableComponents/Elements';
|
import {
|
||||||
|
Content,
|
||||||
|
ContentWrapper,
|
||||||
|
CardActions,
|
||||||
|
} from '../../../ReusableComponents/Elements';
|
||||||
import SettingsCard from '../../../ReusableComponents/SettingsCard';
|
import SettingsCard from '../../../ReusableComponents/SettingsCard';
|
||||||
import { TITLE_BADGE_POSITIVE } from '../../../ReusableComponents/TitleBadge';
|
import { TITLE_BADGE_POSITIVE } from '../../../ReusableComponents/TitleBadge';
|
||||||
import {
|
import {
|
||||||
|
@ -92,6 +96,7 @@ const OverviewTodos = () => {
|
||||||
'woocommerce-paypal-payments'
|
'woocommerce-paypal-payments'
|
||||||
) }
|
) }
|
||||||
</p>
|
</p>
|
||||||
|
<CardActions>
|
||||||
<Button
|
<Button
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
onClick={ resetHandler }
|
onClick={ resetHandler }
|
||||||
|
@ -99,12 +104,16 @@ const OverviewTodos = () => {
|
||||||
>
|
>
|
||||||
<Icon icon={ reusableBlock } size={ 18 } />
|
<Icon icon={ reusableBlock } size={ 18 } />
|
||||||
{ isResetting
|
{ isResetting
|
||||||
? __( 'Restoring…', 'woocommerce-paypal-payments' )
|
? __(
|
||||||
|
'Restoring…',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
)
|
||||||
: __(
|
: __(
|
||||||
'Restore dismissed Things To Do',
|
'Restore dismissed Things To Do',
|
||||||
'woocommerce-paypal-payments'
|
'woocommerce-paypal-payments'
|
||||||
) }
|
) }
|
||||||
</Button>
|
</Button>
|
||||||
|
</CardActions>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
@ -300,6 +309,7 @@ const OverviewFeatureDescription = ( { refreshHandler, isRefreshing } ) => {
|
||||||
'woocommerce-paypal-payments'
|
'woocommerce-paypal-payments'
|
||||||
) }
|
) }
|
||||||
</p>
|
</p>
|
||||||
|
<CardActions>
|
||||||
<Button
|
<Button
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
onClick={ refreshHandler }
|
onClick={ refreshHandler }
|
||||||
|
@ -308,6 +318,7 @@ const OverviewFeatureDescription = ( { refreshHandler, isRefreshing } ) => {
|
||||||
<Icon icon={ reusableBlock } size={ 18 } />
|
<Icon icon={ reusableBlock } size={ 18 } />
|
||||||
{ buttonLabel }
|
{ buttonLabel }
|
||||||
</Button>
|
</Button>
|
||||||
|
</CardActions>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,6 +37,7 @@ use WooCommerce\PayPalCommerce\Settings\Service\ConnectionUrlGenerator;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Service\FeaturesEligibilityService;
|
use WooCommerce\PayPalCommerce\Settings\Service\FeaturesEligibilityService;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Service\OnboardingUrlManager;
|
use WooCommerce\PayPalCommerce\Settings\Service\OnboardingUrlManager;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Service\TodosEligibilityService;
|
use WooCommerce\PayPalCommerce\Settings\Service\TodosEligibilityService;
|
||||||
|
use WooCommerce\PayPalCommerce\Settings\Service\TodosSortingAndFilteringService;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Service\DataSanitizer;
|
use WooCommerce\PayPalCommerce\Settings\Service\DataSanitizer;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Service\SettingsDataManager;
|
use WooCommerce\PayPalCommerce\Settings\Service\SettingsDataManager;
|
||||||
|
@ -340,7 +341,8 @@ return array(
|
||||||
return new TodosRestEndpoint(
|
return new TodosRestEndpoint(
|
||||||
$container->get( 'settings.data.todos' ),
|
$container->get( 'settings.data.todos' ),
|
||||||
$container->get( 'settings.data.definition.todos' ),
|
$container->get( 'settings.data.definition.todos' ),
|
||||||
$container->get( 'settings.rest.settings' )
|
$container->get( 'settings.rest.settings' ),
|
||||||
|
$container->get( 'settings.service.todos_sorting' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'settings.data.todos' => static function ( ContainerInterface $container ) : TodosModel {
|
'settings.data.todos' => static function ( ContainerInterface $container ) : TodosModel {
|
||||||
|
@ -358,17 +360,10 @@ return array(
|
||||||
$container->get( 'settings.data.payment' ),
|
$container->get( 'settings.data.payment' ),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'settings.service.todos_eligibilities' => static function ( ContainerInterface $container ) : TodosEligibilityService {
|
'settings.service.pay_later_status' => static function ( ContainerInterface $container ) : array {
|
||||||
$features = apply_filters(
|
|
||||||
'woocommerce_paypal_payments_rest_common_merchant_features',
|
|
||||||
array()
|
|
||||||
);
|
|
||||||
|
|
||||||
$payment_endpoint = $container->get( 'settings.rest.payment' );
|
|
||||||
$settings = $payment_endpoint->get_details()->get_data();
|
|
||||||
|
|
||||||
$pay_later_endpoint = $container->get( 'settings.rest.pay_later_messaging' );
|
$pay_later_endpoint = $container->get( 'settings.rest.pay_later_messaging' );
|
||||||
$pay_later_settings = $pay_later_endpoint->get_details()->get_data();
|
$pay_later_settings = $pay_later_endpoint->get_details()->get_data();
|
||||||
|
|
||||||
$pay_later_statuses = array(
|
$pay_later_statuses = array(
|
||||||
'cart' => $pay_later_settings['data']['cart']['status'] === 'enabled',
|
'cart' => $pay_later_settings['data']['cart']['status'] === 'enabled',
|
||||||
'checkout' => $pay_later_settings['data']['checkout']['status'] === 'enabled',
|
'checkout' => $pay_later_settings['data']['checkout']['status'] === 'enabled',
|
||||||
|
@ -379,16 +374,41 @@ return array(
|
||||||
$pay_later_settings['data']['custom_placement'][0]['status'] === 'enabled',
|
$pay_later_settings['data']['custom_placement'][0]['status'] === 'enabled',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Settings status.
|
$is_pay_later_messaging_enabled_for_any_location = ! array_filter( $pay_later_statuses );
|
||||||
$gateways = array(
|
|
||||||
|
return array(
|
||||||
|
'statuses' => $pay_later_statuses,
|
||||||
|
'is_enabled_for_any_location' => $is_pay_later_messaging_enabled_for_any_location,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'settings.service.button_locations' => static function ( ContainerInterface $container ) : array {
|
||||||
|
$styling_endpoint = $container->get( 'settings.rest.styling' );
|
||||||
|
$styling_data = $styling_endpoint->get_details()->get_data()['data'];
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'cart_enabled' => $styling_data['cart']->enabled ?? false,
|
||||||
|
'block_checkout_enabled' => $styling_data['expressCheckout']->enabled ?? false,
|
||||||
|
'product_enabled' => $styling_data['product']->enabled ?? false,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'settings.service.gateways_status' => static function ( ContainerInterface $container ) : array {
|
||||||
|
$payment_endpoint = $container->get( 'settings.rest.payment' );
|
||||||
|
$settings = $payment_endpoint->get_details()->get_data();
|
||||||
|
|
||||||
|
return array(
|
||||||
'apple_pay' => $settings['data']['ppcp-applepay']['enabled'] ?? false,
|
'apple_pay' => $settings['data']['ppcp-applepay']['enabled'] ?? false,
|
||||||
'google_pay' => $settings['data']['ppcp-googlepay']['enabled'] ?? false,
|
'google_pay' => $settings['data']['ppcp-googlepay']['enabled'] ?? false,
|
||||||
'axo' => $settings['data']['ppcp-axo-gateway']['enabled'] ?? false,
|
'axo' => $settings['data']['ppcp-axo-gateway']['enabled'] ?? false,
|
||||||
'card-button' => $settings['data']['ppcp-card-button-gateway']['enabled'] ?? false,
|
'card-button' => $settings['data']['ppcp-card-button-gateway']['enabled'] ?? false,
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
'settings.service.merchant_capabilities' => static function ( ContainerInterface $container ) : array {
|
||||||
|
$features = apply_filters(
|
||||||
|
'woocommerce_paypal_payments_rest_common_merchant_features',
|
||||||
|
array()
|
||||||
|
);
|
||||||
|
|
||||||
// Merchant eligibility.
|
return array(
|
||||||
$capabilities = array(
|
|
||||||
'apple_pay' => $features['apple_pay']['enabled'] ?? false,
|
'apple_pay' => $features['apple_pay']['enabled'] ?? false,
|
||||||
'google_pay' => $features['google_pay']['enabled'] ?? false,
|
'google_pay' => $features['google_pay']['enabled'] ?? false,
|
||||||
'acdc' => $features['advanced_credit_and_debit_cards']['enabled'] ?? false,
|
'acdc' => $features['advanced_credit_and_debit_cards']['enabled'] ?? false,
|
||||||
|
@ -396,25 +416,68 @@ return array(
|
||||||
'apm' => $features['alternative_payment_methods']['enabled'] ?? false,
|
'apm' => $features['alternative_payment_methods']['enabled'] ?? false,
|
||||||
'paylater' => $features['pay_later_messaging']['enabled'] ?? false,
|
'paylater' => $features['pay_later_messaging']['enabled'] ?? false,
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
|
||||||
$is_pay_later_messaging_enabled_for_any_location = ! array_filter( $pay_later_statuses );
|
'settings.service.todos_eligibilities' => static function ( ContainerInterface $container ) : TodosEligibilityService {
|
||||||
|
$pay_later_service = $container->get( 'settings.service.pay_later_status' );
|
||||||
|
$pay_later_statuses = $pay_later_service['statuses'];
|
||||||
|
$is_pay_later_messaging_enabled_for_any_location = $pay_later_service['is_enabled_for_any_location'];
|
||||||
|
|
||||||
|
$button_locations = $container->get( 'settings.service.button_locations' );
|
||||||
|
$gateways = $container->get( 'settings.service.gateways_status' );
|
||||||
|
$capabilities = $container->get( 'settings.service.merchant_capabilities' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes TodosEligibilityService with eligibility conditions for various PayPal features.
|
||||||
|
* Each parameter determines whether a specific feature should be shown in the Things To Do list.
|
||||||
|
*
|
||||||
|
* Logic relies on three main factors:
|
||||||
|
* 1. $container->get( 'x.eligible' ) - Module based eligibility check, usually whether the WooCommerce store is using a supported country/currency matrix.
|
||||||
|
* 2. $capabilities - Whether the merchant is eligible for specific features on their PayPal account.
|
||||||
|
* 3. $gateways, $pay_later_statuses, $button_locations - Plugin settings (enabled/disabled status).
|
||||||
|
*
|
||||||
|
* @param bool $is_fastlane_eligible - Show if merchant is eligible (ACDC) but hasn't enabled Fastlane gateway.
|
||||||
|
* @param bool $is_card_payment_eligible - Show if merchant is eligible (ACDC) but hasn't enabled card button gateway.
|
||||||
|
* @param bool $is_pay_later_messaging_eligible - Show if Pay Later messaging is enabled for at least one location.
|
||||||
|
* @param bool $is_pay_later_messaging_product_eligible - Show if Pay Later is not enabled anywhere and specifically not on product page.
|
||||||
|
* @param bool $is_pay_later_messaging_cart_eligible - Show if Pay Later is not enabled anywhere and specifically not on cart.
|
||||||
|
* @param bool $is_pay_later_messaging_checkout_eligible - Show if Pay Later is not enabled anywhere and specifically not on checkout.
|
||||||
|
* @param bool $is_subscription_eligible - Show if WooCommerce Subscriptions plugin is active but merchant is not eligible for PayPal Vaulting.
|
||||||
|
* @param bool $is_paypal_buttons_cart_eligible - Show if PayPal buttons are not enabled on cart page.
|
||||||
|
* @param bool $is_paypal_buttons_block_checkout_eligible - Show if PayPal buttons are not enabled on blocks checkout.
|
||||||
|
* @param bool $is_paypal_buttons_product_eligible - Show if PayPal buttons are not enabled on product page.
|
||||||
|
* @param bool $is_apple_pay_domain_eligible - Show if merchant has Apple Pay capability on PayPal account.
|
||||||
|
* @param bool $is_digital_wallet_eligible - Show if merchant is eligible (ACDC) but doesn't have both wallet types on PayPal.
|
||||||
|
* @param bool $is_apple_pay_eligible - Show if merchant is eligible (ACDC) but doesn't have Apple Pay on PayPal.
|
||||||
|
* @param bool $is_google_pay_eligible - Show if merchant is eligible (ACDC) but doesn't have Google Pay on PayPal.
|
||||||
|
* @param bool $is_enable_apple_pay_eligible - Show if merchant has Apple Pay capability but hasn't enabled the gateway.
|
||||||
|
* @param bool $is_enable_google_pay_eligible - Show if merchant has Google Pay capability but hasn't enabled the gateway.
|
||||||
|
*/
|
||||||
return new TodosEligibilityService(
|
return new TodosEligibilityService(
|
||||||
$capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane.
|
$container->get( 'axo.eligible' ) && $capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane.
|
||||||
$capabilities['acdc'] && ! $gateways['card-button'], // Enable Credit and Debit Cards on your checkout.
|
$capabilities['acdc'] && ! $gateways['card-button'], // Enable Credit and Debit Cards on your checkout.
|
||||||
$is_pay_later_messaging_enabled_for_any_location, // Enable Pay Later messaging.
|
$is_pay_later_messaging_enabled_for_any_location, // Enable Pay Later messaging.
|
||||||
! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['product'], // Add Pay Later messaging (Product page).
|
! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['product'], // Add Pay Later messaging (Product page).
|
||||||
! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['cart'], // Add Pay Later messaging (Cart).
|
! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['cart'], // Add Pay Later messaging (Cart).
|
||||||
! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['checkout'], // Add Pay Later messaging (Checkout).
|
! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['checkout'], // Add Pay Later messaging (Checkout).
|
||||||
$container->has( 'save-payment-methods.eligible' ) && ! $container->get( 'save-payment-methods.eligible' ) && $container->has( 'wc-subscriptions.helper' ) && $container->get( 'wc-subscriptions.helper' )
|
$container->has( 'save-payment-methods.eligible' ) &&
|
||||||
->plugin_is_active(), // Configure a PayPal Subscription.
|
! $container->get( 'save-payment-methods.eligible' ) &&
|
||||||
true, // Add PayPal buttons.
|
$container->has( 'wc-subscriptions.helper' ) &&
|
||||||
|
$container->get( 'wc-subscriptions.helper' )->plugin_is_active(), // Configure a PayPal Subscription.
|
||||||
|
! $button_locations['cart_enabled'], // Add PayPal buttons to cart.
|
||||||
|
! $button_locations['block_checkout_enabled'], // Add PayPal buttons to block checkout.
|
||||||
|
! $button_locations['product_enabled'], // Add PayPal buttons to product.
|
||||||
$capabilities['apple_pay'], // Register Domain for Apple Pay.
|
$capabilities['apple_pay'], // Register Domain for Apple Pay.
|
||||||
$capabilities['acdc'] && ! ( $capabilities['apple_pay'] && $capabilities['google_pay'] ), // Add digital wallets to your account.
|
$capabilities['acdc'] && ! ( $capabilities['apple_pay'] && $capabilities['google_pay'] ), // Add digital wallets to your account.
|
||||||
$capabilities['acdc'] && ! $capabilities['apple_pay'], // Add Apple Pay to your account.
|
$container->get( 'applepay.eligible' ) && $capabilities['acdc'] && ! $capabilities['apple_pay'], // Add Apple Pay to your account.
|
||||||
$capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account.
|
$container->get( 'googlepay.eligible' ) && $capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account.
|
||||||
$capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay.
|
$container->get( 'applepay.eligible' ) && $capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay.
|
||||||
$capabilities['google_pay'] && ! $gateways['google_pay'], // Enable Google Pay.
|
$container->get( 'googlepay.eligible' ) && $capabilities['google_pay'] && ! $gateways['google_pay'],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'settings.service.todos_sorting' => static function ( ContainerInterface $container ) : TodosSortingAndFilteringService {
|
||||||
|
return new TodosSortingAndFilteringService(
|
||||||
|
$container->get( 'settings.data.todos' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'settings.rest.features' => static function ( ContainerInterface $container ) : FeaturesRestEndpoint {
|
'settings.rest.features' => static function ( ContainerInterface $container ) : FeaturesRestEndpoint {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* PayPal Commerce Todos Definitions
|
* Todos Definitions
|
||||||
*
|
*
|
||||||
* @package WooCommerce\PayPalCommerce\Settings\Data\Definition
|
* @package WooCommerce\PayPalCommerce\Settings\Data\Definition
|
||||||
*/
|
*/
|
||||||
|
@ -145,10 +145,30 @@ class TodosDefinition {
|
||||||
),
|
),
|
||||||
'priority' => 5,
|
'priority' => 5,
|
||||||
),
|
),
|
||||||
'add_paypal_buttons' => array(
|
'add_paypal_buttons_cart' => array(
|
||||||
'title' => __( 'Add PayPal buttons', 'woocommerce-paypal-payments' ),
|
'title' => __( 'Add PayPal buttons to the Cart page', 'woocommerce-paypal-payments' ),
|
||||||
'description' => __( 'Allow customers to check out quickly and securely from the <x> page. Customers save time and get through checkout in fewer clicks.', 'woocommerce-paypal-payments' ),
|
'description' => __( 'Allow customers to check out quickly and securely from the Cart page. Customers save time and get through checkout in fewer clicks.', 'woocommerce-paypal-payments' ),
|
||||||
'isEligible' => $eligibility_checks['add_paypal_buttons'],
|
'isEligible' => $eligibility_checks['add_paypal_buttons_cart'],
|
||||||
|
'action' => array(
|
||||||
|
'type' => 'tab',
|
||||||
|
'tab' => 'styling',
|
||||||
|
),
|
||||||
|
'priority' => 6,
|
||||||
|
),
|
||||||
|
'add_paypal_buttons_block_checkout' => array(
|
||||||
|
'title' => __( 'Add PayPal buttons to the Express Checkout page', 'woocommerce-paypal-payments' ),
|
||||||
|
'description' => __( 'Allow customers to check out quickly and securely from the Express Checkout page. Customers save time and get through checkout in fewer clicks.', 'woocommerce-paypal-payments' ),
|
||||||
|
'isEligible' => $eligibility_checks['add_paypal_buttons_block_checkout'],
|
||||||
|
'action' => array(
|
||||||
|
'type' => 'tab',
|
||||||
|
'tab' => 'styling',
|
||||||
|
),
|
||||||
|
'priority' => 6,
|
||||||
|
),
|
||||||
|
'add_paypal_buttons_product' => array(
|
||||||
|
'title' => __( 'Add PayPal buttons to the Product page', 'woocommerce-paypal-payments' ),
|
||||||
|
'description' => __( 'Allow customers to check out quickly and securely from the Product page. Customers save time and get through checkout in fewer clicks.', 'woocommerce-paypal-payments' ),
|
||||||
|
'isEligible' => $eligibility_checks['add_paypal_buttons_product'],
|
||||||
'action' => array(
|
'action' => array(
|
||||||
'type' => 'tab',
|
'type' => 'tab',
|
||||||
'tab' => 'styling',
|
'tab' => 'styling',
|
||||||
|
|
|
@ -17,6 +17,7 @@ use WP_REST_Response;
|
||||||
use WP_REST_Request;
|
use WP_REST_Request;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Data\TodosModel;
|
use WooCommerce\PayPalCommerce\Settings\Data\TodosModel;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Data\Definition\TodosDefinition;
|
use WooCommerce\PayPalCommerce\Settings\Data\Definition\TodosDefinition;
|
||||||
|
use WooCommerce\PayPalCommerce\Settings\Service\TodosSortingAndFilteringService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REST controller for the "Things To Do" items in the Overview tab.
|
* REST controller for the "Things To Do" items in the Overview tab.
|
||||||
|
@ -33,17 +34,6 @@ class TodosRestEndpoint extends RestEndpoint {
|
||||||
*/
|
*/
|
||||||
protected $rest_base = 'todos';
|
protected $rest_base = 'todos';
|
||||||
|
|
||||||
/**
|
|
||||||
* Pay Later messaging todo IDs in priority order.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private const PAY_LATER_IDS = array(
|
|
||||||
'add_pay_later_messaging_product_page',
|
|
||||||
'add_pay_later_messaging_cart',
|
|
||||||
'add_pay_later_messaging_checkout',
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The todos model instance.
|
* The todos model instance.
|
||||||
*
|
*
|
||||||
|
@ -65,21 +55,31 @@ class TodosRestEndpoint extends RestEndpoint {
|
||||||
*/
|
*/
|
||||||
protected SettingsRestEndpoint $settings;
|
protected SettingsRestEndpoint $settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The todos sorting service.
|
||||||
|
*
|
||||||
|
* @var TodosSortingAndFilteringService
|
||||||
|
*/
|
||||||
|
protected TodosSortingAndFilteringService $sorting_service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TodosRestEndpoint constructor.
|
* TodosRestEndpoint constructor.
|
||||||
*
|
*
|
||||||
* @param TodosModel $todos The todos model instance.
|
* @param TodosModel $todos The todos model instance.
|
||||||
* @param TodosDefinition $todos_definition The todos definition instance.
|
* @param TodosDefinition $todos_definition The todos definition instance.
|
||||||
* @param SettingsRestEndpoint $settings The settings endpoint instance.
|
* @param SettingsRestEndpoint $settings The settings endpoint instance.
|
||||||
|
* @param TodosSortingAndFilteringService $sorting_service The todos sorting service.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
TodosModel $todos,
|
TodosModel $todos,
|
||||||
TodosDefinition $todos_definition,
|
TodosDefinition $todos_definition,
|
||||||
SettingsRestEndpoint $settings
|
SettingsRestEndpoint $settings,
|
||||||
|
TodosSortingAndFilteringService $sorting_service
|
||||||
) {
|
) {
|
||||||
$this->todos = $todos;
|
$this->todos = $todos;
|
||||||
$this->todos_definition = $todos_definition;
|
$this->todos_definition = $todos_definition;
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
|
$this->sorting_service = $sorting_service;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,8 +157,7 @@ class TodosRestEndpoint extends RestEndpoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sorted_todos = $this->sort_todos_by_priority( $todos );
|
$filtered_todos = $this->sorting_service->apply_all_priority_filters( $todos );
|
||||||
$filtered_todos = $this->filter_pay_later_todos( $sorted_todos );
|
|
||||||
|
|
||||||
return $this->return_success(
|
return $this->return_success(
|
||||||
array(
|
array(
|
||||||
|
@ -245,67 +244,4 @@ class TodosRestEndpoint extends RestEndpoint {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Filters Pay Later messaging todos to show only the highest priority eligible todo.
|
|
||||||
*
|
|
||||||
* @param array $todos The array of todos to filter.
|
|
||||||
* @return array Filtered todos with only one Pay Later messaging todo.
|
|
||||||
*/
|
|
||||||
private function filter_pay_later_todos( array $todos ): array {
|
|
||||||
$pay_later_todos = array_filter(
|
|
||||||
$todos,
|
|
||||||
function( $todo ) {
|
|
||||||
return in_array( $todo['id'], self::PAY_LATER_IDS, true );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$other_todos = array_filter(
|
|
||||||
$todos,
|
|
||||||
function( $todo ) {
|
|
||||||
return ! in_array( $todo['id'], self::PAY_LATER_IDS, true );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Find the highest priority Pay Later todo that's eligible.
|
|
||||||
$priority_pay_later_todo = null;
|
|
||||||
foreach ( self::PAY_LATER_IDS as $pay_later_id ) {
|
|
||||||
$matching_todo = current(
|
|
||||||
array_filter(
|
|
||||||
$pay_later_todos,
|
|
||||||
function( $todo ) use ( $pay_later_id ) {
|
|
||||||
return $todo['id'] === $pay_later_id;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( $matching_todo ) {
|
|
||||||
$priority_pay_later_todo = $matching_todo;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $priority_pay_later_todo
|
|
||||||
? array_merge( $other_todos, array( $priority_pay_later_todo ) )
|
|
||||||
: $other_todos;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sorts todos by their priority value.
|
|
||||||
*
|
|
||||||
* @param array $todos Array of todos to sort.
|
|
||||||
* @return array Sorted array of todos.
|
|
||||||
*/
|
|
||||||
private function sort_todos_by_priority( array $todos ): array {
|
|
||||||
usort(
|
|
||||||
$todos,
|
|
||||||
function( $a, $b ) {
|
|
||||||
$priority_a = $a['priority'] ?? 999;
|
|
||||||
$priority_b = $b['priority'] ?? 999;
|
|
||||||
return $priority_a <=> $priority_b;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $todos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* PayPal Commerce eligibility service for WooCommerce.
|
* Eligibility service for Todos.
|
||||||
*
|
*
|
||||||
* This file contains the TodosEligibilityService class which manages eligibility checks
|
* This file contains the TodosEligibilityService class which manages eligibility checks
|
||||||
* for various PayPal Commerce features including Fastlane, card payments, Pay Later messaging,
|
* for various features including Fastlane, card payments, Pay Later messaging,
|
||||||
* subscriptions, Apple Pay, Google Pay, and other digital wallet features.
|
* subscriptions, Apple Pay, Google Pay, and other digital wallet features.
|
||||||
*
|
*
|
||||||
* @package WooCommerce\PayPalCommerce\Settings\Service
|
* @package WooCommerce\PayPalCommerce\Settings\Service
|
||||||
|
@ -66,6 +66,27 @@ class TodosEligibilityService {
|
||||||
*/
|
*/
|
||||||
private bool $is_subscription_eligible;
|
private bool $is_subscription_eligible;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether PayPal buttons for cart are eligible.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private bool $is_paypal_buttons_cart_eligible;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether PayPal buttons for block checkout are eligible.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private bool $is_paypal_buttons_block_checkout_eligible;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether PayPal buttons for product page are eligible.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private bool $is_paypal_buttons_product_eligible;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether Apple Pay domain registration is eligible.
|
* Whether Apple Pay domain registration is eligible.
|
||||||
*
|
*
|
||||||
|
@ -94,13 +115,6 @@ class TodosEligibilityService {
|
||||||
*/
|
*/
|
||||||
private bool $is_google_pay_eligible;
|
private bool $is_google_pay_eligible;
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether PayPal buttons are eligible.
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private bool $is_paypal_buttons_eligible;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether enabling Apple Pay is eligible.
|
* Whether enabling Apple Pay is eligible.
|
||||||
*
|
*
|
||||||
|
@ -125,7 +139,9 @@ class TodosEligibilityService {
|
||||||
* @param bool $is_pay_later_messaging_cart_eligible Whether Pay Later messaging for cart is eligible.
|
* @param bool $is_pay_later_messaging_cart_eligible Whether Pay Later messaging for cart is eligible.
|
||||||
* @param bool $is_pay_later_messaging_checkout_eligible Whether Pay Later messaging for checkout is eligible.
|
* @param bool $is_pay_later_messaging_checkout_eligible Whether Pay Later messaging for checkout is eligible.
|
||||||
* @param bool $is_subscription_eligible Whether subscriptions are eligible.
|
* @param bool $is_subscription_eligible Whether subscriptions are eligible.
|
||||||
* @param bool $is_paypal_buttons_eligible Whether PayPal buttons are eligible.
|
* @param bool $is_paypal_buttons_cart_eligible Whether PayPal buttons for cart are eligible.
|
||||||
|
* @param bool $is_paypal_buttons_block_checkout_eligible Whether PayPal buttons for block checkout are eligible.
|
||||||
|
* @param bool $is_paypal_buttons_product_eligible Whether PayPal buttons for product page are eligible.
|
||||||
* @param bool $is_apple_pay_domain_eligible Whether Apple Pay domain registration is eligible.
|
* @param bool $is_apple_pay_domain_eligible Whether Apple Pay domain registration is eligible.
|
||||||
* @param bool $is_digital_wallet_eligible Whether digital wallet features are eligible.
|
* @param bool $is_digital_wallet_eligible Whether digital wallet features are eligible.
|
||||||
* @param bool $is_apple_pay_eligible Whether Apple Pay is eligible.
|
* @param bool $is_apple_pay_eligible Whether Apple Pay is eligible.
|
||||||
|
@ -141,7 +157,9 @@ class TodosEligibilityService {
|
||||||
bool $is_pay_later_messaging_cart_eligible,
|
bool $is_pay_later_messaging_cart_eligible,
|
||||||
bool $is_pay_later_messaging_checkout_eligible,
|
bool $is_pay_later_messaging_checkout_eligible,
|
||||||
bool $is_subscription_eligible,
|
bool $is_subscription_eligible,
|
||||||
bool $is_paypal_buttons_eligible,
|
bool $is_paypal_buttons_cart_eligible,
|
||||||
|
bool $is_paypal_buttons_block_checkout_eligible,
|
||||||
|
bool $is_paypal_buttons_product_eligible,
|
||||||
bool $is_apple_pay_domain_eligible,
|
bool $is_apple_pay_domain_eligible,
|
||||||
bool $is_digital_wallet_eligible,
|
bool $is_digital_wallet_eligible,
|
||||||
bool $is_apple_pay_eligible,
|
bool $is_apple_pay_eligible,
|
||||||
|
@ -156,7 +174,9 @@ class TodosEligibilityService {
|
||||||
$this->is_pay_later_messaging_cart_eligible = $is_pay_later_messaging_cart_eligible;
|
$this->is_pay_later_messaging_cart_eligible = $is_pay_later_messaging_cart_eligible;
|
||||||
$this->is_pay_later_messaging_checkout_eligible = $is_pay_later_messaging_checkout_eligible;
|
$this->is_pay_later_messaging_checkout_eligible = $is_pay_later_messaging_checkout_eligible;
|
||||||
$this->is_subscription_eligible = $is_subscription_eligible;
|
$this->is_subscription_eligible = $is_subscription_eligible;
|
||||||
$this->is_paypal_buttons_eligible = $is_paypal_buttons_eligible;
|
$this->is_paypal_buttons_cart_eligible = $is_paypal_buttons_cart_eligible;
|
||||||
|
$this->is_paypal_buttons_block_checkout_eligible = $is_paypal_buttons_block_checkout_eligible;
|
||||||
|
$this->is_paypal_buttons_product_eligible = $is_paypal_buttons_product_eligible;
|
||||||
$this->is_apple_pay_domain_eligible = $is_apple_pay_domain_eligible;
|
$this->is_apple_pay_domain_eligible = $is_apple_pay_domain_eligible;
|
||||||
$this->is_digital_wallet_eligible = $is_digital_wallet_eligible;
|
$this->is_digital_wallet_eligible = $is_digital_wallet_eligible;
|
||||||
$this->is_apple_pay_eligible = $is_apple_pay_eligible;
|
$this->is_apple_pay_eligible = $is_apple_pay_eligible;
|
||||||
|
@ -179,7 +199,9 @@ class TodosEligibilityService {
|
||||||
'add_pay_later_messaging_cart' => fn() => $this->is_pay_later_messaging_cart_eligible,
|
'add_pay_later_messaging_cart' => fn() => $this->is_pay_later_messaging_cart_eligible,
|
||||||
'add_pay_later_messaging_checkout' => fn() => $this->is_pay_later_messaging_checkout_eligible,
|
'add_pay_later_messaging_checkout' => fn() => $this->is_pay_later_messaging_checkout_eligible,
|
||||||
'configure_paypal_subscription' => fn() => $this->is_subscription_eligible,
|
'configure_paypal_subscription' => fn() => $this->is_subscription_eligible,
|
||||||
'add_paypal_buttons' => fn() => $this->is_paypal_buttons_eligible,
|
'add_paypal_buttons_cart' => fn() => $this->is_paypal_buttons_cart_eligible,
|
||||||
|
'add_paypal_buttons_block_checkout' => fn() => $this->is_paypal_buttons_block_checkout_eligible,
|
||||||
|
'add_paypal_buttons_product' => fn() => $this->is_paypal_buttons_product_eligible,
|
||||||
'register_domain_apple_pay' => fn() => $this->is_apple_pay_domain_eligible,
|
'register_domain_apple_pay' => fn() => $this->is_apple_pay_domain_eligible,
|
||||||
'add_digital_wallets' => fn() => $this->is_digital_wallet_eligible,
|
'add_digital_wallets' => fn() => $this->is_digital_wallet_eligible,
|
||||||
'add_apple_pay' => fn() => $this->is_apple_pay_eligible,
|
'add_apple_pay' => fn() => $this->is_apple_pay_eligible,
|
||||||
|
|
|
@ -0,0 +1,182 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Service for sorting and filtering todo items.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\Settings\Service
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\Settings\Service;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\Settings\Data\TodosModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service class that provides todo sorting and filtering functionality.
|
||||||
|
*/
|
||||||
|
class TodosSortingAndFilteringService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pay Later messaging todo IDs in priority order.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private const PAY_LATER_IDS = array(
|
||||||
|
'add_pay_later_messaging_product_page',
|
||||||
|
'add_pay_later_messaging_cart',
|
||||||
|
'add_pay_later_messaging_checkout',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Button placement todo IDs in priority order.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private const BUTTON_PLACEMENT_IDS = array(
|
||||||
|
'add_paypal_buttons_cart',
|
||||||
|
'add_paypal_buttons_block_checkout',
|
||||||
|
'add_paypal_buttons_product',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The TodosModel instance.
|
||||||
|
*
|
||||||
|
* @var TodosModel
|
||||||
|
*/
|
||||||
|
private TodosModel $todos_model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param TodosModel $todos_model The TodosModel instance.
|
||||||
|
*/
|
||||||
|
public function __construct( TodosModel $todos_model ) {
|
||||||
|
$this->todos_model = $todos_model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Pay Later messaging todo IDs in priority order.
|
||||||
|
*
|
||||||
|
* @return array Pay Later messaging todo IDs.
|
||||||
|
*/
|
||||||
|
public function get_pay_later_ids(): array {
|
||||||
|
return self::PAY_LATER_IDS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Button Placement todo IDs in priority order.
|
||||||
|
*
|
||||||
|
* @return array Button Placement todo IDs.
|
||||||
|
*/
|
||||||
|
public function get_button_placement_ids(): array {
|
||||||
|
return self::BUTTON_PLACEMENT_IDS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts todos by their priority value.
|
||||||
|
*
|
||||||
|
* @param array $todos Array of todos to sort.
|
||||||
|
* @return array Sorted array of todos.
|
||||||
|
*/
|
||||||
|
public function sort_todos_by_priority( array $todos ): array {
|
||||||
|
usort(
|
||||||
|
$todos,
|
||||||
|
function( $a, $b ) {
|
||||||
|
$priority_a = $a['priority'] ?? 999;
|
||||||
|
$priority_b = $b['priority'] ?? 999;
|
||||||
|
return $priority_a <=> $priority_b;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $todos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters a group of todos to show only the highest priority one.
|
||||||
|
* Takes into account dismissed todos.
|
||||||
|
*
|
||||||
|
* @param array $todos The array of todos to filter.
|
||||||
|
* @param array $group_ids Array of todo IDs in priority order.
|
||||||
|
* @return array Filtered todos with only one todo from the specified group.
|
||||||
|
*/
|
||||||
|
public function filter_highest_priority_todo( array $todos, array $group_ids ): array {
|
||||||
|
$dismissed_todos = $this->todos_model->get_dismissed_todos();
|
||||||
|
|
||||||
|
$group_todos = array_filter(
|
||||||
|
$todos,
|
||||||
|
function( $todo ) use ( $group_ids ) {
|
||||||
|
return in_array( $todo['id'], $group_ids, true );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$other_todos = array_filter(
|
||||||
|
$todos,
|
||||||
|
function( $todo ) use ( $group_ids ) {
|
||||||
|
return ! in_array( $todo['id'], $group_ids, true );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Find the highest priority todo from the group that's eligible AND not dismissed.
|
||||||
|
$priority_todo = null;
|
||||||
|
foreach ( $group_ids as $todo_id ) {
|
||||||
|
// Skip if this todo ID is dismissed.
|
||||||
|
if ( in_array( $todo_id, $dismissed_todos, true ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$matching_todo = current(
|
||||||
|
array_filter(
|
||||||
|
$group_todos,
|
||||||
|
function( $todo ) use ( $todo_id ) {
|
||||||
|
return $todo['id'] === $todo_id;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( $matching_todo ) {
|
||||||
|
$priority_todo = $matching_todo;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $priority_todo
|
||||||
|
? array_merge( $other_todos, array( $priority_todo ) )
|
||||||
|
: $other_todos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter pay later todos to show only the highest priority eligible one.
|
||||||
|
*
|
||||||
|
* @param array $todos The array of todos to filter.
|
||||||
|
* @return array Filtered todos.
|
||||||
|
*/
|
||||||
|
public function filter_pay_later_todos( array $todos ): array {
|
||||||
|
return $this->filter_highest_priority_todo( $todos, self::PAY_LATER_IDS );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter button placement todos to show only the highest priority eligible one.
|
||||||
|
*
|
||||||
|
* @param array $todos The array of todos to filter.
|
||||||
|
* @return array Filtered todos.
|
||||||
|
*/
|
||||||
|
public function filter_button_placement_todos( array $todos ): array {
|
||||||
|
return $this->filter_highest_priority_todo( $todos, self::BUTTON_PLACEMENT_IDS );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply all priority filters to the todos list.
|
||||||
|
*
|
||||||
|
* This method applies sorting and all priority filtering in the correct order.
|
||||||
|
*
|
||||||
|
* @param array $todos The original todos array.
|
||||||
|
* @return array Fully filtered and sorted todos.
|
||||||
|
*/
|
||||||
|
public function apply_all_priority_filters( array $todos ): array {
|
||||||
|
$sorted_todos = $this->sort_todos_by_priority( $todos );
|
||||||
|
$filtered_todos = $this->filter_pay_later_todos( $sorted_todos );
|
||||||
|
$filtered_todos = $this->filter_button_placement_todos( $filtered_todos );
|
||||||
|
|
||||||
|
return $filtered_todos;
|
||||||
|
}
|
||||||
|
}
|
|
@ -341,18 +341,18 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
||||||
unset( $payment_methods['venmo'] );
|
unset( $payment_methods['venmo'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unset if not eligible for Google Pay.
|
// Unset if country/currency is not supported or merchant not eligible for Google Pay.
|
||||||
if ( ! $googlepay_product_status->is_active() ) {
|
if ( ! $container->get( 'googlepay.eligible' ) || ! $googlepay_product_status->is_active() ) {
|
||||||
unset( $payment_methods['ppcp-googlepay'] );
|
unset( $payment_methods['ppcp-googlepay'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unset if not eligible for Apple Pay.
|
// Unset if country/currency is not supported or merchant not eligible for Apple Pay.
|
||||||
if ( ! $applepay_product_status->is_active() ) {
|
if ( ! $container->get( 'applepay.eligible' ) || ! $applepay_product_status->is_active() ) {
|
||||||
unset( $payment_methods['ppcp-applepay'] );
|
unset( $payment_methods['ppcp-applepay'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unset Fastlane if store location is not United States or merchant is not eligible for ACDC.
|
// Unset Fastlane if country/currency is not supported or merchant is not eligible for BCDC.
|
||||||
if ( $container->get( 'api.shop.country' ) !== 'US' || ! $dcc_product_status->is_active() ) {
|
if ( ! $container->get( 'axo.eligible' ) || ! $dcc_product_status->is_active() ) {
|
||||||
unset( $payment_methods['ppcp-axo-gateway'] );
|
unset( $payment_methods['ppcp-axo-gateway'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue