New Settings UI: Conditionally show subscriptions product option

This commit is contained in:
Himad M 2024-12-05 10:33:34 -04:00
parent ebc53b7bfa
commit 137d40489c
No known key found for this signature in database
GPG key ID: 5FC769E9888A7B98
6 changed files with 41 additions and 25 deletions

View file

@ -9,6 +9,7 @@ const PRODUCTS_CHECKBOX_GROUP_NAME = 'products';
const StepProducts = () => {
const { products, setProducts } = OnboardingHooks.useProducts();
const { canUseSubscriptions } = OnboardingHooks.useFlags();
return (
<div className="ppcp-r-page-products">
@ -86,31 +87,33 @@ const StepProducts = () => {
</li>
</ul>
</SelectBox>
<SelectBox
title={ __(
'Subscriptions',
'woocommerce-paypal-payments'
) }
description={ __(
'Recurring payments for either physical goods or services.',
'woocommerce-paypal-payments'
) }
name={ PRODUCTS_CHECKBOX_GROUP_NAME }
value={ PRODUCT_TYPES.SUBSCRIPTIONS }
changeCallback={ setProducts }
currentValue={ products }
type="checkbox"
>
<a
target="__blank"
href="https://woocommerce.com/document/woocommerce-paypal-payments/#subscriptions-faq"
>
{ __(
'WooCommerce Subscriptions',
{ canUseSubscriptions && (
<SelectBox
title={ __(
'Subscriptions',
'woocommerce-paypal-payments'
) }
</a>
</SelectBox>
description={ __(
'Recurring payments for either physical goods or services.',
'woocommerce-paypal-payments'
) }
name={ PRODUCTS_CHECKBOX_GROUP_NAME }
value={ PRODUCT_TYPES.SUBSCRIPTIONS }
changeCallback={ setProducts }
currentValue={ products }
type="checkbox"
>
<a
target="__blank"
href="https://woocommerce.com/document/woocommerce-paypal-payments/#subscriptions-faq"
>
{ __(
'WooCommerce Subscriptions',
'woocommerce-paypal-payments'
) }
</a>
</SelectBox>
) }
</SelectBoxWrapper>
</div>
</div>

View file

@ -123,3 +123,8 @@ export const useNavigationState = () => {
business,
};
};
export const useFlags = () => {
const { flags } = useHooks();
return flags;
};

View file

@ -20,6 +20,7 @@ const defaultTransient = {
canUseCasualSelling: false,
canUseVaulting: false,
canUseCardPayments: false,
canUseSubscriptions: false,
},
};

View file

@ -37,6 +37,7 @@ return array(
$can_use_casual_selling = $container->get( 'settings.casual-selling.eligible' );
$can_use_vaulting = $container->has( 'save-payment-methods.eligible' ) && $container->get( 'save-payment-methods.eligible' );
$can_use_card_payments = $container->has( 'card-fields.eligible' ) && $container->get( 'card-fields.eligible' );
$can_use_subscriptions = $container->has( 'wc-subscriptions.helper' ) && $container->get( 'wc-subscriptions.helper' )->plugin_is_active();
// Card payments are disabled for this plugin when WooPayments is active.
// TODO: Move this condition to the card-fields.eligible service?
@ -47,7 +48,8 @@ return array(
return new OnboardingProfile(
$can_use_casual_selling,
$can_use_vaulting,
$can_use_card_payments
$can_use_card_payments,
$can_use_subscriptions
);
},
'settings.data.general' => static function ( ContainerInterface $container ) : GeneralSettings {

View file

@ -48,13 +48,15 @@ class OnboardingProfile extends AbstractDataModel {
public function __construct(
bool $can_use_casual_selling = false,
bool $can_use_vaulting = false,
bool $can_use_card_payments = false
bool $can_use_card_payments = false,
bool $can_use_subscriptions = false
) {
parent::__construct();
$this->flags['can_use_casual_selling'] = $can_use_casual_selling;
$this->flags['can_use_vaulting'] = $can_use_vaulting;
$this->flags['can_use_card_payments'] = $can_use_card_payments;
$this->flags['can_use_subscriptions'] = $can_use_subscriptions;
}
/**

View file

@ -77,6 +77,9 @@ class OnboardingRestEndpoint extends RestEndpoint {
'can_use_card_payments' => array(
'js_name' => 'canUseCardPayments',
),
'can_use_subscriptions' => array(
'js_name' => 'canUseSubscriptions',
),
);
/**