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

219 lines
7.6 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 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;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\LoginSeller;
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;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
use WooCommerce\PayPalCommerce\Onboarding\OnboardingRESTController;
2020-06-15 11:48:37 +03:00
return array(
'api.sandbox-host' => static function ( ContainerInterface $container ): string {
$state = $container->get( 'onboarding.state' );
/**
2020-10-01 08:53:44 +03:00
* The State object.
*
* @var State $state
*/
if ( $state->current_state() >= State::STATE_ONBOARDED ) {
2020-10-01 08:53:44 +03:00
return PAYPAL_SANDBOX_API_URL;
}
2020-10-01 08:53:44 +03:00
return CONNECT_WOO_SANDBOX_URL;
},
'api.production-host' => static function ( ContainerInterface $container ): string {
$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-10-01 08:53:44 +03:00
return CONNECT_WOO_URL;
},
'api.host' => static function ( ContainerInterface $container ): string {
$environment = $container->get( 'onboarding.environment' );
/**
* The Environment and State variables.
*
* @var Environment $environment
*/
return $environment->current_environment_is( Environment::SANDBOX )
? (string) $container->get( 'api.sandbox-host' ) : (string) $container->get( 'api.production-host' );
},
'api.paypal-host-production' => static function( ContainerInterface $container ) : string {
2020-10-01 08:53:44 +03:00
return PAYPAL_API_URL;
},
'api.paypal-host-sandbox' => static function( ContainerInterface $container ) : string {
2020-10-01 08:53:44 +03:00
return PAYPAL_SANDBOX_API_URL;
},
'api.partner_merchant_id-production' => static function( ContainerInterface $container ) : string {
return CONNECT_WOO_MERCHANT_ID;
},
'api.partner_merchant_id-sandbox' => static function( ContainerInterface $container ) : string {
return CONNECT_WOO_SANDBOX_MERCHANT_ID;
},
'api.paypal-host' => function( ContainerInterface $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 $container->get( 'api.paypal-host-sandbox' );
}
return $container->get( 'api.paypal-host-production' );
},
'api.bearer' => static function ( ContainerInterface $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 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' );
$host = $container->get( 'api.host' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
2021-07-27 14:29:05 +02:00
$settings = $container->get( 'wcgateway.settings' );
return new PayPalBearer(
2020-09-11 13:38:02 +03:00
$cache,
$host,
$key,
$secret,
$logger,
2021-07-27 14:29:05 +02:00
$settings
);
},
'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 {
$settings = $container->get( 'wcgateway.settings' );
return new Environment( $settings );
},
'onboarding.assets' => function( ContainerInterface $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
);
},
'onboarding.url' => static function ( ContainerInterface $container ): string {
return plugins_url(
'/modules/ppcp-onboarding/',
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php'
);
},
'api.endpoint.login-seller-production' => static function ( ContainerInterface $container ) : LoginSeller {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new LoginSeller(
$container->get( 'api.paypal-host-production' ),
$container->get( 'api.partner_merchant_id-production' ),
$logger
);
},
'api.endpoint.login-seller-sandbox' => static function ( ContainerInterface $container ) : LoginSeller {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new LoginSeller(
$container->get( 'api.paypal-host-sandbox' ),
$container->get( 'api.partner_merchant_id-sandbox' ),
$logger
);
},
'onboarding.endpoint.login-seller' => static function ( ContainerInterface $container ) : LoginSellerEndpoint {
$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' );
$cache = new Cache( 'ppcp-paypal-bearer' );
return new LoginSellerEndpoint(
$request_data,
$login_seller_production,
$login_seller_sandbox,
$partner_referrals_data,
$settings,
2021-09-23 17:19:46 +03:00
$cache,
$logger
);
},
'api.endpoint.partner-referrals-sandbox' => static function ( ContainerInterface $container ) : PartnerReferrals {
return new PartnerReferrals(
2020-10-01 08:53:44 +03:00
CONNECT_WOO_SANDBOX_URL,
new ConnectBearer(),
$container->get( 'api.repository.partner-referrals-data' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'api.endpoint.partner-referrals-production' => static function ( ContainerInterface $container ) : PartnerReferrals {
2020-10-01 08:53:44 +03:00
return new PartnerReferrals(
CONNECT_WOO_URL,
new ConnectBearer(),
$container->get( 'api.repository.partner-referrals-data' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
$partner_referrals = $container->get( 'api.endpoint.partner-referrals-production' );
$partner_referrals_sandbox = $container->get( 'api.endpoint.partner-referrals-sandbox' );
$settings = $container->get( 'wcgateway.settings' );
return new OnboardingRenderer(
$settings,
$partner_referrals,
$partner_referrals_sandbox
);
},
'onboarding.rest' => static function( $container ) : OnboardingRESTController {
return new OnboardingRESTController( $container );
},
);