2020-06-15 11:48:37 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Inpsyde\PayPalCommerce\Onboarding;
|
|
|
|
|
|
|
|
use Dhii\Data\Container\ContainerInterface;
|
2020-06-29 12:17:09 +03:00
|
|
|
use Inpsyde\PayPalCommerce\ApiClient\Authentication\Bearer;
|
|
|
|
use Inpsyde\PayPalCommerce\ApiClient\Authentication\ConnectBearer;
|
|
|
|
use Inpsyde\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
2020-06-15 11:48:37 +03:00
|
|
|
use Inpsyde\PayPalCommerce\Onboarding\Assets\OnboardingAssets;
|
|
|
|
use Inpsyde\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
|
|
|
|
use Inpsyde\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
|
2020-06-29 12:17:09 +03:00
|
|
|
use WpOop\TransientCache\CachePoolFactory;
|
2020-06-15 11:48:37 +03:00
|
|
|
|
|
|
|
return [
|
|
|
|
|
2020-06-15 11:53:59 +03:00
|
|
|
'api.host' => static function (ContainerInterface $container): string {
|
|
|
|
$state = $container->get('onboarding.state');
|
|
|
|
$environment = $container->get('onboarding.environment');
|
|
|
|
|
|
|
|
//ToDo: Correct the URLs
|
|
|
|
/**
|
|
|
|
* @var Environment $environment
|
|
|
|
* @var State $state
|
|
|
|
*/
|
|
|
|
if ($state->currentState() >= State::STATE_ONBOARDED) {
|
|
|
|
if ($environment->currentEnvironmentIs(Environment::SANDBOX)) {
|
|
|
|
return 'https://api.sandbox.paypal.com';
|
|
|
|
}
|
|
|
|
return 'https://api.sandbox.paypal.com';
|
|
|
|
}
|
|
|
|
|
2020-06-29 12:17:09 +03:00
|
|
|
//ToDo: Real connect.woocommerce.com
|
2020-06-15 11:53:59 +03:00
|
|
|
if ($environment->currentEnvironmentIs(Environment::SANDBOX)) {
|
2020-06-29 12:17:09 +03:00
|
|
|
return 'http://connect-woo.wpcust.com';
|
|
|
|
}
|
|
|
|
return 'http://connect-woo.wpcust.com';
|
|
|
|
|
|
|
|
},
|
2020-06-29 12:28:25 +03:00
|
|
|
'api.paypal-host' => function(ContainerInterface $container) : string {
|
|
|
|
$environment = $container->get('onboarding.environment');
|
|
|
|
if ($environment->currentEnvironmentIs(Environment::SANDBOX)) {
|
|
|
|
return 'https://api.sandbox.paypal.com';
|
|
|
|
}
|
|
|
|
return 'https://api.paypal.com';
|
|
|
|
},
|
2020-06-29 12:17:09 +03:00
|
|
|
|
|
|
|
'api.bearer' => static function (ContainerInterface $container): Bearer {
|
|
|
|
|
|
|
|
$state = $container->get('onboarding.state');
|
|
|
|
if ($state->currentState() < State::STATE_ONBOARDED) {
|
|
|
|
return new ConnectBearer();
|
2020-06-15 11:53:59 +03:00
|
|
|
}
|
2020-06-29 12:17:09 +03:00
|
|
|
global $wpdb;
|
|
|
|
$cacheFactory = new CachePoolFactory($wpdb);
|
|
|
|
$pool = $cacheFactory->createCachePool('ppcp-token');
|
|
|
|
$key = $container->get('api.key');
|
|
|
|
$secret = $container->get('api.secret');
|
2020-06-15 11:53:59 +03:00
|
|
|
|
2020-06-29 12:17:09 +03:00
|
|
|
$host = $container->get('api.host');
|
2020-07-01 13:50:52 +03:00
|
|
|
$logger = $container->get('woocommerce.logger.woocommerce');
|
2020-06-29 12:17:09 +03:00
|
|
|
return new PayPalBearer(
|
|
|
|
$pool,
|
|
|
|
$host,
|
|
|
|
$key,
|
2020-07-01 13:50:52 +03:00
|
|
|
$secret,
|
|
|
|
$logger
|
2020-06-29 12:17:09 +03:00
|
|
|
);
|
2020-06-15 11:53:59 +03:00
|
|
|
},
|
2020-06-15 11:48:37 +03:00
|
|
|
'onboarding.state' => function(ContainerInterface $container) : State {
|
|
|
|
$environment = $container->get('onboarding.environment');
|
|
|
|
$settings = $container->get('wcgateway.settings');
|
|
|
|
return new State($environment, $settings);
|
|
|
|
},
|
|
|
|
'onboarding.environment' => function(ContainerInterface $container) : Environment {
|
2020-06-30 07:49:25 +03:00
|
|
|
$settings = $container->get('wcgateway.settings');
|
|
|
|
return new Environment($settings);
|
2020-06-15 11:48:37 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
'onboarding.assets' => function(ContainerInterface $container) : OnboardingAssets {
|
|
|
|
$state = $container->get('onboarding.state');
|
|
|
|
$loginSellerEndpoint = $container->get('onboarding.endpoint.login-seller');
|
|
|
|
return new OnboardingAssets(
|
|
|
|
$container->get('onboarding.url'),
|
|
|
|
$state,
|
|
|
|
$loginSellerEndpoint
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
'onboarding.url' => static function (ContainerInterface $container): string {
|
|
|
|
return plugins_url(
|
2020-06-29 11:26:18 +03:00
|
|
|
'/modules.local/ppcp-onboarding/',
|
2020-06-15 11:48:37 +03:00
|
|
|
dirname(__FILE__, 3) . '/woocommerce-paypal-commerce-gateway.php'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
'onboarding.endpoint.login-seller' => static function (ContainerInterface $container) : LoginSellerEndpoint {
|
|
|
|
|
|
|
|
$requestData = $container->get('button.request-data');
|
|
|
|
$loginSellerEndpoint = $container->get('api.endpoint.login-seller');
|
|
|
|
$partnerReferralsData = $container->get('api.repository.partner-referrals-data');
|
2020-07-02 13:02:23 +03:00
|
|
|
$settings = $container->get('wcgateway.settings');
|
2020-07-09 10:28:38 +03:00
|
|
|
|
|
|
|
global $wpdb;
|
|
|
|
$cacheFactory = new CachePoolFactory($wpdb);
|
|
|
|
$pool = $cacheFactory->createCachePool('ppcp-token');
|
2020-06-15 11:48:37 +03:00
|
|
|
return new LoginSellerEndpoint(
|
|
|
|
$requestData,
|
|
|
|
$loginSellerEndpoint,
|
|
|
|
$partnerReferralsData,
|
2020-07-09 10:28:38 +03:00
|
|
|
$settings,
|
|
|
|
$pool
|
2020-06-15 11:48:37 +03:00
|
|
|
);
|
|
|
|
},
|
|
|
|
'onboarding.render' => static function (ContainerInterface $container) : OnboardingRenderer {
|
|
|
|
|
|
|
|
$partnerReferrals = $container->get('api.endpoint.partner-referrals');
|
|
|
|
return new OnboardingRenderer(
|
|
|
|
$partnerReferrals,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
];
|