diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index f34257f79..3620957f9 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -14,7 +14,7 @@ use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile; return array( - 'settings.url' => static function ( ContainerInterface $container ) : string { + 'settings.url' => static function ( ContainerInterface $container ) : string { /** * The path cannot be false. * @@ -25,12 +25,13 @@ return array( dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php' ); }, - 'settings.data.onboarding' => static function ( ContainerInterface $container ) : OnboardingProfile { - $can_use_casual_selling = false; + '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' ); // Card payments are disabled for this plugin when WooPayments is active. + // TODO: Move this condition to the card-fields.eligible service? if ( class_exists( '\WC_Payments' ) ) { $can_use_card_payments = false; } @@ -41,7 +42,26 @@ return array( $can_use_card_payments ); }, - 'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint { + 'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint { return new OnboardingRestEndpoint( $container->get( 'settings.data.onboarding' ) ); }, + 'settings.casual-selling.supported-countries' => static function ( ContainerInterface $container ) : array { + // TODO: This is a dummy list, while we wait for the official eligibility list. + + return array( + 'US', + 'CA', + 'DE', + 'ES', + 'AT', + 'CH', + 'NL', + ); + }, + 'settings.casual-selling.eligible' => static function ( ContainerInterface $container ) : bool { + $country = $container->get( 'api.shop.country' ); + $eligible_countries = $container->get( 'settings.casual-selling.supported-countries' ); + + return in_array( $country, $eligible_countries, true ); + }, );