diff --git a/modules/ppcp-onboarding/services.php b/modules/ppcp-onboarding/services.php index 54fc926cd5..2e83780404 100644 --- a/modules/ppcp-onboarding/services.php +++ b/modules/ppcp-onboarding/services.php @@ -105,7 +105,7 @@ $woo_country = $container->get( 'api.shop.country' ); $eligibility_checks = $container->get( 'wcgateway.feature-eligibility.list' ); - return new MerchantDetails( $woo_country, $woo_country, $eligibility_checks ); + return new MerchantDetails( $woo_country, $eligibility_checks ); }, 'onboarding.assets' => function ( ContainerInterface $container ): OnboardingAssets { $state = $container->get( 'onboarding.state' ); diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 6b0f7eda1c..ee586c0645 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -5,7 +5,7 @@ * @package WooCommerce\PayPalCommerce\Settings */ -declare( strict_types = 1 ); +declare( strict_types=1 ); namespace WooCommerce\PayPalCommerce\Settings; @@ -49,9 +49,9 @@ use WooCommerce\PayPalCommerce\Settings\Service\BrandedExperience\ActivationDetector; use WooCommerce\PayPalCommerce\Settings\Service\BrandedExperience\PathRepository; use WooCommerce\PayPalCommerce\Settings\Service\ConnectionUrlGenerator; -use WooCommerce\PayPalCommerce\Settings\Service\FeaturesEligibilityService; use WooCommerce\PayPalCommerce\Settings\Service\GatewayRedirectService; use WooCommerce\PayPalCommerce\Settings\Service\LoadingScreenService; +use WooCommerce\PayPalCommerce\Settings\Service\MerchantCapabilities; use WooCommerce\PayPalCommerce\Settings\Service\Migration\SettingsMigration; use WooCommerce\PayPalCommerce\Settings\Service\Migration\MigrationManager; use WooCommerce\PayPalCommerce\Settings\Service\Migration\PaymentSettingsMigration; @@ -83,14 +83,14 @@ return plugins_url( '/modules/ppcp-settings/', $container->get( 'ppcp.path-to-plugin-main-file' ) ); }, 'settings.data.onboarding' => static function ( ContainerInterface $container ): OnboardingProfile { - $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(); + $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(); $should_skip_payment_methods = class_exists( '\WC_Payments' ); - $can_use_fastlane = $container->get( 'axo.eligible' ); - $can_use_pay_later = $container->get( 'button.helper.messages-apply' ); + $can_use_fastlane = $container->get( 'axo.eligible' ); + $can_use_pay_later = $container->get( 'button.helper.messages-apply' ); return new OnboardingProfile( $can_use_casual_selling, @@ -354,14 +354,15 @@ ); }, 'settings.service.script-data-handler' => static function ( ContainerInterface $container ): ScriptDataHandler { - $settings = $container->get( 'wcgateway.settings' ); - $settings_url = $container->get( 'settings.url' ); - $paylater_is_available = $container->get( 'paylater-configurator.is-available' ); - $store_country = $container->get( 'wcgateway.store-country' ); - $merchant_id = $container->get( 'api.partner_merchant_id' ); - $button_language_choices = $container->get( 'wcgateway.wp-paypal-locales-map' ); - $partner_attribution = $container->get( 'api.helper.partner-attribution' ); + $settings = $container->get( 'wcgateway.settings' ); + $settings_url = $container->get( 'settings.url' ); + $paylater_is_available = $container->get( 'paylater-configurator.is-available' ); + $store_country = $container->get( 'wcgateway.store-country' ); + $merchant_id = $container->get( 'api.partner_merchant_id' ); + $button_language_choices = $container->get( 'wcgateway.wp-paypal-locales-map' ); + $partner_attribution = $container->get( 'api.helper.partner-attribution' ); $path_to_module_assets_folder = $container->get( 'ppcp.path-to-plugin-folder' ) . 'modules/ppcp-settings/assets'; + return new ScriptDataHandler( $settings, $settings_url, $paylater_is_available, $store_country, $merchant_id, $button_language_choices, $partner_attribution, $path_to_module_assets_folder ); }, 'settings.service.data-migration' => static fn( ContainerInterface $c ): MigrationManager => new MigrationManager( @@ -392,7 +393,7 @@ $c->get( 'settings.data.general' ), $c->get( 'api.endpoint.partners' ), ), - 'settings.ajax.switch_ui' => static fn ( ContainerInterface $c ): SwitchSettingsUiEndpoint => new SwitchSettingsUiEndpoint( + 'settings.ajax.switch_ui' => static fn( ContainerInterface $c ): SwitchSettingsUiEndpoint => new SwitchSettingsUiEndpoint( $c->get( 'woocommerce.logger.woocommerce' ), $c->get( 'button.request-data' ), $c->get( 'settings.data.onboarding' ), @@ -418,7 +419,7 @@ ); }, 'settings.data.definition.methods' => static function ( ContainerInterface $container ): PaymentMethodsDefinition { - $axo_checkout_config_notice = $container->get( 'axo.checkout-config-notice.raw' ); + $axo_checkout_config_notice = $container->get( 'axo.checkout-config-notice.raw' ); $axo_incompatible_plugins_notice = $container->get( 'axo.incompatible-plugins-notice.raw' ); // Combine the notices - only include non-empty ones. @@ -449,7 +450,7 @@ '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', + $pay_later_settings['data']['custom_placement'][0]['status'] === 'enabled', ); $is_pay_later_messaging_enabled_for_any_location = ! array_filter( $pay_later_statuses ); @@ -461,7 +462,7 @@ }, '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']; + $styling_data = $styling_endpoint->get_details()->get_data()['data']; return array( 'cart_enabled' => $styling_data['cart']->enabled ?? false, @@ -471,7 +472,7 @@ }, 'settings.service.gateways_status' => static function ( ContainerInterface $container ): array { $payment_endpoint = $container->get( 'settings.rest.payment' ); - $settings = $payment_endpoint->get_details()->get_data(); + $settings = $payment_endpoint->get_details()->get_data(); return array( 'apple_pay' => $settings['data']['ppcp-applepay']['enabled'] ?? false, @@ -497,24 +498,26 @@ $general_settings = $container->get( 'settings.data.general' ); assert( $general_settings instanceof GeneralSettings ); + $is_acdc_enabled = ( $features['advanced_credit_and_debit_cards']['enabled'] ?? false ) && ! $general_settings->own_brand_only(); + return array( - 'apple_pay' => ( $features['apple_pay']['enabled'] ?? false ) && ! $general_settings->own_brand_only(), - 'google_pay' => ( $features['google_pay']['enabled'] ?? false ) && ! $general_settings->own_brand_only(), - 'acdc' => ( $features['advanced_credit_and_debit_cards']['enabled'] ?? false ) && ! $general_settings->own_brand_only(), - 'save_paypal' => $features['save_paypal_and_venmo']['enabled'] ?? false, + 'apple_pay' => ( $features['apple_pay']['enabled'] ?? false ) && $is_acdc_enabled, + 'google_pay' => ( $features['google_pay']['enabled'] ?? false ) && $is_acdc_enabled, + 'acdc' => $is_acdc_enabled, 'apm' => $features['alternative_payment_methods']['enabled'] ?? false, - 'paylater' => $features['pay_later_messaging']['enabled'] ?? false, + 'save_paypal' => $features['save_paypal_and_venmo']['enabled'] ?? false, + 'paylater' => $features['pay_later_messaging']['enabled'] ?? false , 'installments' => $features['installments']['enabled'] ?? false, ); }, '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']; + $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' ); + $gateways = $container->get( 'settings.service.gateways_status' ); // TODO: This "merchant_capabilities" service is only used here. Could it be merged to make the code cleaner and less segmented? $capabilities = $container->get( 'settings.service.merchant_capabilities' ); @@ -545,23 +548,23 @@ * 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_pay_later_messaging_eligible - Show if Pay Later messaging is enabled for at least one location. + * @param bool $is_fastlane_eligible - Show if merchant is eligible (ACDC) but hasn't enabled Fastlane 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_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. - * @param bool $is_enable_installments_eligible - Show if merchant has installments capability and merchant country is MX. - * @param bool $is_working_capital_eligible - Show if feature flag is enabled, merchant country is US and "Stay Updated" is turned On. + * @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. + * @param bool $is_enable_installments_eligible - Show if merchant has installments capability and merchant country is MX. + * @param bool $is_working_capital_eligible - Show if feature flag is enabled, merchant country is US and "Stay Updated" is turned On. */ return new TodosEligibilityService( $container->get( 'axo.eligible' ) && $capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane. @@ -593,65 +596,14 @@ ); }, 'settings.data.definition.features' => static function ( ContainerInterface $container ): FeaturesDefinition { - $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(); + $merchant_capabilities = $container->get( 'settings.service.merchant_capabilities' ); - // Settings status. - $gateways = array( - 'card-button' => $settings['data']['ppcp-card-button-gateway']['enabled'] ?? false, - ); - // Merchant capabilities, serve to show active or inactive badge and buttons. - $capabilities = array( - 'apple_pay' => $features['apple_pay']['enabled'] ?? false, - 'google_pay' => $features['google_pay']['enabled'] ?? false, - 'acdc' => $features['advanced_credit_and_debit_cards']['enabled'] ?? false, - 'save_paypal' => $features['save_paypal_and_venmo']['enabled'] ?? false, - 'alternative_payment_methods' => $features['alternative_payment_methods']['enabled'] ?? false, - 'installments' => $features['installments']['enabled'] ?? false, - ); - - $merchant_capabilities = array( - 'save_paypal' => $capabilities['save_paypal'], // Save PayPal and Venmo eligibility. - 'acdc' => $capabilities['acdc'], // Advanced credit and debit cards eligibility. - 'apm' => $capabilities['alternative_payment_methods'], // Alternative payment methods eligibility. - 'google_pay' => $capabilities['acdc'] && $capabilities['google_pay'], // Google Pay eligibility. - 'apple_pay' => $capabilities['acdc'] && $capabilities['apple_pay'], // Apple Pay eligibility. - 'pay_later' => $capabilities['acdc'] && ! $gateways['card-button'], // Pay Later eligibility. - 'installments' => $capabilities['installments'], // Installments eligibility. - ); return new FeaturesDefinition( - $container->get( 'settings.service.features_eligibilities' ), $container->get( 'settings.data.general' ), $merchant_capabilities, $container->get( 'settings.data.settings' ) ); }, - 'settings.service.features_eligibilities' => static function ( ContainerInterface $container ): FeaturesEligibilityService { - - $messages_apply = $container->get( 'button.helper.messages-apply' ); - assert( $messages_apply instanceof MessagesApply ); - $pay_later_eligible = $messages_apply->for_country(); - - // TODO: Variable "merchant_country" contains "shop-country". Which is correct? - $merchant_country = $container->get( 'api.shop.country' ); - $ineligible_countries = array( 'RU', 'BR', 'JP' ); - $apm_eligible = ! in_array( $merchant_country, $ineligible_countries, true ); - - return new FeaturesEligibilityService( - $container->get( 'save-payment-methods.eligible' ), // Save PayPal and Venmo eligibility. - $container->get( 'card-fields.eligibility.check' ), // Advanced credit and debit cards eligibility. - $apm_eligible, // Alternative payment methods eligibility. - $container->get( 'googlepay.eligibility.check' ), // Google Pay eligibility. - $container->get( 'applepay.eligibility.check' ), // Apple Pay eligibility. - $pay_later_eligible, // Pay Later eligibility. - 'MX' === $container->get( 'settings.data.general' )->get_merchant_country(), // Installments eligibility. - ); - }, 'settings.service.todos_sorting' => static function ( ContainerInterface $container ): TodosSortingAndFilteringService { return new TodosSortingAndFilteringService( $container->get( 'settings.data.todos' ) @@ -701,12 +653,10 @@ $data = $container->get( 'settings.data.general' ); assert( $data instanceof GeneralSettings ); - $merchant_country = $data->get_merchant_country(); - $woo_data = $data->get_woo_settings(); - + $merchant_country = $data->get_merchant_country(); $eligibility_checks = $container->get( 'wcgateway.feature-eligibility.list' ); - return new MerchantDetails( $merchant_country, $woo_data['country'], $eligibility_checks ); + return new MerchantDetails( $merchant_country, $eligibility_checks ); }, 'settings.migration.bcdc-override-check' => static function (): callable { return static fn(): bool => (bool) get_option( PaymentSettingsMigration::OPTION_NAME_BCDC_MIGRATION_OVERRIDE ); diff --git a/modules/ppcp-settings/src/Data/Definition/FeaturesDefinition.php b/modules/ppcp-settings/src/Data/Definition/FeaturesDefinition.php index 4d30830f77..f8d5e31c55 100644 --- a/modules/ppcp-settings/src/Data/Definition/FeaturesDefinition.php +++ b/modules/ppcp-settings/src/Data/Definition/FeaturesDefinition.php @@ -22,12 +22,6 @@ class FeaturesDefinition { - /** - * The features eligibility service. - * - * @var FeaturesEligibilityService - */ - protected FeaturesEligibilityService $eligibilities; /** * The general settings service. @@ -53,18 +47,15 @@ class FeaturesDefinition { /** * Constructor. * - * @param FeaturesEligibilityService $eligibilities The features eligibility service. * @param GeneralSettings $settings The general settings service. * @param array $merchant_capabilities The merchant capabilities. * @param SettingsModel $plugin_settings The plugin settings. */ public function __construct( - FeaturesEligibilityService $eligibilities, GeneralSettings $settings, array $merchant_capabilities, SettingsModel $plugin_settings ) { - $this->eligibilities = $eligibilities; $this->settings = $settings; $this->merchant_capabilities = $merchant_capabilities; $this->plugin_settings = $plugin_settings; @@ -76,15 +67,7 @@ public function __construct( * @return array The array of feature definitions. */ public function get(): array { - $all_features = $this->all_available_features(); - $eligible_features = array(); - $eligibility_checks = $this->eligibilities->get_eligibility_checks(); - foreach ( $all_features as $feature_key => $feature ) { - if ( $eligibility_checks[ $feature_key ]() ) { - $eligible_features[ $feature_key ] = $feature; - } - } - return $eligible_features; + return $this->all_available_features(); } /** @@ -106,7 +89,7 @@ public function all_available_features(): array { $country_location = in_array( $store_country, $paylater_countries, true ) ? strtolower( $store_country ) : 'us'; $save_paypal_and_venmo = $this->plugin_settings->get_save_paypal_and_venmo(); - return array( + $features = array( 'save_paypal_and_venmo' => array( 'title' => __( 'Save PayPal and Venmo', 'woocommerce-paypal-payments' ), 'description' => __( 'Securely save PayPal and Venmo payment methods for subscriptions or return buyers.', 'woocommerce-paypal-payments' ), @@ -297,7 +280,7 @@ public function all_available_features(): array { 'Let customers know they can buy now and pay later with PayPal. Adding this messaging can boost conversion rates and increase cart sizes by 39%¹, with no extra cost to you—plus, you get paid up front.', 'woocommerce-paypal-payments' ), - 'enabled' => $this->merchant_capabilities['pay_later'] && ! $save_paypal_and_venmo, + 'enabled' => $this->merchant_capabilities['paylater'] && ! $save_paypal_and_venmo, 'buttons' => array( array( 'type' => 'secondary', @@ -346,5 +329,10 @@ public function all_available_features(): array { ), ), ); + if ( $this->settings->get_merchant_country() !== 'MX' ) { + unset( $features['installments'] ); + } + + return $features; } } diff --git a/modules/ppcp-settings/src/Service/FeaturesEligibilityService.php b/modules/ppcp-settings/src/Service/FeaturesEligibilityService.php deleted file mode 100644 index 3e0fc3278a..0000000000 --- a/modules/ppcp-settings/src/Service/FeaturesEligibilityService.php +++ /dev/null @@ -1,114 +0,0 @@ -is_save_paypal_eligible = $is_save_paypal_eligible; - $this->check_acdc_eligible = $check_acdc_eligible; - $this->is_apm_eligible = $is_apm_eligible; - $this->check_google_pay_eligible = $check_google_pay_eligible; - $this->check_apple_pay_eligible = $check_apple_pay_eligible; - $this->is_pay_later_eligible = $is_pay_later_eligible; - $this->is_installments_eligible = $is_installments_eligible; - } - - /** - * Returns all eligibility checks as callables. - * - * @return array - */ - public function get_eligibility_checks(): array { - return array( - 'save_paypal_and_venmo' => fn() => $this->is_save_paypal_eligible, - 'advanced_credit_and_debit_cards' => $this->check_acdc_eligible, - 'alternative_payment_methods' => fn() => $this->is_apm_eligible, - 'google_pay' => $this->check_google_pay_eligible, - 'apple_pay' => $this->check_apple_pay_eligible, - 'pay_later' => fn() => $this->is_pay_later_eligible, - 'installments' => fn() => $this->is_installments_eligible, - ); - } -} diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 289b64a714..a001da00c9 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -7,7 +7,7 @@ // phpcs:disable WordPress.Security.NonceVerification.Recommended -declare(strict_types=1); +declare( strict_types=1 ); namespace WooCommerce\PayPalCommerce\WcGateway; @@ -19,14 +19,17 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; use WooCommerce\PayPalCommerce\Applepay\ApplePayGateway; +use WooCommerce\PayPalCommerce\Applepay\Assets\AppleProductStatus; use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway; use WooCommerce\PayPalCommerce\Axo\Helper\PropertiesDictionary; use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply; use WooCommerce\PayPalCommerce\Button\Helper\MessagesDisclaimers; use WooCommerce\PayPalCommerce\Common\Pattern\SingletonDecorator; use WooCommerce\PayPalCommerce\Googlepay\GooglePayGateway; +use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\LocalApmProductStatus; use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer; use WooCommerce\PayPalCommerce\Onboarding\State; +use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings; use WooCommerce\PayPalCommerce\Settings\Data\SettingsModel; use WooCommerce\PayPalCommerce\Settings\SettingsModule; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; @@ -233,20 +236,23 @@ ); }, 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways { - $settings = $container->get( 'wcgateway.settings' ); - $settings_status = $container->get( 'wcgateway.settings.status' ); + $settings = $container->get( 'wcgateway.settings' ); + $settings_status = $container->get( 'wcgateway.settings.status' ); $subscription_helper = $container->get( 'wc-subscriptions.helper' ); - $context = $container->get( 'button.helper.context' ); + $context = $container->get( 'button.helper.context' ); + return new DisableGateways( $settings, $settings_status, $subscription_helper, $context ); }, 'wcgateway.is-wc-settings-page' => static function ( ContainerInterface $container ): bool { $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; + return 'wc-settings' === $page; }, 'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool { $is_wc_settings_page = $container->get( 'wcgateway.is-wc-settings-page' ); - $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : ''; + $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : ''; + return $is_wc_settings_page && 'checkout' === $tab; }, 'wcgateway.is-wc-gateways-list-page' => static function ( ContainerInterface $container ): bool { @@ -259,6 +265,7 @@ } $section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : ''; + return in_array( $section, array( @@ -305,7 +312,7 @@ return ''; } - $section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : ''; + $section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : ''; $ppcp_tab = isset( $_GET[ SectionsRenderer::KEY ] ) ? sanitize_text_field( wp_unslash( $_GET[ SectionsRenderer::KEY ] ) ) : ''; $is_connected = $container->get( 'settings.flag.is-connected' ); @@ -367,6 +374,7 @@ static function ( ContainerInterface $container ): Settings { }, 'wcgateway.store-country' => static function (): string { $location = wc_get_base_location(); + return $location['country']; }, 'wcgateway.send-only-message' => static function () { @@ -455,8 +463,9 @@ static function ( ContainerInterface $container ): Settings { ); }, 'wcgateway.is-send-only-country' => static function ( ContainerInterface $container ) { - $store_country = $container->get( 'wcgateway.store-country' ); + $store_country = $container->get( 'wcgateway.store-country' ); $send_only_countries = $container->get( 'wcgateway.send-only-countries' ); + return in_array( $store_country, $send_only_countries, true ); }, 'wcgateway.notice.send-only-country' => static function ( ContainerInterface $container ) { @@ -478,7 +487,7 @@ static function ( ContainerInterface $container ): string { $settings = $container->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); - $axo_available = $container->has( 'axo.available' ) && $container->get( 'axo.available' ); + $axo_available = $container->has( 'axo.available' ) && $container->get( 'axo.available' ); $dcc_configuration = $container->get( 'wcgateway.configuration.card-configuration' ); assert( $dcc_configuration instanceof CardPaymentsConfiguration ); @@ -491,7 +500,7 @@ static function ( ContainerInterface $container ): string { } $checkout_page_link = esc_url( get_edit_post_link( wc_get_page_id( 'checkout' ) ) ?? '' ); - $instructions_link = 'https://woocommerce.com/document/cart-checkout-blocks-status/#using-the-cart-and-checkout-blocks'; + $instructions_link = 'https://woocommerce.com/document/cart-checkout-blocks-status/#using-the-cart-and-checkout-blocks'; $notice_content = sprintf( /* translators: %1$s: URL to the Checkout edit page. %2$s: URL to the WooCommerce Checkout instructions. */ @@ -522,7 +531,8 @@ static function ( ContainerInterface $container ): string { ); }, 'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus { - $settings = $container->get( 'wcgateway.settings' ); + $settings = $container->get( 'wcgateway.settings' ); + return new SettingsStatus( $settings ); }, 'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer { @@ -563,16 +573,17 @@ static function ( ContainerInterface $container ): string { }, 'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor { - $session_handler = $container->get( 'session.handler' ); - $order_endpoint = $container->get( 'api.endpoint.order' ); - $order_factory = $container->get( 'api.factory.order' ); - $threed_secure = $container->get( 'button.helper.three-d-secure' ); + $session_handler = $container->get( 'session.handler' ); + $order_endpoint = $container->get( 'api.endpoint.order' ); + $order_factory = $container->get( 'api.factory.order' ); + $threed_secure = $container->get( 'button.helper.three-d-secure' ); $authorized_payments_processor = $container->get( 'wcgateway.processor.authorized-payments' ); $settings = $container->get( 'wcgateway.settings' ); $environment = $container->get( 'settings.environment' ); $logger = $container->get( 'woocommerce.logger.woocommerce' ); - $subscription_helper = $container->get( 'wc-subscriptions.helper' ); - $order_helper = $container->get( 'api.order-helper' ); + $subscription_helper = $container->get( 'wc-subscriptions.helper' ); + $order_helper = $container->get( 'api.order-helper' ); + return new OrderProcessor( $session_handler, $order_endpoint, @@ -600,13 +611,14 @@ static function ( ContainerInterface $container ): string { ); }, 'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor { - $order_endpoint = $container->get( 'api.endpoint.order' ); - $payments_endpoint = $container->get( 'api.endpoint.payments' ); - $logger = $container->get( 'woocommerce.logger.woocommerce' ); + $order_endpoint = $container->get( 'api.endpoint.order' ); + $payments_endpoint = $container->get( 'api.endpoint.payments' ); + $logger = $container->get( 'woocommerce.logger.woocommerce' ); $notice = $container->get( 'wcgateway.notice.authorize-order-action' ); $settings = $container->get( 'wcgateway.settings' ); $subscription_helper = $container->get( 'wc-subscriptions.helper' ); $amount_factory = $container->get( 'api.factory.amount' ); + return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint, @@ -619,18 +631,22 @@ static function ( ContainerInterface $container ): string { }, 'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction { $column = $container->get( 'wcgateway.admin.orders-payment-status-column' ); + return new RenderAuthorizeAction( $column ); }, 'wcgateway.admin.render-reauthorize-action' => static function ( ContainerInterface $container ): RenderReauthorizeAction { $column = $container->get( 'wcgateway.admin.orders-payment-status-column' ); + return new RenderReauthorizeAction( $column ); }, 'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail { $column = $container->get( 'wcgateway.admin.orders-payment-status-column' ); + return new PaymentStatusOrderDetail( $column ); }, 'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ): OrderTablePaymentStatusColumn { $settings = $container->get( 'wcgateway.settings' ); + return new OrderTablePaymentStatusColumn( $settings ); }, 'wcgateway.admin.fees-renderer' => static function ( ContainerInterface $container ): FeesRenderer { @@ -709,7 +725,7 @@ static function ( ContainerInterface $container ): string { $dcc_configuration = $container->get( 'wcgateway.configuration.card-configuration' ); assert( $dcc_configuration instanceof CardPaymentsConfiguration ); - $fields = array( + $fields = array( 'checkout_settings_heading' => array( 'heading' => __( 'Standard Payments Settings', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-heading', @@ -1235,7 +1251,7 @@ static function ( ContainerInterface $container ): string { 'type' => 'checkbox', 'desc_tip' => true, 'label' => sprintf( - // translators: %1$s and %2$s are the opening and closing of HTML tag. + // translators: %1$s and %2$s are the opening and closing of HTML tag. __( 'Securely store your customers’ PayPal accounts for a seamless checkout experience. Payment methods are saved in the secure %1$sPayPal Vault%2$s.', 'woocommerce-paypal-payments' ), '', '' @@ -1285,8 +1301,8 @@ static function ( ContainerInterface $container ): string { * Depending on your store location, some credit cards can't be used. * Here, we filter them out. */ - $card_options = $fields['disable_cards']['options']; - $card_icons = $fields['card_icons']['options']; + $card_options = $fields['disable_cards']['options']; + $card_icons = $fields['card_icons']['options']; $dark_versions = array(); foreach ( $card_options as $card => $label ) { if ( $dcc_applies->can_process_card( $card ) ) { @@ -1302,7 +1318,7 @@ static function ( ContainerInterface $container ): string { } $fields['disable_cards']['options'] = $card_options; - $fields['card_icons']['options'] = array_merge( $dark_versions, $card_options ); + $fields['card_icons']['options'] = array_merge( $dark_versions, $card_options ); if ( $container->get( 'api.shop.country' ) !== 'MX' ) { unset( $fields['mexico_installments'] ); @@ -1372,6 +1388,7 @@ static function ( ContainerInterface $container ): string { 'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ): ReturnUrlEndpoint { $gateway = $container->get( 'wcgateway.paypal-gateway' ); $endpoint = $container->get( 'api.endpoint.order' ); + return new ReturnUrlEndpoint( $gateway, $endpoint, @@ -1401,6 +1418,7 @@ static function ( ContainerInterface $container ): string { if ( $settings->has( 'soft_descriptor' ) ) { return $settings->get( 'soft_descriptor' ); } + return ''; }, @@ -1425,6 +1443,7 @@ static function ( ContainerInterface $container ): string { $settings = $container->get( 'wcgateway.settings' ); $partner_endpoint = $container->get( 'api.endpoint.partners' ); + return new DCCProductStatus( $settings, $partner_endpoint, @@ -1436,8 +1455,9 @@ static function ( ContainerInterface $container ): string { }, 'wcgateway.helper.refund-fees-updater' => static function ( ContainerInterface $container ): RefundFeesUpdater { - $order_endpoint = $container->get( 'api.endpoint.order' ); - $logger = $container->get( 'woocommerce.logger.woocommerce' ); + $order_endpoint = $container->get( 'api.endpoint.order' ); + $logger = $container->get( 'woocommerce.logger.woocommerce' ); + return new RefundFeesUpdater( $order_endpoint, $logger ); }, 'wcgateway.helper.fees-updater' => static function ( ContainerInterface $container ): FeesUpdater { @@ -1499,6 +1519,7 @@ static function ( ContainerInterface $container ): string { }, 'wcgateway.fraudnet' => static function ( ContainerInterface $container ): FraudNet { $source_website_id = $container->get( 'wcgateway.fraudnet-source-website-id' ); + return new FraudNet( (string) $source_website_id() ); @@ -1615,6 +1636,7 @@ static function ( ContainerInterface $container ): string { 'wcgateway.helper.vaulting-scope' => static function ( ContainerInterface $container ): bool { try { $token = $container->get( 'api.bearer' )->bearer(); + return $token->vaulting_available(); } catch ( RuntimeException $exception ) { return false; @@ -1625,7 +1647,7 @@ static function ( ContainerInterface $container ): string { $vaulting_label = ''; if ( ! $container->get( 'wcgateway.helper.vaulting-scope' ) ) { $vaulting_label .= sprintf( - // translators: %1$s and %2$s are the opening and closing of HTML tag. + // translators: %1$s and %2$s are the opening and closing of HTML tag. __( ' To use vaulting features, you must %1$senable vaulting on your account%2$s.', 'woocommerce-paypal-payments' ), 'has( 'allow_card_button_gateway' ) ? - (bool) $settings->get( 'allow_card_button_gateway' ) : - $container->get( 'wcgateway.settings.allow_card_button_gateway.default' ) + (bool) $settings->get( 'allow_card_button_gateway' ) : + $container->get( 'wcgateway.settings.allow_card_button_gateway.default' ) ); }, 'wcgateway.settings.has_enabled_separate_button_gateways' => static function ( ContainerInterface $container ): bool { @@ -1700,7 +1722,7 @@ static function ( ContainerInterface $container ): string { }, 'wcgateway.settings.fraudnet-label' => static function ( ContainerInterface $container ): string { $label = sprintf( - // translators: %1$s and %2$s are the opening and closing of HTML tag. + // translators: %1$s and %2$s are the opening and closing of HTML tag. __( 'Manage online risk with %1$sFraudNet%2$s.', 'woocommerce-paypal-payments' ), '', '' @@ -1864,6 +1886,7 @@ static function ( ContainerInterface $container ): string { 'wcgateway.button.default-locations' => static function ( ContainerInterface $container ): array { $button_locations = $container->get( 'wcgateway.button.locations' ); unset( $button_locations['mini-cart'] ); + return array_keys( $button_locations ); }, 'wcgateway.button.recommended-styling-notice' => static function ( ContainerInterface $container ): string { @@ -1887,6 +1910,7 @@ static function ( ContainerInterface $container ): string { 'wcgateway.settings.pay-later.messaging-locations' => static function ( ContainerInterface $container ): array { $button_locations = $container->get( 'wcgateway.button.locations' ); unset( $button_locations['mini-cart'] ); + return array_merge( $button_locations, array( @@ -1898,6 +1922,7 @@ static function ( ContainerInterface $container ): string { 'wcgateway.settings.pay-later.default-messaging-locations' => static function ( ContainerInterface $container ): array { $locations = $container->get( 'wcgateway.settings.pay-later.messaging-locations' ); unset( $locations['home'] ); + return array_keys( $locations ); }, 'wcgateway.settings.pay-later.button-locations' => static function ( ContainerInterface $container ): array { @@ -1929,11 +1954,11 @@ static function ( ContainerInterface $container ): string { ); }, 'wcgateway.is-fraudnet-enabled' => static function ( ContainerInterface $container ): bool { - $settings = $container->get( 'wcgateway.settings' ); + $settings = $container->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); if ( apply_filters( - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- feature flags use this convention + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- feature flags use this convention 'woocommerce.feature-flags.woocommerce_paypal_payments.settings_enabled', getenv( 'PCP_SETTINGS_ENABLED' ) === '1' ) ) { @@ -1963,6 +1988,7 @@ static function ( ContainerInterface $container ): string { 'wcgateway.display-manager' => SingletonDecorator::make( static function ( ContainerInterface $container ): DisplayManager { $settings = $container->get( 'wcgateway.settings' ); + return new DisplayManager( $settings ); } ), @@ -2036,7 +2062,7 @@ static function ( ContainerInterface $container ): DisplayManager { }, 'wcgateway.settings.wc-tasks.pay-later-task-config' => static function ( ContainerInterface $container ): array { - $section_id = PayPalGateway::ID; + $section_id = PayPalGateway::ID; $pay_later_tab_id = Settings::PAY_LATER_TAB_ID; if ( $container->has( 'paylater-configurator.is-available' ) && $container->get( 'paylater-configurator.is-available' ) ) { @@ -2054,7 +2080,7 @@ static function ( ContainerInterface $container ): DisplayManager { }, 'wcgateway.settings.wc-tasks.connect-task-config' => static function ( ContainerInterface $container ): array { - $is_connected = $container->get( 'settings.flag.is-connected' ); + $is_connected = $container->get( 'settings.flag.is-connected' ); $is_current_country_send_only = $container->get( 'wcgateway.is-send-only-country' ); if ( ! $is_connected && ! $is_current_country_send_only ) { @@ -2116,12 +2142,12 @@ static function ( ContainerInterface $container ): DisplayManager { * }> */ 'wcgateway.settings.wc-tasks.simple-redirect-tasks-config' => static function ( ContainerInterface $container ): array { - $list_of_config = array(); + $list_of_config = array(); $task_config_services = $container->get( 'wcgateway.settings.wc-tasks.task-config-services' ); foreach ( $task_config_services as $service_id ) { if ( $container->has( $service_id ) ) { - $task_config = $container->get( $service_id ); + $task_config = $container->get( $service_id ); $list_of_config = array_merge( $list_of_config, $task_config ); } } @@ -2142,10 +2168,10 @@ static function ( ContainerInterface $container ): DisplayManager { $simple_redirect_tasks = array(); foreach ( $simple_redirect_tasks_config as $config ) { - $id = $config['id'] ?? ''; - $title = $config['title'] ?? ''; - $description = $config['description'] ?? ''; - $redirect_url = $config['redirect_url'] ?? ''; + $id = $config['id'] ?? ''; + $title = $config['title'] ?? ''; + $description = $config['description'] ?? ''; + $redirect_url = $config['redirect_url'] ?? ''; $simple_redirect_tasks[] = $simple_redirect_task_factory->create_task( $id, $title, $description, $redirect_url ); } @@ -2247,14 +2273,33 @@ static function ( ContainerInterface $container ): DisplayManager { $container->get( 'woocommerce.logger.woocommerce' ) ); }, - 'wcgateway.settings.admin-settings-enabled' => static function ( ContainerInterface $container ): bool { return $container->has( 'settings.url' ) && ! SettingsModule::should_use_the_old_ui(); }, + 'wcgateway.installments.eligibility.check' => static function ( ContainerInterface $container ): callable { + /** + * Decides, whether the current merchant is eligible to use the + * "Installments" feature on this site. + */ + return static function () use ( $container ) { + return 'MX' === $container->get( 'settings.data.general' )->get_merchant_country(); + }; + }, + 'wcgateway.alternative_payment_methods.eligibility.check' => static function ( ContainerInterface $container ): callable { + /** + * Decides, whether the current merchant is eligible to use the + * "Alternative Payment Methods" feature on this site. + */ + return static function () use ( $container ) { + $merchant_country = $container->get( 'api.shop.country' ); + $ineligible_countries = array( 'RU', 'BR', 'JP' ); + return ! in_array( $merchant_country, $ineligible_countries, true ); + }; + }, 'wcgateway.contact-module.eligibility.check' => static function ( ContainerInterface $container ): callable { $feature_enabled = (bool) apply_filters( - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- feature flags use this convention + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- feature flags use this convention 'woocommerce.feature-flags.woocommerce_paypal_payments.contact_module_enabled', getenv( 'PCP_CONTACT_MODULE_ENABLED' ) !== '0' ); @@ -2268,10 +2313,12 @@ static function ( ContainerInterface $container ): DisplayManager { return false; } - $details = $container->get( 'settings.merchant-details' ); - assert( $details instanceof MerchantDetails ); + $data = $container->get( 'settings.data.general' ); + assert( $data instanceof GeneralSettings ); + + $merchant_country = $data->get_merchant_country(); - $enable_contact_module = 'US' === $details->get_merchant_country(); + $enable_contact_module = 'US' === $merchant_country; /** * The contact module is enabled for US-based merchants by default. @@ -2285,19 +2332,28 @@ static function ( ContainerInterface $container ): DisplayManager { }, /** - * Returns a centralized list of feature eligibility checks. + * Returns a centralized list of feature eligibility checks either for onboarding or for connected merchant. * * This is a helper service which is used by the `MerchantDetails` class and * should not be directly accessed. */ 'wcgateway.feature-eligibility.list' => static function ( ContainerInterface $container ): array { - return array( - MerchantDetails::FEATURE_SAVE_PAYPAL_VENMO => $container->get( 'save-payment-methods.eligibility.check' ), - MerchantDetails::FEATURE_ADVANCED_CARD_PROCESSING => $container->get( 'card-fields.eligibility.check' ), - MerchantDetails::FEATURE_GOOGLE_PAY => $container->get( 'googlepay.eligibility.check' ), - MerchantDetails::FEATURE_APPLE_PAY => $container->get( 'applepay.eligibility.check' ), - MerchantDetails::FEATURE_CONTACT_MODULE => $container->get( 'wcgateway.contact-module.eligibility.check' ), - ); + $connection_state = $container->get( 'settings.connection-state' ); + assert( $connection_state instanceof ConnectionState ); + + if ( $connection_state->is_connected() ) { + return $container->get( 'settings.service.merchant_capabilities' ); + } else { + return array( + MerchantDetails::FEATURE_SAVE_PAYPAL_VENMO => $container->get( 'save-payment-methods.eligibility.check' ), + MerchantDetails::FEATURE_ADVANCED_CARD_PROCESSING => $container->get( 'card-fields.eligibility.check' ), + MerchantDetails::FEATURE_GOOGLE_PAY => $container->get( 'googlepay.eligibility.check' ), + MerchantDetails::FEATURE_APPLE_PAY => $container->get( 'applepay.eligibility.check' ), + MerchantDetails::FEATURE_CONTACT_MODULE => $container->get( 'wcgateway.contact-module.eligibility.check' ), + MerchantDetails::FEATURE_ALTERNATIVE_PAYMENT_METHODS => $container->get( 'wcgateway.alternative_payment_methods.eligibility.check' ), + MerchantDetails::FEATURE_INSTALLMENTS => $container->get( 'wcgateway.installments.eligibility.check' ), + ); + } }, /** @@ -2317,7 +2373,7 @@ static function ( ContainerInterface $container ): DisplayManager { */ 'wcgateway.settings.invoice-prefix-random' => static function ( ContainerInterface $container ): string { $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $prefix = ''; + $prefix = ''; for ( $i = 0; $i < 6; $i++ ) { $prefix .= $characters[ wp_rand( 0, strlen( $characters ) - 1 ) ]; } @@ -2369,7 +2425,7 @@ static function ( ContainerInterface $container ): DisplayManager { 'wcgateway.server-side-shipping-callback-enabled' => static function ( ContainerInterface $container ): bool { return apply_filters( - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 'woocommerce.feature-flags.woocommerce_paypal_payments.server_side_shipping_callback_enabled', getenv( 'PCP_SERVER_SIDE_SHIPPING_CALLBACK_ENABLED' ) !== '0' ); @@ -2377,7 +2433,7 @@ static function ( ContainerInterface $container ): DisplayManager { 'wcgateway.appswitch-enabled' => static function ( ContainerInterface $container ): bool { return apply_filters( - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 'woocommerce.feature-flags.woocommerce_paypal_payments.appswitch_enabled', getenv( 'PCP_APPSWITCH_ENABLED' ) !== '0' ); diff --git a/modules/ppcp-wc-gateway/src/Helper/MerchantDetails.php b/modules/ppcp-wc-gateway/src/Helper/MerchantDetails.php index 45dab634a3..742b2a77f9 100644 --- a/modules/ppcp-wc-gateway/src/Helper/MerchantDetails.php +++ b/modules/ppcp-wc-gateway/src/Helper/MerchantDetails.php @@ -41,6 +41,16 @@ class MerchantDetails { */ public const FEATURE_CONTACT_MODULE = 'contact_module'; + /** + * Whether Alternative Payment Methods can be used by the merchant. + */ + public const FEATURE_ALTERNATIVE_PAYMENT_METHODS = 'alternative_payment_methods'; + + /** + * Whether Installments Methods can be used by the merchant. + */ + public const FEATURE_INSTALLMENTS = 'installments'; + /** * The merchant's country according to PayPal, which might be different from * the WooCommerce country. @@ -51,13 +61,6 @@ class MerchantDetails { */ private string $merchant_country; - /** - * The WooCommerce store country. - * - * @var string - */ - private string $store_country; - /** * A collection of feature eligibility checks. The value can be either a * boolean (static eligibility) or a callback that returns a boolean (lazy check). @@ -69,15 +72,12 @@ class MerchantDetails { /** * Constructor. * - * @param string $merchant_country Merchant country provided by PayPal's API. Not editable. - * @param string $store_country WooCommerce store country, can be changed by the site - * admin via the WooCommerce settings. + * @param string $merchant_country Merchant country either provided by WC store country or by PayPal's API. * @param array $eligibility_checks Array of eligibility checks. Default service: * 'wcgateway.feature-eligibility.list'. */ - public function __construct( string $merchant_country, string $store_country, array $eligibility_checks ) { + public function __construct( string $merchant_country, array $eligibility_checks ) { $this->merchant_country = $merchant_country; - $this->store_country = $store_country; $this->eligibility_checks = $eligibility_checks; } @@ -94,16 +94,6 @@ public function get_merchant_country(): string { return $this->merchant_country; } - /** - * The WooCommerce store's country, which could be different from the - * merchant's country in some cases. This country is used by WooCommerce. - * - * @return string - */ - public function get_shop_country(): string { - return $this->store_country; - } - /** * Tests, if the merchant is eligible to use a certain feature. * Feature checks are reliable _after_ the "plugins_loaded" action finished. diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 67f31ec484..c1efaad6f2 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -23,6 +23,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\LocalApmProductStatus; +use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings; use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule; use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule; use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait; @@ -543,13 +544,16 @@ static function ( array $features ) use ( $c ): array { return $features; } + $data = $c->get( 'settings.data.general' ); + assert( $data instanceof GeneralSettings ); + $merchant_country = $data->get_merchant_country(); + $reference_transaction_status = $c->get( 'api.reference-transaction-status' ); assert( $reference_transaction_status instanceof ReferenceTransactionStatus ); $dcc_product_status = $c->get( 'wcgateway.helper.dcc-product-status' ); assert( $dcc_product_status instanceof DCCProductStatus ); - $dcc_applies = $c->get( 'api.helpers.dccapplies' ); $apms_product_status = $c->get( 'ppcp-local-apms.product-status' ); assert( $apms_product_status instanceof LocalApmProductStatus ); @@ -564,6 +568,9 @@ static function ( array $features ) use ( $c ): array { 'enabled' => $reference_transaction_status->reference_transaction_enabled(), ); + $dcc_applies = $c->get( 'api.helpers.dccapplies' ); + assert( $dcc_applies instanceof DccApplies ); + $features['advanced_credit_and_debit_cards'] = array( 'enabled' => $dcc_product_status->is_active() && $dcc_applies->for_country_currency(), ); @@ -573,10 +580,13 @@ static function ( array $features ) use ( $c ): array { ); // When local APMs are available, then PayLater messaging is also available. - $features['pay_later_messaging'] = $features['alternative_payment_methods']; + $features['pay_later_messaging'] = array( + 'enabled' => $apms_product_status->is_active(), + ); + // Even if installments can be ACTIVE in SellerStatus (PayPal) we are using it only in MX for now. $features['installments'] = array( - 'enabled' => $installments_product_status->is_active(), + 'enabled' => $installments_product_status->is_active() && $merchant_country === 'MX', ); $features['contact_module'] = array(