mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
🔀 Merge branch 'trunk'
# Conflicts: # modules/ppcp-settings/services.php
This commit is contained in:
commit
90f70537ba
17 changed files with 487 additions and 176 deletions
|
@ -160,7 +160,7 @@ class PartnersEndpoint {
|
|||
|
||||
$this->failure_registry->clear_failures( FailureRegistry::SELLER_STATUS_KEY );
|
||||
|
||||
$status = $this->seller_status_factory->from_paypal_reponse( $json );
|
||||
$status = $this->seller_status_factory->from_paypal_response( $json );
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,15 +28,23 @@ class SellerStatus {
|
|||
*/
|
||||
private $capabilities;
|
||||
|
||||
/**
|
||||
* Merchant country on PayPal.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $country;
|
||||
|
||||
/**
|
||||
* SellerStatus constructor.
|
||||
*
|
||||
* @param SellerStatusProduct[] $products The products.
|
||||
* @param SellerStatusCapability[] $capabilities The capabilities.
|
||||
* @param string $country Merchant country on PayPal.
|
||||
*
|
||||
* @psalm-suppress RedundantConditionGivenDocblockType
|
||||
*/
|
||||
public function __construct( array $products, array $capabilities ) {
|
||||
public function __construct( array $products, array $capabilities, string $country = '' ) {
|
||||
foreach ( $products as $key => $product ) {
|
||||
if ( is_a( $product, SellerStatusProduct::class ) ) {
|
||||
continue;
|
||||
|
@ -52,6 +60,7 @@ class SellerStatus {
|
|||
|
||||
$this->products = $products;
|
||||
$this->capabilities = $capabilities;
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +82,16 @@ class SellerStatus {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the enitity as array.
|
||||
* Returns merchant's country on PayPal.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function country() : string {
|
||||
return $this->country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity as array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@ -95,6 +113,7 @@ class SellerStatus {
|
|||
return array(
|
||||
'products' => $products,
|
||||
'capabilities' => $capabilities,
|
||||
'country' => $this->country,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class SellerStatusFactory {
|
|||
*
|
||||
* @return SellerStatus
|
||||
*/
|
||||
public function from_paypal_reponse( \stdClass $json ) : SellerStatus {
|
||||
public function from_paypal_response( \stdClass $json ) : SellerStatus {
|
||||
$products = array_map(
|
||||
function( $json ) : SellerStatusProduct {
|
||||
$product = new SellerStatusProduct(
|
||||
|
@ -49,6 +49,6 @@ class SellerStatusFactory {
|
|||
isset( $json->capabilities ) ? (array) $json->capabilities : array()
|
||||
);
|
||||
|
||||
return new SellerStatus( $products, $capabilities );
|
||||
return new SellerStatus( $products, $capabilities, $json->country ?? '' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,10 @@
|
|||
width: 3rem;
|
||||
}
|
||||
}
|
||||
|
||||
.css-1s8clkf.etu8a6w2 {
|
||||
width: 374px;
|
||||
}
|
||||
}
|
||||
|
||||
&__subheader, #configurator-controlPanelSubHeader {
|
||||
|
|
|
@ -22,8 +22,13 @@ const StepBusiness = ( {} ) => {
|
|||
);
|
||||
|
||||
useEffect( () => {
|
||||
if ( ! businessChoice ) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsCasualSeller( BUSINESS_TYPES.CASUAL_SELLER === businessChoice );
|
||||
}, [ businessChoice, setIsCasualSeller ] );
|
||||
|
||||
const { canUseSubscriptions } = OnboardingHooks.useFlags();
|
||||
const businessChoices = [
|
||||
{
|
||||
|
|
|
@ -36,8 +36,7 @@ const ALL_STEPS = [
|
|||
id: 'methods',
|
||||
title: __( 'Choose checkout options', 'woocommerce-paypal-payments' ),
|
||||
StepComponent: StepPaymentMethods,
|
||||
canProceed: ( { methods } ) =>
|
||||
methods.areOptionalPaymentMethodsEnabled !== null,
|
||||
canProceed: ( { methods } ) => methods.optionalMethods !== null,
|
||||
},
|
||||
{
|
||||
id: 'complete',
|
||||
|
|
|
@ -24,7 +24,7 @@ export const learnMoreLinks = {
|
|||
'https://www.paypal.com/uk/business/paypal-business-fees',
|
||||
PayPalCheckout:
|
||||
'https://www.paypal.com/uk/business/accept-payments/checkout',
|
||||
PayLater:
|
||||
PayInThree:
|
||||
'https://www.paypal.com/uk/business/accept-payments/checkout/installments',
|
||||
},
|
||||
FR: {
|
||||
|
|
|
@ -34,6 +34,7 @@ use WooCommerce\PayPalCommerce\Settings\Service\AuthenticationManager;
|
|||
use WooCommerce\PayPalCommerce\Settings\Service\ConnectionUrlGenerator;
|
||||
use WooCommerce\PayPalCommerce\Settings\Service\OnboardingUrlManager;
|
||||
use WooCommerce\PayPalCommerce\Settings\Service\TodosEligibilityService;
|
||||
use WooCommerce\PayPalCommerce\Settings\Service\TodosSortingAndFilteringService;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Settings\Service\DataSanitizer;
|
||||
use WooCommerce\PayPalCommerce\Settings\Service\SettingsDataManager;
|
||||
|
@ -43,10 +44,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
|||
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\ConnectionState;
|
||||
use WooCommerce\PayPalCommerce\Applepay\ApplePayGateway;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\GooglePayGateway;
|
||||
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
|
||||
|
||||
return array(
|
||||
'settings.url' => static function ( ContainerInterface $container ) : string {
|
||||
|
@ -311,7 +308,8 @@ return array(
|
|||
$container->get( 'api.env.endpoint.login-seller' ),
|
||||
$container->get( 'api.repository.partner-referrals-data' ),
|
||||
$container->get( 'settings.connection-state' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'api.endpoint.partners' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
'settings.service.sanitizer' => static function ( ContainerInterface $container ) : DataSanitizer {
|
||||
|
@ -341,7 +339,8 @@ return array(
|
|||
return new TodosRestEndpoint(
|
||||
$container->get( 'settings.data.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 {
|
||||
|
@ -359,14 +358,10 @@ return array(
|
|||
$container->get( 'settings.data.payment' ),
|
||||
);
|
||||
},
|
||||
'settings.service.todos_eligibilities' => static function ( ContainerInterface $container ) : TodosEligibilityService {
|
||||
$features = apply_filters(
|
||||
'woocommerce_paypal_payments_rest_common_merchant_features',
|
||||
array()
|
||||
);
|
||||
|
||||
'settings.service.pay_later_status' => static function ( ContainerInterface $container ) : array {
|
||||
$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',
|
||||
|
@ -377,19 +372,41 @@ return array(
|
|||
$pay_later_settings['data']['custom_placement'][0]['status'] === 'enabled',
|
||||
);
|
||||
|
||||
$payment_settings = $container->get( 'settings.data.payment' );
|
||||
assert( $payment_settings instanceof PaymentSettings );
|
||||
$is_pay_later_messaging_enabled_for_any_location = ! array_filter( $pay_later_statuses );
|
||||
|
||||
// Settings status.
|
||||
$gateways = array(
|
||||
'apple_pay' => $payment_settings->is_method_enabled( ApplePayGateway::ID ),
|
||||
'google_pay' => $payment_settings->is_method_enabled( GooglePayGateway::ID ),
|
||||
'axo' => $payment_settings->is_method_enabled( AxoGateway::ID ),
|
||||
'card-button' => $payment_settings->is_method_enabled( CardButtonGateway::ID ),
|
||||
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,
|
||||
'google_pay' => $settings['data']['ppcp-googlepay']['enabled'] ?? false,
|
||||
'axo' => $settings['data']['ppcp-axo-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.
|
||||
$capabilities = array(
|
||||
return array(
|
||||
'apple_pay' => $features['apple_pay']['enabled'] ?? false,
|
||||
'google_pay' => $features['google_pay']['enabled'] ?? false,
|
||||
'acdc' => $features['advanced_credit_and_debit_cards']['enabled'] ?? false,
|
||||
|
@ -397,25 +414,68 @@ return array(
|
|||
'apm' => $features['alternative_payment_methods']['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(
|
||||
$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.
|
||||
$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).
|
||||
$container->has( 'save-payment-methods.eligible' ) && ! $container->get( 'save-payment-methods.eligible' ) && $container->has( 'wc-subscriptions.helper' ) && $container->get( 'wc-subscriptions.helper' )
|
||||
->plugin_is_active(), // Configure a PayPal Subscription.
|
||||
true, // Add PayPal buttons.
|
||||
$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'], // Add Apple Pay to your account.
|
||||
$capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account.
|
||||
$capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay.
|
||||
$capabilities['google_pay'] && ! $gateways['google_pay'], // Enable Google Pay.
|
||||
$container->has( 'save-payment-methods.eligible' ) &&
|
||||
! $container->get( 'save-payment-methods.eligible' ) &&
|
||||
$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['acdc'] && ! ( $capabilities['apple_pay'] && $capabilities['google_pay'] ), // Add digital wallets to your account.
|
||||
$container->get( 'applepay.eligible' ) && $capabilities['acdc'] && ! $capabilities['apple_pay'], // Add Apple Pay to your account.
|
||||
$container->get( 'googlepay.eligible' ) && $capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account.
|
||||
$container->get( 'applepay.eligible' ) && $capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple 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' )
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -52,6 +52,13 @@ class MerchantConnectionDTO {
|
|||
*/
|
||||
public string $merchant_email = '';
|
||||
|
||||
/**
|
||||
* Merchant's country.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public string $merchant_country = '';
|
||||
|
||||
/**
|
||||
* Whether the merchant is a business or personal account.
|
||||
* Possible values: ['business'|'personal'|'unknown']
|
||||
|
@ -68,6 +75,7 @@ class MerchantConnectionDTO {
|
|||
* @param string $client_secret API client secret.
|
||||
* @param string $merchant_id PayPal's 13-character merchant ID.
|
||||
* @param string $merchant_email Email address of the merchant account.
|
||||
* @param string $merchant_country Merchant's country.
|
||||
* @param string $seller_type Whether the merchant is a business or personal account.
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -76,13 +84,15 @@ class MerchantConnectionDTO {
|
|||
string $client_secret,
|
||||
string $merchant_id,
|
||||
string $merchant_email,
|
||||
string $merchant_country,
|
||||
string $seller_type = SellerTypeEnum::UNKNOWN
|
||||
) {
|
||||
$this->is_sandbox = $is_sandbox;
|
||||
$this->client_id = $client_id;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->merchant_id = $merchant_id;
|
||||
$this->merchant_email = $merchant_email;
|
||||
$this->seller_type = $seller_type;
|
||||
$this->is_sandbox = $is_sandbox;
|
||||
$this->client_id = $client_id;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->merchant_id = $merchant_id;
|
||||
$this->merchant_email = $merchant_email;
|
||||
$this->merchant_country = $merchant_country;
|
||||
$this->seller_type = $seller_type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* PayPal Commerce Todos Definitions
|
||||
* Todos Definitions
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Settings\Data\Definition
|
||||
*/
|
||||
|
@ -145,10 +145,30 @@ class TodosDefinition {
|
|||
),
|
||||
'priority' => 5,
|
||||
),
|
||||
'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'],
|
||||
'add_paypal_buttons_cart' => array(
|
||||
'title' => __( 'Add PayPal buttons to the Cart page', '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_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(
|
||||
'type' => 'tab',
|
||||
'tab' => 'styling',
|
||||
|
|
|
@ -74,6 +74,7 @@ class GeneralSettings extends AbstractDataModel {
|
|||
'sandbox_merchant' => false,
|
||||
'merchant_id' => '',
|
||||
'merchant_email' => '',
|
||||
'merchant_country' => '',
|
||||
'client_id' => '',
|
||||
'client_secret' => '',
|
||||
'seller_type' => 'unknown',
|
||||
|
@ -138,6 +139,7 @@ class GeneralSettings extends AbstractDataModel {
|
|||
$this->data['sandbox_merchant'] = $connection->is_sandbox;
|
||||
$this->data['merchant_id'] = sanitize_text_field( $connection->merchant_id );
|
||||
$this->data['merchant_email'] = sanitize_email( $connection->merchant_email );
|
||||
$this->data['merchant_country'] = sanitize_text_field( $connection->merchant_country );
|
||||
$this->data['client_id'] = sanitize_text_field( $connection->client_id );
|
||||
$this->data['client_secret'] = sanitize_text_field( $connection->client_secret );
|
||||
$this->data['seller_type'] = sanitize_text_field( $connection->seller_type );
|
||||
|
@ -156,6 +158,7 @@ class GeneralSettings extends AbstractDataModel {
|
|||
$this->data['client_secret'],
|
||||
$this->data['merchant_id'],
|
||||
$this->data['merchant_email'],
|
||||
$this->data['merchant_country'],
|
||||
$this->data['seller_type']
|
||||
);
|
||||
}
|
||||
|
@ -171,6 +174,7 @@ class GeneralSettings extends AbstractDataModel {
|
|||
$this->data['sandbox_merchant'] = $defaults['sandbox_merchant'];
|
||||
$this->data['merchant_id'] = $defaults['merchant_id'];
|
||||
$this->data['merchant_email'] = $defaults['merchant_email'];
|
||||
$this->data['merchant_country'] = $defaults['merchant_country'];
|
||||
$this->data['client_id'] = $defaults['client_id'];
|
||||
$this->data['client_secret'] = $defaults['client_secret'];
|
||||
$this->data['seller_type'] = $defaults['seller_type'];
|
||||
|
@ -239,4 +243,13 @@ class GeneralSettings extends AbstractDataModel {
|
|||
public function get_merchant_email() : string {
|
||||
return $this->data['merchant_email'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently connected merchant's country.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_merchant_country() : string {
|
||||
return $this->data['merchant_country'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ use WP_REST_Response;
|
|||
use WP_REST_Request;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\TodosModel;
|
||||
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.
|
||||
|
@ -33,17 +34,6 @@ 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.
|
||||
*
|
||||
|
@ -65,21 +55,31 @@ class TodosRestEndpoint extends RestEndpoint {
|
|||
*/
|
||||
protected SettingsRestEndpoint $settings;
|
||||
|
||||
/**
|
||||
* The todos sorting service.
|
||||
*
|
||||
* @var TodosSortingAndFilteringService
|
||||
*/
|
||||
protected TodosSortingAndFilteringService $sorting_service;
|
||||
|
||||
/**
|
||||
* TodosRestEndpoint constructor.
|
||||
*
|
||||
* @param TodosModel $todos The todos model instance.
|
||||
* @param TodosDefinition $todos_definition The todos definition instance.
|
||||
* @param SettingsRestEndpoint $settings The settings endpoint instance.
|
||||
* @param TodosModel $todos The todos model instance.
|
||||
* @param TodosDefinition $todos_definition The todos definition instance.
|
||||
* @param SettingsRestEndpoint $settings The settings endpoint instance.
|
||||
* @param TodosSortingAndFilteringService $sorting_service The todos sorting service.
|
||||
*/
|
||||
public function __construct(
|
||||
TodosModel $todos,
|
||||
TodosDefinition $todos_definition,
|
||||
SettingsRestEndpoint $settings
|
||||
SettingsRestEndpoint $settings,
|
||||
TodosSortingAndFilteringService $sorting_service
|
||||
) {
|
||||
$this->todos = $todos;
|
||||
$this->todos_definition = $todos_definition;
|
||||
$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->filter_pay_later_todos( $sorted_todos );
|
||||
$filtered_todos = $this->sorting_service->apply_all_priority_filters( $todos );
|
||||
|
||||
return $this->return_success(
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ namespace WooCommerce\PayPalCommerce\Settings\Service;
|
|||
use JsonException;
|
||||
use Throwable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\LoginSeller;
|
||||
|
@ -72,6 +74,13 @@ class AuthenticationManager {
|
|||
*/
|
||||
private ConnectionState $connection_state;
|
||||
|
||||
/**
|
||||
* Partners endpoint.
|
||||
*
|
||||
* @var PartnersEndpoint
|
||||
*/
|
||||
private PartnersEndpoint $partners_endpoint;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -80,6 +89,7 @@ class AuthenticationManager {
|
|||
* @param EnvironmentConfig $login_endpoint API handler to fetch merchant credentials.
|
||||
* @param PartnerReferralsData $referrals_data Partner referrals data.
|
||||
* @param ConnectionState $connection_state Connection state manager.
|
||||
* @param PartnersEndpoint $partners_endpoint Partners endpoint.
|
||||
* @param ?LoggerInterface $logger Logging instance.
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -88,14 +98,16 @@ class AuthenticationManager {
|
|||
EnvironmentConfig $login_endpoint,
|
||||
PartnerReferralsData $referrals_data,
|
||||
ConnectionState $connection_state,
|
||||
PartnersEndpoint $partners_endpoint,
|
||||
?LoggerInterface $logger = null
|
||||
) {
|
||||
$this->common_settings = $common_settings;
|
||||
$this->connection_host = $connection_host;
|
||||
$this->login_endpoint = $login_endpoint;
|
||||
$this->referrals_data = $referrals_data;
|
||||
$this->connection_state = $connection_state;
|
||||
$this->logger = $logger ?: new NullLogger();
|
||||
$this->common_settings = $common_settings;
|
||||
$this->connection_host = $connection_host;
|
||||
$this->login_endpoint = $login_endpoint;
|
||||
$this->referrals_data = $referrals_data;
|
||||
$this->connection_state = $connection_state;
|
||||
$this->partners_endpoint = $partners_endpoint;
|
||||
$this->logger = $logger ?: new NullLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,12 +208,19 @@ class AuthenticationManager {
|
|||
|
||||
$payee = $this->request_payee( $client_id, $client_secret, $use_sandbox );
|
||||
|
||||
try {
|
||||
$seller_status = $this->partners_endpoint->seller_status();
|
||||
} catch ( PayPalApiException $exception ) {
|
||||
$seller_status = null;
|
||||
}
|
||||
|
||||
$connection = new MerchantConnectionDTO(
|
||||
$use_sandbox,
|
||||
$client_id,
|
||||
$client_secret,
|
||||
$payee['merchant_id'],
|
||||
$payee['email_address'],
|
||||
! is_null( $seller_status ) ? $seller_status->country() : '',
|
||||
SellerTypeEnum::BUSINESS
|
||||
);
|
||||
|
||||
|
@ -267,10 +286,17 @@ class AuthenticationManager {
|
|||
*/
|
||||
$connection = $this->common_settings->get_merchant_data();
|
||||
|
||||
$connection->is_sandbox = $use_sandbox;
|
||||
$connection->client_id = $credentials['client_id'];
|
||||
$connection->client_secret = $credentials['client_secret'];
|
||||
$connection->merchant_id = $credentials['merchant_id'];
|
||||
try {
|
||||
$seller_status = $this->partners_endpoint->seller_status();
|
||||
} catch ( PayPalApiException $exception ) {
|
||||
$seller_status = null;
|
||||
}
|
||||
|
||||
$connection->is_sandbox = $use_sandbox;
|
||||
$connection->client_id = $credentials['client_id'];
|
||||
$connection->client_secret = $credentials['client_secret'];
|
||||
$connection->merchant_id = $credentials['merchant_id'];
|
||||
$connection->merchant_country = ! is_null( $seller_status ) ? $seller_status->country() : '';
|
||||
|
||||
$this->update_connection_details( $connection );
|
||||
}
|
||||
|
@ -306,6 +332,13 @@ class AuthenticationManager {
|
|||
$connection->seller_type = $seller_type;
|
||||
}
|
||||
|
||||
try {
|
||||
$seller_status = $this->partners_endpoint->seller_status();
|
||||
} catch ( PayPalApiException $exception ) {
|
||||
$seller_status = null;
|
||||
}
|
||||
$connection->merchant_country = ! is_null( $seller_status ) ? $seller_status->country() : '';
|
||||
|
||||
$this->update_connection_details( $connection );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* PayPal Commerce eligibility service for WooCommerce.
|
||||
* Eligibility service for Todos.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Settings\Service
|
||||
|
@ -66,6 +66,27 @@ class TodosEligibilityService {
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -94,13 +115,6 @@ class TodosEligibilityService {
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -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_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_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_digital_wallet_eligible Whether digital wallet features are 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_checkout_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_digital_wallet_eligible,
|
||||
bool $is_apple_pay_eligible,
|
||||
|
@ -149,20 +167,22 @@ 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_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_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_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_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_enable_apple_pay_eligible = $is_enable_apple_pay_eligible;
|
||||
$this->is_enable_google_pay_eligible = $is_enable_google_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_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,
|
||||
'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,
|
||||
'add_digital_wallets' => fn() => $this->is_digital_wallet_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;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,8 @@ declare( strict_types = 1 );
|
|||
namespace WooCommerce\PayPalCommerce\Settings;
|
||||
|
||||
use WC_Payment_Gateway;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Assets\AppleProductStatus;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
||||
|
@ -302,8 +304,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
|
||||
$flags = new ConfigurationFlagsDTO();
|
||||
|
||||
// TODO: Get the merchant country from PayPal here!
|
||||
$flags->country_code = 'US';
|
||||
$flags->country_code = $general_settings->get_merchant_country();
|
||||
$flags->is_business_seller = $general_settings->is_business_seller();
|
||||
$flags->use_card_payments = $onboarding_profile->get_accept_card_payments();
|
||||
$flags->use_subscriptions = in_array( ProductChoicesEnum::SUBSCRIPTIONS, $onboarding_profile->get_products(), true );
|
||||
|
@ -340,18 +341,18 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
unset( $payment_methods['venmo'] );
|
||||
}
|
||||
|
||||
// Unset if not eligible for Google Pay.
|
||||
if ( ! $googlepay_product_status->is_active() ) {
|
||||
// Unset if country/currency is not supported or merchant not eligible for Google Pay.
|
||||
if ( ! $container->get( 'googlepay.eligible' ) || ! $googlepay_product_status->is_active() ) {
|
||||
unset( $payment_methods['ppcp-googlepay'] );
|
||||
}
|
||||
|
||||
// Unset if not eligible for Apple Pay.
|
||||
if ( ! $applepay_product_status->is_active() ) {
|
||||
// Unset if country/currency is not supported or merchant not eligible for Apple Pay.
|
||||
if ( ! $container->get( 'applepay.eligible' ) || ! $applepay_product_status->is_active() ) {
|
||||
unset( $payment_methods['ppcp-applepay'] );
|
||||
}
|
||||
|
||||
// Unset Fastlane if store location is not United States or merchant is not eligible for ACDC.
|
||||
if ( $container->get( 'api.shop.country' ) !== 'US' || ! $dcc_product_status->is_active() ) {
|
||||
// Unset Fastlane if country/currency is not supported or merchant is not eligible for BCDC.
|
||||
if ( ! $container->get( 'axo.eligible' ) || ! $dcc_product_status->is_active() ) {
|
||||
unset( $payment_methods['ppcp-axo-gateway'] );
|
||||
}
|
||||
|
||||
|
|
|
@ -1854,6 +1854,13 @@ return array(
|
|||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
if ( apply_filters(
|
||||
'woocommerce.feature-flags.woocommerce_paypal_payments.settings_enabled',
|
||||
getenv( 'PCP_SETTINGS_ENABLED' ) === '1'
|
||||
) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $settings->has( 'fraudnet_enabled' ) && $settings->get( 'fraudnet_enabled' );
|
||||
},
|
||||
'wcgateway.fraudnet-assets' => function( ContainerInterface $container ) : FraudNetAssets {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue