Things To Do: Wire the Pay Later Messaging todo items

This commit is contained in:
Daniel Dudzic 2025-02-11 14:47:15 +01:00
parent 6488b636b6
commit d2685d8787
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
5 changed files with 182 additions and 71 deletions

View file

@ -49,10 +49,10 @@ const TodoSettingsBlock = ( {
await selectTab( tabId, todo.action.section );
} else if ( todo.action.type === 'external' ) {
window.open( todo.action.url, '_blank' );
// If it has completeOnClick flag, trigger the action
if ( todo.action.completeOnClick === true ) {
await completeOnClick( todo.id );
}
}
if ( todo.action.completeOnClick === true ) {
await completeOnClick( todo.id );
}
if ( todo.action.modal ) {

View file

@ -279,6 +279,18 @@ return 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_settings = $pay_later_endpoint->get_details()->get_data();
$pay_later_statuses = array(
'cart' => $pay_later_settings['data']['cart']['status'] === 'enabled',
'checkout' => $pay_later_settings['data']['checkout']['status'] === 'enabled',
'product' => $pay_later_settings['data']['product']['status'] === 'enabled',
'shop' => $pay_later_settings['data']['shop']['status'] === 'enabled',
'home' => $pay_later_settings['data']['home']['status'] === 'enabled',
'custom_placement' => ! empty( $pay_later_settings['data']['custom_placement'] ) &&
$pay_later_settings['data']['custom_placement'][0]['status'] === 'enabled',
);
// Settings status.
$gateways = array(
'apple_pay' => $settings['data']['ppcp-applepay']['enabled'] ?? false,
@ -297,20 +309,24 @@ return array(
'paylater' => $features['pay_later_messaging']['enabled'] ?? false,
);
$is_pay_later_messaging_enabled_for_any_location = ! array_filter( $pay_later_statuses );
return new TodosEligibilityService(
$capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane.
$capabilities['acdc'] && ! $gateways['card-button'], // Enable Credit and Debit Cards on your checkout.
true, // Enable Pay Later messaging.
true, // Add Pay Later messaging.
true, // Configure a PayPal Subscription.
true, // Add PayPal buttons.
true, // Register Domain for Apple Pay.
$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['cart'], // Add Pay Later messaging (Cart).
! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['checkout'], // Add Pay Later messaging (Checkout).
true, // Configure a PayPal Subscription.
true, // Add PayPal buttons.
true, // Register Domain for Apple Pay.
$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.
$capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account.
true, // Configure a PayPal Subscription.
$capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay.
$capabilities['google_pay'] && ! $gateways['google_pay'] // Enable Google Pay.
$capabilities['acdc'] && ! $capabilities['apple_pay'], // Add Apple Pay to your account.
$capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account.
true, // Configure a PayPal Subscription.
$capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay.
$capabilities['google_pay'] && ! $gateways['google_pay'], // Enable Google Pay.
);
},
);

View file

@ -57,7 +57,7 @@ class TodosDefinition {
$eligibility_checks = $this->eligibilities->get_eligibility_checks();
return array(
'enable_fastlane' => array(
'enable_fastlane' => array(
'title' => __( 'Enable Fastlane', 'woocommerce-paypal-payments' ),
'description' => __( 'Accelerate your guest checkout with Fastlane by PayPal', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['enable_fastlane'],
@ -68,7 +68,7 @@ class TodosDefinition {
'highlight' => 'ppcp-axo-gateway',
),
),
'enable_credit_debit_cards' => array(
'enable_credit_debit_cards' => array(
'title' => __( 'Enable Credit and Debit Cards on your checkout', 'woocommerce-paypal-payments' ),
'description' => __( 'Credit and Debit Cards is now available for Blocks checkout pages', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['enable_credit_debit_cards'],
@ -79,27 +79,43 @@ class TodosDefinition {
'highlight' => 'ppcp-card-button-gateway',
),
),
'enable_pay_later_messaging' => array(
'enable_pay_later_messaging' => array(
'title' => __( 'Enable Pay Later messaging', 'woocommerce-paypal-payments' ),
'description' => __( 'Show Pay Later messaging to boost conversion rate and increase cart size.', 'woocommerce-paypal-payments' ),
'description' => __( 'Show Pay Later messaging to boost conversion rate and increase cart size', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['enable_pay_later_messaging'],
'action' => array(
'type' => 'tab',
'tab' => 'overview',
'section' => 'pay_later_messaging',
'type' => 'tab',
'tab' => 'pay_later_messaging',
),
),
'add_pay_later_messaging' => array(
'title' => __( 'Add Pay Later messaging', 'woocommerce-paypal-payments' ),
'description' => __( 'Present Pay Later messaging on your <x> page to boost conversion rate and increase cart size.', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['add_pay_later_messaging'],
'add_pay_later_messaging_product_page' => array(
'title' => __( 'Add Pay Later messaging to the Product page', 'woocommerce-paypal-payments' ),
'description' => __( 'Present Pay Later messaging on your Product page to boost conversion rate and increase cart size', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['add_pay_later_messaging_product_page'],
'action' => array(
'type' => 'tab',
'tab' => 'overview',
'section' => 'pay_later_messaging',
'type' => 'tab',
'tab' => 'pay_later_messaging',
),
),
'configure_paypal_subscription' => array(
'add_pay_later_messaging_cart' => array(
'title' => __( 'Add Pay Later messaging to the Cart page', 'woocommerce-paypal-payments' ),
'description' => __( 'Present Pay Later messaging on your Cart page to boost conversion rate and increase cart size', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['add_pay_later_messaging_cart'],
'action' => array(
'type' => 'tab',
'tab' => 'pay_later_messaging',
),
),
'add_pay_later_messaging_checkout' => array(
'title' => __( 'Add Pay Later messaging to the Checkout page', 'woocommerce-paypal-payments' ),
'description' => __( 'Present Pay Later messaging on your Checkout page to boost conversion rate and increase cart size', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['add_pay_later_messaging_checkout'],
'action' => array(
'type' => 'tab',
'tab' => 'pay_later_messaging',
),
),
'configure_paypal_subscription' => array(
'title' => __( 'Configure a PayPal Subscription', 'woocommerce-paypal-payments' ),
'description' => __( 'Connect a subscriptions-type product from WooCommerce with PayPal', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['configure_paypal_subscription'],
@ -108,7 +124,7 @@ class TodosDefinition {
'url' => admin_url( 'edit.php?post_type=product&product_type=subscription' ),
),
),
'add_paypal_buttons' => array(
'add_paypal_buttons' => array(
'title' => __( 'Add PayPal buttons', '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' ),
'isEligible' => $eligibility_checks['add_paypal_buttons'],
@ -117,7 +133,7 @@ class TodosDefinition {
'tab' => 'styling',
),
),
'register_domain_apple_pay' => array(
'register_domain_apple_pay' => array(
'title' => __( 'Register Domain for Apple Pay', 'woocommerce-paypal-payments' ),
'description' => __( 'To enable Apple Pay, you must register your domain with PayPal', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['register_domain_apple_pay'],
@ -129,7 +145,7 @@ class TodosDefinition {
'completeOnClick' => true,
),
),
'add_digital_wallets' => array(
'add_digital_wallets' => array(
'title' => __( 'Add digital wallets to your account', 'woocommerce-paypal-payments' ),
'description' => __( 'Add the ability to accept Apple Pay & Google Pay to your PayPal account', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['add_digital_wallets'],
@ -138,7 +154,7 @@ class TodosDefinition {
'url' => 'https://www.paypal.com/businessmanage/account/settings',
),
),
'add_apple_pay' => array(
'add_apple_pay' => array(
'title' => __( 'Add Apple Pay to your account', 'woocommerce-paypal-payments' ),
'description' => __( 'Add the ability to accept Apple Pay to your PayPal account', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['add_apple_pay'],
@ -147,7 +163,7 @@ class TodosDefinition {
'url' => 'https://www.paypal.com/businessmanage/account/settings',
),
),
'add_google_pay' => array(
'add_google_pay' => array(
'title' => __( 'Add Google Pay to your account', 'woocommerce-paypal-payments' ),
'description' => __( 'Add the ability to accept Google Pay to your PayPal account', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['add_google_pay'],
@ -156,7 +172,7 @@ class TodosDefinition {
'url' => 'https://www.paypal.com/businessmanage/account/settings',
),
),
'enable_apple_pay' => array(
'enable_apple_pay' => array(
'title' => __( 'Enable Apple Pay', 'woocommerce-paypal-payments' ),
'description' => __( 'Allow your buyers to check out via Apple Pay', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['enable_apple_pay'],
@ -167,7 +183,7 @@ class TodosDefinition {
'highlight' => 'ppcp-applepay',
),
),
'enable_google_pay' => array(
'enable_google_pay' => array(
'title' => __( 'Enable Google Pay', 'woocommerce-paypal-payments' ),
'description' => __( 'Allow your buyers to check out via Google Pay', 'woocommerce-paypal-payments' ),
'isEligible' => $eligibility_checks['enable_google_pay'],

View file

@ -33,6 +33,17 @@ class TodosRestEndpoint extends RestEndpoint {
*/
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.
*
@ -146,9 +157,11 @@ class TodosRestEndpoint extends RestEndpoint {
}
}
$filtered_todos = $this->filter_pay_later_todos( $todos );
return $this->return_success(
array(
'todos' => $todos,
'todos' => $filtered_todos,
'dismissedTodos' => $dismissed_ids,
'completedOnClickTodos' => $completed_onclick_ids,
)
@ -231,4 +244,48 @@ 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;
}
}

View file

@ -38,6 +38,27 @@ class TodosEligibilityService {
*/
private bool $is_pay_later_messaging_eligible;
/**
* Whether Pay Later messaging for product page is eligible.
*
* @var bool
*/
private bool $is_pay_later_messaging_product_eligible;
/**
* Whether Pay Later messaging for cart is eligible.
*
* @var bool
*/
private bool $is_pay_later_messaging_cart_eligible;
/**
* Whether Pay Later messaging for checkout is eligible.
*
* @var bool
*/
private bool $is_pay_later_messaging_checkout_eligible;
/**
* Whether subscriptions are eligible.
*
@ -73,13 +94,6 @@ class TodosEligibilityService {
*/
private bool $is_google_pay_eligible;
/**
* Whether Pay Later messaging for UI elements is eligible.
*
* @var bool
*/
private bool $is_pay_later_messaging_ui_eligible;
/**
* Whether PayPal buttons are eligible.
*
@ -114,7 +128,9 @@ class TodosEligibilityService {
* @param bool $is_fastlane_eligible Whether Fastlane is eligible.
* @param bool $is_card_payment_eligible Whether card payments are eligible.
* @param bool $is_pay_later_messaging_eligible Whether Pay Later messaging is eligible.
* @param bool $is_pay_later_messaging_ui_eligible Whether Pay Later messaging for UI is eligible.
* @param bool $is_pay_later_messaging_product_eligible Whether Pay Later messaging for product page 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_subscription_eligible Whether subscriptions are eligible.
* @param bool $is_paypal_buttons_eligible Whether PayPal buttons are eligible.
* @param bool $is_apple_pay_domain_eligible Whether Apple Pay domain registration is eligible.
@ -129,7 +145,9 @@ class TodosEligibilityService {
bool $is_fastlane_eligible,
bool $is_card_payment_eligible,
bool $is_pay_later_messaging_eligible,
bool $is_pay_later_messaging_ui_eligible,
bool $is_pay_later_messaging_product_eligible,
bool $is_pay_later_messaging_cart_eligible,
bool $is_pay_later_messaging_checkout_eligible,
bool $is_subscription_eligible,
bool $is_paypal_buttons_eligible,
bool $is_apple_pay_domain_eligible,
@ -140,19 +158,21 @@ class TodosEligibilityService {
bool $is_enable_apple_pay_eligible,
bool $is_enable_google_pay_eligible
) {
$this->is_fastlane_eligible = $is_fastlane_eligible;
$this->is_card_payment_eligible = $is_card_payment_eligible;
$this->is_pay_later_messaging_eligible = $is_pay_later_messaging_eligible;
$this->is_pay_later_messaging_ui_eligible = $is_pay_later_messaging_ui_eligible;
$this->is_subscription_eligible = $is_subscription_eligible;
$this->is_paypal_buttons_eligible = $is_paypal_buttons_eligible;
$this->is_apple_pay_domain_eligible = $is_apple_pay_domain_eligible;
$this->is_digital_wallet_eligible = $is_digital_wallet_eligible;
$this->is_apple_pay_eligible = $is_apple_pay_eligible;
$this->is_google_pay_eligible = $is_google_pay_eligible;
$this->is_add_subscription_eligible = $is_add_subscription_eligible;
$this->is_enable_apple_pay_eligible = $is_enable_apple_pay_eligible;
$this->is_enable_google_pay_eligible = $is_enable_google_pay_eligible;
$this->is_fastlane_eligible = $is_fastlane_eligible;
$this->is_card_payment_eligible = $is_card_payment_eligible;
$this->is_pay_later_messaging_eligible = $is_pay_later_messaging_eligible;
$this->is_pay_later_messaging_product_eligible = $is_pay_later_messaging_product_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_subscription_eligible = $is_subscription_eligible;
$this->is_paypal_buttons_eligible = $is_paypal_buttons_eligible;
$this->is_apple_pay_domain_eligible = $is_apple_pay_domain_eligible;
$this->is_digital_wallet_eligible = $is_digital_wallet_eligible;
$this->is_apple_pay_eligible = $is_apple_pay_eligible;
$this->is_google_pay_eligible = $is_google_pay_eligible;
$this->is_add_subscription_eligible = $is_add_subscription_eligible;
$this->is_enable_apple_pay_eligible = $is_enable_apple_pay_eligible;
$this->is_enable_google_pay_eligible = $is_enable_google_pay_eligible;
}
/**
@ -162,18 +182,20 @@ class TodosEligibilityService {
*/
public function get_eligibility_checks(): array {
return array(
'enable_fastlane' => fn() => $this->is_fastlane_eligible,
'enable_credit_debit_cards' => fn() => $this->is_card_payment_eligible,
'enable_pay_later_messaging' => fn() => $this->is_pay_later_messaging_eligible,
'add_pay_later_messaging' => fn() => $this->is_pay_later_messaging_eligible,
'configure_paypal_subscription' => fn() => $this->is_subscription_eligible,
'add_paypal_buttons' => fn() => $this->is_paypal_buttons_eligible,
'register_domain_apple_pay' => fn() => $this->is_apple_pay_domain_eligible,
'add_digital_wallets' => fn() => $this->is_digital_wallet_eligible,
'add_apple_pay' => fn() => $this->is_apple_pay_eligible,
'add_google_pay' => fn() => $this->is_google_pay_eligible,
'enable_apple_pay' => fn() => $this->is_enable_apple_pay_eligible,
'enable_google_pay' => fn() => $this->is_enable_google_pay_eligible,
'enable_fastlane' => fn() => $this->is_fastlane_eligible,
'enable_credit_debit_cards' => fn() => $this->is_card_payment_eligible,
'enable_pay_later_messaging' => fn() => $this->is_pay_later_messaging_eligible,
'add_pay_later_messaging_product_page' => fn() => $this->is_pay_later_messaging_product_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,
'configure_paypal_subscription' => fn() => $this->is_subscription_eligible,
'add_paypal_buttons' => fn() => $this->is_paypal_buttons_eligible,
'register_domain_apple_pay' => fn() => $this->is_apple_pay_domain_eligible,
'add_digital_wallets' => fn() => $this->is_digital_wallet_eligible,
'add_apple_pay' => fn() => $this->is_apple_pay_eligible,
'add_google_pay' => fn() => $this->is_google_pay_eligible,
'enable_apple_pay' => fn() => $this->is_enable_apple_pay_eligible,
'enable_google_pay' => fn() => $this->is_enable_google_pay_eligible,
);
}
}