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
|
|
|
|
2021-02-17 14:35:37 +01:00
|
|
|
use Psr\Container\ContainerInterface;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\ConnectBearer;
|
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
2020-09-24 10:29:09 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\LoginSeller;
|
2020-09-24 09:58:28 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnerReferrals;
|
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;
|
2022-01-14 14:02:33 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
|
2021-09-13 16:28:47 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\OnboardingRESTController;
|
2020-06-15 11:48:37 +03:00
|
|
|
|
2020-08-31 09:37:15 +03:00
|
|
|
return array(
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.sandbox-host' => static function ( ContainerInterface $container ): string {
|
2020-08-31 09:37:15 +03:00
|
|
|
|
|
|
|
$state = $container->get( 'onboarding.state' );
|
|
|
|
|
|
|
|
/**
|
2020-10-01 08:53:44 +03:00
|
|
|
* The State object.
|
2020-08-31 09:37:15 +03:00
|
|
|
*
|
|
|
|
* @var State $state
|
|
|
|
*/
|
|
|
|
if ( $state->current_state() >= State::STATE_ONBOARDED ) {
|
2020-10-01 08:53:44 +03:00
|
|
|
return PAYPAL_SANDBOX_API_URL;
|
2020-08-31 09:37:15 +03:00
|
|
|
}
|
2020-10-01 08:53:44 +03:00
|
|
|
return CONNECT_WOO_SANDBOX_URL;
|
2020-09-24 08:41:08 +03:00
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.production-host' => static function ( ContainerInterface $container ): string {
|
2020-08-31 09:37:15 +03:00
|
|
|
|
2020-09-24 08:41:08 +03:00
|
|
|
$state = $container->get( 'onboarding.state' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Environment and State variables.
|
|
|
|
*
|
|
|
|
* @var Environment $environment
|
|
|
|
* @var State $state
|
|
|
|
*/
|
|
|
|
if ( $state->current_state() >= State::STATE_ONBOARDED ) {
|
2020-10-01 08:53:44 +03:00
|
|
|
return PAYPAL_API_URL;
|
2020-08-31 09:37:15 +03:00
|
|
|
}
|
2020-10-01 08:53:44 +03:00
|
|
|
return CONNECT_WOO_URL;
|
2020-09-24 08:41:08 +03:00
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.host' => static function ( ContainerInterface $container ): string {
|
2020-09-24 08:41:08 +03:00
|
|
|
$environment = $container->get( 'onboarding.environment' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Environment and State variables.
|
|
|
|
*
|
|
|
|
* @var Environment $environment
|
|
|
|
*/
|
|
|
|
return $environment->current_environment_is( Environment::SANDBOX )
|
2020-09-24 09:58:28 +03:00
|
|
|
? (string) $container->get( 'api.sandbox-host' ) : (string) $container->get( 'api.production-host' );
|
2020-08-31 09:37:15 +03:00
|
|
|
|
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.paypal-host-production' => static function( ContainerInterface $container ) : string {
|
2020-10-01 08:53:44 +03:00
|
|
|
return PAYPAL_API_URL;
|
2020-09-24 10:29:09 +03:00
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.paypal-host-sandbox' => static function( ContainerInterface $container ) : string {
|
2020-10-01 08:53:44 +03:00
|
|
|
return PAYPAL_SANDBOX_API_URL;
|
2020-09-24 10:29:09 +03:00
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.partner_merchant_id-production' => static function( ContainerInterface $container ) : string {
|
2020-10-13 09:42:34 +03:00
|
|
|
return CONNECT_WOO_MERCHANT_ID;
|
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.partner_merchant_id-sandbox' => static function( ContainerInterface $container ) : string {
|
2020-10-13 09:42:34 +03:00
|
|
|
return CONNECT_WOO_SANDBOX_MERCHANT_ID;
|
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.paypal-host' => function( ContainerInterface $container ) : string {
|
2020-08-31 09:37:15 +03:00
|
|
|
$environment = $container->get( 'onboarding.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' );
|
|
|
|
|
2020-08-31 09:37:15 +03:00
|
|
|
},
|
|
|
|
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.bearer' => static function ( ContainerInterface $container ): Bearer {
|
2020-08-31 09:37:15 +03:00
|
|
|
|
|
|
|
$state = $container->get( 'onboarding.state' );
|
2020-08-31 12:39:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The State.
|
|
|
|
*
|
|
|
|
* @var State $state
|
|
|
|
*/
|
|
|
|
if ( $state->current_state() < State::STATE_ONBOARDED ) {
|
2020-08-31 09:37:15 +03:00
|
|
|
return new ConnectBearer();
|
|
|
|
}
|
2020-09-11 14:24:08 +03:00
|
|
|
$cache = new Cache( 'ppcp-paypal-bearer' );
|
2020-09-11 13:38:02 +03:00
|
|
|
$key = $container->get( 'api.key' );
|
|
|
|
$secret = $container->get( 'api.secret' );
|
2020-08-31 09:37:15 +03:00
|
|
|
$host = $container->get( 'api.host' );
|
|
|
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
2021-07-27 14:29:05 +02:00
|
|
|
$settings = $container->get( 'wcgateway.settings' );
|
2020-08-31 09:37:15 +03:00
|
|
|
return new PayPalBearer(
|
2020-09-11 13:38:02 +03:00
|
|
|
$cache,
|
2020-08-31 09:37:15 +03:00
|
|
|
$host,
|
|
|
|
$key,
|
|
|
|
$secret,
|
2021-07-26 16:08:32 +02:00
|
|
|
$logger,
|
2021-07-27 14:29:05 +02:00
|
|
|
$settings
|
2020-08-31 09:37:15 +03:00
|
|
|
);
|
|
|
|
},
|
2021-02-17 14:35:37 +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
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'onboarding.environment' => function( ContainerInterface $container ) : Environment {
|
2020-08-31 09:37:15 +03:00
|
|
|
$settings = $container->get( 'wcgateway.settings' );
|
|
|
|
return new Environment( $settings );
|
|
|
|
},
|
|
|
|
|
2021-02-17 14:35:37 +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' ),
|
|
|
|
$state,
|
2022-02-08 10:25:01 +02:00
|
|
|
$container->get( 'onboarding.environment' ),
|
2020-08-31 09:37:15 +03:00
|
|
|
$login_seller_endpoint
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2021-02-17 14:35:37 +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
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.endpoint.login-seller-production' => static function ( ContainerInterface $container ) : LoginSeller {
|
2020-09-24 10:29:09 +03:00
|
|
|
|
|
|
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
|
|
|
return new LoginSeller(
|
|
|
|
$container->get( 'api.paypal-host-production' ),
|
2020-10-13 09:42:34 +03:00
|
|
|
$container->get( 'api.partner_merchant_id-production' ),
|
2020-09-24 10:29:09 +03:00
|
|
|
$logger
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.endpoint.login-seller-sandbox' => static function ( ContainerInterface $container ) : LoginSeller {
|
2020-09-24 10:29:09 +03:00
|
|
|
|
|
|
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
|
|
|
return new LoginSeller(
|
|
|
|
$container->get( 'api.paypal-host-sandbox' ),
|
2020-10-13 09:42:34 +03:00
|
|
|
$container->get( 'api.partner_merchant_id-sandbox' ),
|
2020-09-24 10:29:09 +03:00
|
|
|
$logger
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2021-02-17 14:35:37 +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' );
|
2021-09-23 17:19:46 +03:00
|
|
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
2020-08-31 09:37:15 +03:00
|
|
|
|
2020-09-16 10:00:28 +03:00
|
|
|
$cache = new Cache( 'ppcp-paypal-bearer' );
|
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,
|
|
|
|
$logger
|
2020-08-31 09:37:15 +03:00
|
|
|
);
|
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.endpoint.partner-referrals-sandbox' => static function ( ContainerInterface $container ) : PartnerReferrals {
|
2020-09-25 10:09:35 +03:00
|
|
|
|
2020-09-24 09:58:28 +03:00
|
|
|
return new PartnerReferrals(
|
2020-10-01 08:53:44 +03:00
|
|
|
CONNECT_WOO_SANDBOX_URL,
|
2020-09-25 10:09:35 +03:00
|
|
|
new ConnectBearer(),
|
2020-09-24 09:58:28 +03:00
|
|
|
$container->get( 'woocommerce.logger.woocommerce' )
|
|
|
|
);
|
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'api.endpoint.partner-referrals-production' => static function ( ContainerInterface $container ) : PartnerReferrals {
|
2020-10-01 08:53:44 +03:00
|
|
|
|
2020-09-24 09:58:28 +03:00
|
|
|
return new PartnerReferrals(
|
2020-10-13 09:42:34 +03:00
|
|
|
CONNECT_WOO_URL,
|
2020-09-25 10:09:35 +03:00
|
|
|
new ConnectBearer(),
|
2020-09-24 09:58:28 +03:00
|
|
|
$container->get( 'woocommerce.logger.woocommerce' )
|
|
|
|
);
|
|
|
|
},
|
2021-02-17 14:35:37 +01:00
|
|
|
'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
|
2020-08-31 09:37:15 +03:00
|
|
|
|
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' );
|
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,
|
|
|
|
$partner_referrals_data
|
2020-08-31 09:37:15 +03:00
|
|
|
);
|
|
|
|
},
|
2022-01-14 14:02:33 +02:00
|
|
|
'onboarding.render-options' => static function ( ContainerInterface $container ) : OnboardingOptionsRenderer {
|
|
|
|
return new OnboardingOptionsRenderer();
|
|
|
|
},
|
2021-09-13 16:28:47 +02:00
|
|
|
'onboarding.rest' => static function( $container ) : OnboardingRESTController {
|
|
|
|
return new OnboardingRESTController( $container );
|
2021-01-27 14:56:42 -05:00
|
|
|
},
|
2020-08-31 09:37:15 +03:00
|
|
|
);
|