2020-06-15 11:48:37 +03:00
|
|
|
<?php
|
2020-08-31 09:37:15 +03:00
|
|
|
/**
|
|
|
|
* The onboarding module services.
|
|
|
|
*
|
2020-09-11 14:11:10 +03:00
|
|
|
* @package WooCommerce\PayPalCommerce\Onboarding
|
2020-08-31 09:37:15 +03:00
|
|
|
*/
|
2020-06-15 11:48:37 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-11 14:11:10 +03:00
|
|
|
namespace WooCommerce\PayPalCommerce\Onboarding;
|
2020-06-15 11:48:37 +03:00
|
|
|
|
2024-10-21 11:57:45 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
|
2022-11-09 10:11:31 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\Assets\OnboardingAssets;
|
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
|
2023-09-26 13:58:33 +01:00
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\UpdateSignupLinksEndpoint;
|
2024-10-21 11:57:45 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingSendOnlyNoticeRenderer;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
|
2025-02-03 13:39:16 +01:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
2025-02-17 18:43:56 +01:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
2025-03-14 15:14:12 +01:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\ConnectionState;
|
|
|
|
use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings;
|
2025-06-10 18:45:09 +02:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\MerchantDetails;
|
2020-06-15 11:48:37 +03:00
|
|
|
|
2020-08-31 09:37:15 +03:00
|
|
|
return array(
|
2025-01-17 13:59:17 +01:00
|
|
|
'api.paypal-host' => function( ContainerInterface $container ) : string {
|
2025-02-17 18:48:38 +01:00
|
|
|
$environment = $container->get( 'settings.environment' );
|
2020-08-31 12:38:29 +03:00
|
|
|
/**
|
|
|
|
* The current environment.
|
|
|
|
*
|
|
|
|
* @var Environment $environment
|
|
|
|
*/
|
|
|
|
if ( $environment->current_environment_is( Environment::SANDBOX ) ) {
|
2020-09-24 10:29:09 +03:00
|
|
|
return $container->get( 'api.paypal-host-sandbox' );
|
2020-08-31 09:37:15 +03:00
|
|
|
}
|
2020-09-24 10:29:09 +03:00
|
|
|
return $container->get( 'api.paypal-host-production' );
|
|
|
|
|
2023-11-14 10:50:56 +02:00
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'api.paypal-website-url' => function( ContainerInterface $container ) : string {
|
2025-02-17 18:48:38 +01:00
|
|
|
$environment = $container->get( 'settings.environment' );
|
2023-11-14 10:50:56 +02:00
|
|
|
assert( $environment instanceof Environment );
|
|
|
|
if ( $environment->current_environment_is( Environment::SANDBOX ) ) {
|
|
|
|
return $container->get( 'api.paypal-website-url-sandbox' );
|
|
|
|
}
|
|
|
|
return $container->get( 'api.paypal-website-url-production' );
|
|
|
|
|
2020-08-31 09:37:15 +03:00
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.state' => function( ContainerInterface $container ) : State {
|
2020-08-31 09:37:15 +03:00
|
|
|
$settings = $container->get( 'wcgateway.settings' );
|
2022-02-08 10:12:38 +02:00
|
|
|
return new State( $settings );
|
2020-08-31 09:37:15 +03:00
|
|
|
},
|
2025-01-30 17:12:50 +01:00
|
|
|
/**
|
2025-03-14 15:14:12 +01:00
|
|
|
* Merchant connection details, which includes the connection status
|
|
|
|
* (onboarding/connected) and connection-aware environment checks.
|
|
|
|
* This is the preferred solution to check environment and connection state.
|
2025-01-30 17:12:50 +01:00
|
|
|
*/
|
2025-03-14 15:14:12 +01:00
|
|
|
'settings.connection-state' => static function ( ContainerInterface $container ) : ConnectionState {
|
2025-01-30 17:12:50 +01:00
|
|
|
$state = $container->get( 'onboarding.state' );
|
|
|
|
assert( $state instanceof State );
|
|
|
|
|
2020-08-31 09:37:15 +03:00
|
|
|
$settings = $container->get( 'wcgateway.settings' );
|
2025-02-17 18:43:56 +01:00
|
|
|
assert( $settings instanceof Settings );
|
|
|
|
|
2025-03-14 15:14:12 +01:00
|
|
|
$is_sandbox = $settings->has( 'sandbox_on' ) && $settings->get( 'sandbox_on' );
|
|
|
|
$is_connected = $state->current_state() >= State::STATE_ONBOARDED;
|
|
|
|
$environment = new Environment( $is_sandbox );
|
|
|
|
|
|
|
|
return new ConnectionState( $is_connected, $environment );
|
|
|
|
},
|
2025-03-14 15:14:41 +01:00
|
|
|
/**
|
|
|
|
* Checks if the onboarding process is completed and the merchant API can be used.
|
|
|
|
* This service only resolves the connection status once per request.
|
|
|
|
*
|
|
|
|
* @deprecated Use 'settings.connection-state' instead.
|
|
|
|
*/
|
2025-03-14 15:14:12 +01:00
|
|
|
'settings.flag.is-connected' => static function ( ContainerInterface $container ) : bool {
|
|
|
|
$state = $container->get( 'settings.connection-state' );
|
|
|
|
assert( $state instanceof ConnectionState );
|
|
|
|
|
|
|
|
return $state->is_connected();
|
|
|
|
},
|
2025-03-14 15:14:41 +01:00
|
|
|
/**
|
|
|
|
* Determines whether the merchant is connected to a sandbox account.
|
|
|
|
* This service only resolves the sandbox flag once per request.
|
|
|
|
*
|
|
|
|
* @deprecated Use 'settings.connection-state' instead.
|
|
|
|
*/
|
2025-03-14 15:14:12 +01:00
|
|
|
'settings.flag.is-sandbox' => static function ( ContainerInterface $container ) : bool {
|
|
|
|
$state = $container->get( 'settings.connection-state' );
|
|
|
|
assert( $state instanceof ConnectionState );
|
|
|
|
|
|
|
|
return $state->is_sandbox();
|
2025-02-17 18:43:56 +01:00
|
|
|
},
|
2025-03-14 15:14:41 +01:00
|
|
|
/**
|
|
|
|
* Returns details about the connected environment (production/sandbox).
|
|
|
|
*
|
|
|
|
* @deprecated Directly use 'settings.connection-state' instead of this.
|
|
|
|
*/
|
2025-02-17 18:48:38 +01:00
|
|
|
'settings.environment' => function ( ContainerInterface $container ) : Environment {
|
2025-03-14 15:14:12 +01:00
|
|
|
$state = $container->get( 'settings.connection-state' );
|
|
|
|
assert( $state instanceof ConnectionState );
|
|
|
|
|
|
|
|
return $state->get_environment();
|
2020-08-31 09:37:15 +03:00
|
|
|
},
|
2025-06-10 18:45:09 +02:00
|
|
|
'settings.merchant-details' => static function ( ContainerInterface $container ) : MerchantDetails {
|
2025-06-11 17:43:46 +02:00
|
|
|
$woo_country = $container->get( 'api.shop.country' );
|
|
|
|
$eligibility_checks = $container->get( 'wcgateway.feature-eligibility.list' );
|
2020-08-31 09:37:15 +03:00
|
|
|
|
2025-06-11 17:43:46 +02:00
|
|
|
return new MerchantDetails( $woo_country, $woo_country, $eligibility_checks );
|
2025-06-10 18:45:09 +02:00
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.assets' => function( ContainerInterface $container ) : OnboardingAssets {
|
2020-08-31 09:37:15 +03:00
|
|
|
$state = $container->get( 'onboarding.state' );
|
|
|
|
$login_seller_endpoint = $container->get( 'onboarding.endpoint.login-seller' );
|
|
|
|
return new OnboardingAssets(
|
|
|
|
$container->get( 'onboarding.url' ),
|
2022-02-17 18:51:24 +02:00
|
|
|
$container->get( 'ppcp.asset-version' ),
|
2020-08-31 09:37:15 +03:00
|
|
|
$state,
|
2025-02-17 18:48:38 +01:00
|
|
|
$container->get( 'settings.environment' ),
|
2022-02-22 09:55:46 +02:00
|
|
|
$login_seller_endpoint,
|
|
|
|
$container->get( 'wcgateway.current-ppcp-settings-page-id' )
|
2020-08-31 09:37:15 +03:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.url' => static function ( ContainerInterface $container ): string {
|
2020-08-31 09:37:15 +03:00
|
|
|
return plugins_url(
|
2020-09-01 14:53:03 +03:00
|
|
|
'/modules/ppcp-onboarding/',
|
2022-01-14 16:35:13 +02:00
|
|
|
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
2020-08-31 09:37:15 +03:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.endpoint.login-seller' => static function ( ContainerInterface $container ) : LoginSellerEndpoint {
|
2020-08-31 09:37:15 +03:00
|
|
|
|
2020-09-24 10:29:09 +03:00
|
|
|
$request_data = $container->get( 'button.request-data' );
|
|
|
|
$login_seller_production = $container->get( 'api.endpoint.login-seller-production' );
|
|
|
|
$login_seller_sandbox = $container->get( 'api.endpoint.login-seller-sandbox' );
|
|
|
|
$partner_referrals_data = $container->get( 'api.repository.partner-referrals-data' );
|
|
|
|
$settings = $container->get( 'wcgateway.settings' );
|
2025-02-03 13:42:26 +01:00
|
|
|
$cache = $container->get( 'api.paypal-bearer-cache' );
|
|
|
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
2020-08-31 09:37:15 +03:00
|
|
|
return new LoginSellerEndpoint(
|
|
|
|
$request_data,
|
2020-09-24 10:29:09 +03:00
|
|
|
$login_seller_production,
|
|
|
|
$login_seller_sandbox,
|
2020-08-31 09:37:15 +03:00
|
|
|
$partner_referrals_data,
|
|
|
|
$settings,
|
2021-09-23 17:19:46 +03:00
|
|
|
$cache,
|
2024-08-06 10:44:54 +02:00
|
|
|
$logger,
|
|
|
|
new Cache( 'ppcp-client-credentials-cache' )
|
2020-08-31 09:37:15 +03:00
|
|
|
);
|
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.endpoint.pui' => static function( ContainerInterface $container ) : UpdateSignupLinksEndpoint {
|
2023-09-26 13:58:33 +01:00
|
|
|
return new UpdateSignupLinksEndpoint(
|
2022-04-11 12:50:05 +02:00
|
|
|
$container->get( 'wcgateway.settings' ),
|
2022-04-14 17:17:56 +02:00
|
|
|
$container->get( 'button.request-data' ),
|
2022-05-27 14:53:55 +02:00
|
|
|
$container->get( 'onboarding.signup-link-cache' ),
|
|
|
|
$container->get( 'onboarding.render' ),
|
|
|
|
$container->get( 'onboarding.signup-link-ids' ),
|
2022-04-14 17:17:56 +02:00
|
|
|
$container->get( 'woocommerce.logger.woocommerce' )
|
2022-04-11 12:50:05 +02:00
|
|
|
);
|
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.signup-link-cache' => static function( ContainerInterface $container ): Cache {
|
2022-05-26 11:29:09 +02:00
|
|
|
return new Cache( 'ppcp-paypal-signup-link' );
|
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.signup-link-ids' => static function ( ContainerInterface $container ): array {
|
2022-05-27 14:53:55 +02:00
|
|
|
return array(
|
|
|
|
'production-ppcp',
|
|
|
|
'production-express_checkout',
|
|
|
|
'sandbox-ppcp',
|
|
|
|
'sandbox-express_checkout',
|
|
|
|
);
|
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.render-send-only-notice' => static function( ContainerInterface $container ) {
|
2024-10-21 11:57:45 +02:00
|
|
|
return new OnboardingSendOnlyNoticeRenderer(
|
|
|
|
$container->get( 'wcgateway.send-only-message' )
|
|
|
|
);
|
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
|
2020-09-24 09:58:28 +03:00
|
|
|
$partner_referrals = $container->get( 'api.endpoint.partner-referrals-production' );
|
|
|
|
$partner_referrals_sandbox = $container->get( 'api.endpoint.partner-referrals-sandbox' );
|
2022-01-14 13:56:52 +02:00
|
|
|
$partner_referrals_data = $container->get( 'api.repository.partner-referrals-data' );
|
2020-09-24 09:58:28 +03:00
|
|
|
$settings = $container->get( 'wcgateway.settings' );
|
2023-07-31 18:20:39 +01:00
|
|
|
$signup_link_cache = $container->get( 'onboarding.signup-link-cache' );
|
|
|
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
2020-08-31 09:37:15 +03:00
|
|
|
return new OnboardingRenderer(
|
2020-09-24 09:58:28 +03:00
|
|
|
$settings,
|
|
|
|
$partner_referrals,
|
2022-01-14 13:56:52 +02:00
|
|
|
$partner_referrals_sandbox,
|
2022-05-25 09:42:37 +02:00
|
|
|
$partner_referrals_data,
|
2023-07-31 18:20:39 +01:00
|
|
|
$signup_link_cache,
|
|
|
|
$logger
|
2020-08-31 09:37:15 +03:00
|
|
|
);
|
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.render-options' => static function ( ContainerInterface $container ) : OnboardingOptionsRenderer {
|
2022-02-22 09:04:25 +02:00
|
|
|
return new OnboardingOptionsRenderer(
|
2022-02-23 11:29:00 +02:00
|
|
|
$container->get( 'onboarding.url' ),
|
2022-04-11 12:50:05 +02:00
|
|
|
$container->get( 'api.shop.country' ),
|
|
|
|
$container->get( 'wcgateway.settings' )
|
2022-02-22 09:04:25 +02:00
|
|
|
);
|
2022-01-14 14:02:33 +02:00
|
|
|
},
|
2025-01-17 13:59:17 +01:00
|
|
|
'onboarding.rest' => static function( $container ) : OnboardingRESTController {
|
2021-09-13 16:28:47 +02:00
|
|
|
return new OnboardingRESTController( $container );
|
2021-01-27 14:56:42 -05:00
|
|
|
},
|
2020-08-31 09:37:15 +03:00
|
|
|
);
|