2024-10-18 17:17:07 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The Settings module services.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\PayPalCommerce\Settings
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare( strict_types = 1 );
|
|
|
|
|
|
|
|
namespace WooCommerce\PayPalCommerce\Settings;
|
|
|
|
|
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
2024-10-22 15:14:46 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint;
|
2024-10-22 18:53:24 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
|
2024-10-18 17:17:07 +02:00
|
|
|
|
|
|
|
return array(
|
2024-10-31 16:17:15 +01:00
|
|
|
'settings.url' => static function ( ContainerInterface $container ) : string {
|
2024-10-18 17:17:07 +02:00
|
|
|
/**
|
|
|
|
* The path cannot be false.
|
|
|
|
*
|
|
|
|
* @psalm-suppress PossiblyFalseArgument
|
|
|
|
*/
|
|
|
|
return plugins_url(
|
|
|
|
'/modules/ppcp-settings/',
|
|
|
|
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
|
|
|
);
|
|
|
|
},
|
2024-10-31 16:17:15 +01:00
|
|
|
'settings.data.onboarding' => static function ( ContainerInterface $container ) : OnboardingProfile {
|
|
|
|
$can_use_casual_selling = $container->get( 'settings.casual-selling.eligible' );
|
2024-10-25 13:02:22 +02:00
|
|
|
$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.
|
2024-10-31 16:17:15 +01:00
|
|
|
// TODO: Move this condition to the card-fields.eligible service?
|
2024-10-25 13:02:22 +02:00
|
|
|
if ( class_exists( '\WC_Payments' ) ) {
|
|
|
|
$can_use_card_payments = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new OnboardingProfile(
|
|
|
|
$can_use_casual_selling,
|
|
|
|
$can_use_vaulting,
|
|
|
|
$can_use_card_payments
|
|
|
|
);
|
2024-10-22 18:53:24 +02:00
|
|
|
},
|
2024-10-31 16:17:15 +01:00
|
|
|
'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint {
|
2024-10-22 18:53:24 +02:00
|
|
|
return new OnboardingRestEndpoint( $container->get( 'settings.data.onboarding' ) );
|
2024-10-22 15:14:46 +02:00
|
|
|
},
|
2024-10-31 16:17:15 +01:00
|
|
|
'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 );
|
|
|
|
},
|
2024-10-18 17:17:07 +02:00
|
|
|
);
|