woocommerce-paypal-payments/modules/ppcp-onboarding/services.php

139 lines
4.2 KiB
PHP
Raw Normal View History

2020-06-15 11:48:37 +03:00
<?php
/**
* The onboarding module services.
*
2020-09-11 14:11:10 +03:00
* @package WooCommerce\PayPalCommerce\Onboarding
*/
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
use Dhii\Data\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;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\Onboarding\Assets\OnboardingAssets;
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
use WpOop\TransientCache\CachePoolFactory;
2020-06-15 11:48:37 +03:00
return array(
2020-09-11 13:38:02 +03:00
'api.host' => static function ( $container ): string {
$state = $container->get( 'onboarding.state' );
$environment = $container->get( 'onboarding.environment' );
// ToDo: Correct the URLs.
/**
* The Environment and State variables.
*
* @var Environment $environment
* @var State $state
*/
if ( $state->current_state() >= State::STATE_ONBOARDED ) {
if ( $environment->current_environment_is( Environment::SANDBOX ) ) {
return 'https://api.sandbox.paypal.com';
}
return 'https://api.sandbox.paypal.com';
}
// ToDo: Real connect.woocommerce.com.
if ( $environment->current_environment_is( Environment::SANDBOX ) ) {
return 'http://connect-woo.wpcust.com';
}
return 'http://connect-woo.wpcust.com';
},
2020-09-11 13:38:02 +03:00
'api.paypal-host' => function( $container ) : string {
$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 ) ) {
return 'https://api.sandbox.paypal.com';
}
return 'https://api.paypal.com';
},
2020-09-11 13:38:02 +03:00
'api.bearer' => static function ( $container ): Bearer {
$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 ) {
return new ConnectBearer();
}
2020-09-11 13:38:02 +03:00
$cache = new Cache('ppcp-paypal-bearer');
$key = $container->get( 'api.key' );
$secret = $container->get( 'api.secret' );
$host = $container->get( 'api.host' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new PayPalBearer(
2020-09-11 13:38:02 +03:00
$cache,
$host,
$key,
$secret,
$logger
);
},
2020-09-11 13:38:02 +03:00
'onboarding.state' => function( $container ) : State {
$environment = $container->get( 'onboarding.environment' );
$settings = $container->get( 'wcgateway.settings' );
return new State( $environment, $settings );
},
2020-09-11 13:38:02 +03:00
'onboarding.environment' => function( $container ) : Environment {
$settings = $container->get( 'wcgateway.settings' );
return new Environment( $settings );
},
2020-09-11 13:38:02 +03:00
'onboarding.assets' => function( $container ) : OnboardingAssets {
$state = $container->get( 'onboarding.state' );
$login_seller_endpoint = $container->get( 'onboarding.endpoint.login-seller' );
return new OnboardingAssets(
$container->get( 'onboarding.url' ),
$state,
$login_seller_endpoint
);
},
2020-09-11 13:38:02 +03:00
'onboarding.url' => static function ( $container ): string {
return plugins_url(
'/modules/ppcp-onboarding/',
dirname( __FILE__, 3 ) . '/woocommerce-paypal-commerce-gateway.php'
);
},
2020-09-11 13:38:02 +03:00
'onboarding.endpoint.login-seller' => static function ( $container ) : LoginSellerEndpoint {
$request_data = $container->get( 'button.request-data' );
$login_seller = $container->get( 'api.endpoint.login-seller' );
$partner_referrals_data = $container->get( 'api.repository.partner-referrals-data' );
$settings = $container->get( 'wcgateway.settings' );
2020-09-11 13:38:02 +03:00
$cache = new Cache('ppcp-token');
return new LoginSellerEndpoint(
$request_data,
$login_seller,
$partner_referrals_data,
$settings,
2020-09-11 13:38:02 +03:00
$cache
);
},
2020-09-11 13:38:02 +03:00
'onboarding.render' => static function ( $container ) : OnboardingRenderer {
$partner_referrals = $container->get( 'api.endpoint.partner-referrals' );
return new OnboardingRenderer(
$partner_referrals
);
},
);