Add Container typehint to all service definitions

This commit is contained in:
Anton Ukhanev 2021-02-17 14:35:37 +01:00
parent 3d39f3b2a9
commit cabcb7d9e4
8 changed files with 101 additions and 94 deletions

View file

@ -9,18 +9,19 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\AdminNotices; namespace WooCommerce\PayPalCommerce\AdminNotices;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\AdminNotices\Renderer\Renderer; use WooCommerce\PayPalCommerce\AdminNotices\Renderer\Renderer;
use WooCommerce\PayPalCommerce\AdminNotices\Renderer\RendererInterface; use WooCommerce\PayPalCommerce\AdminNotices\Renderer\RendererInterface;
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository; use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
use WooCommerce\PayPalCommerce\AdminNotices\Repository\RepositoryInterface; use WooCommerce\PayPalCommerce\AdminNotices\Repository\RepositoryInterface;
return array( return array(
'admin-notices.renderer' => static function ( $container ): RendererInterface { 'admin-notices.renderer' => static function ( ContainerInterface $container ): RendererInterface {
$repository = $container->get( 'admin-notices.repository' ); $repository = $container->get( 'admin-notices.repository' );
return new Renderer( $repository ); return new Renderer( $repository );
}, },
'admin-notices.repository' => static function ( $container ): RepositoryInterface { 'admin-notices.repository' => static function ( ContainerInterface $container ): RepositoryInterface {
return new Repository(); return new Repository();
}, },

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient; namespace WooCommerce\PayPalCommerce\ApiClient;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer; use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer; use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\IdentityToken; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\IdentityToken;
@ -46,10 +47,10 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
return array( return array(
'api.host' => function( $container ) : string { 'api.host' => function( ContainerInterface $container ) : string {
return PAYPAL_API_URL; return PAYPAL_API_URL;
}, },
'api.paypal-host' => function( $container ) : string { 'api.paypal-host' => function( ContainerInterface $container ) : string {
return PAYPAL_API_URL; return PAYPAL_API_URL;
}, },
'api.partner_merchant_id' => static function () : string { 'api.partner_merchant_id' => static function () : string {
@ -70,7 +71,7 @@ return array(
'api.prefix' => static function (): string { 'api.prefix' => static function (): string {
return 'WC-'; return 'WC-';
}, },
'api.bearer' => static function ( $container ): Bearer { 'api.bearer' => static function ( ContainerInterface $container ): Bearer {
$cache = new Cache( 'ppcp-paypal-bearer' ); $cache = new Cache( 'ppcp-paypal-bearer' );
$key = $container->get( 'api.key' ); $key = $container->get( 'api.key' );
@ -86,7 +87,7 @@ return array(
$logger $logger
); );
}, },
'api.endpoint.partners' => static function ( $container ) : PartnersEndpoint { 'api.endpoint.partners' => static function ( ContainerInterface $container ) : PartnersEndpoint {
return new PartnersEndpoint( return new PartnersEndpoint(
$container->get( 'api.host' ), $container->get( 'api.host' ),
$container->get( 'api.bearer' ), $container->get( 'api.bearer' ),
@ -96,10 +97,10 @@ return array(
$container->get( 'api.merchant_id' ) $container->get( 'api.merchant_id' )
); );
}, },
'api.factory.sellerstatus' => static function ( $container ) : SellerStatusFactory { 'api.factory.sellerstatus' => static function ( ContainerInterface $container ) : SellerStatusFactory {
return new SellerStatusFactory(); return new SellerStatusFactory();
}, },
'api.endpoint.payment-token' => static function ( $container ) : PaymentTokenEndpoint { 'api.endpoint.payment-token' => static function ( ContainerInterface $container ) : PaymentTokenEndpoint {
return new PaymentTokenEndpoint( return new PaymentTokenEndpoint(
$container->get( 'api.host' ), $container->get( 'api.host' ),
$container->get( 'api.bearer' ), $container->get( 'api.bearer' ),
@ -108,7 +109,7 @@ return array(
$container->get( 'api.prefix' ) $container->get( 'api.prefix' )
); );
}, },
'api.endpoint.webhook' => static function ( $container ) : WebhookEndpoint { 'api.endpoint.webhook' => static function ( ContainerInterface $container ) : WebhookEndpoint {
return new WebhookEndpoint( return new WebhookEndpoint(
$container->get( 'api.host' ), $container->get( 'api.host' ),
@ -117,7 +118,7 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' ) $container->get( 'woocommerce.logger.woocommerce' )
); );
}, },
'api.endpoint.partner-referrals' => static function ( $container ) : PartnerReferrals { 'api.endpoint.partner-referrals' => static function ( ContainerInterface $container ) : PartnerReferrals {
return new PartnerReferrals( return new PartnerReferrals(
$container->get( 'api.host' ), $container->get( 'api.host' ),
@ -126,7 +127,7 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' ) $container->get( 'woocommerce.logger.woocommerce' )
); );
}, },
'api.endpoint.identity-token' => static function ( $container ) : IdentityToken { 'api.endpoint.identity-token' => static function ( ContainerInterface $container ) : IdentityToken {
$logger = $container->get( 'woocommerce.logger.woocommerce' ); $logger = $container->get( 'woocommerce.logger.woocommerce' );
$prefix = $container->get( 'api.prefix' ); $prefix = $container->get( 'api.prefix' );
@ -137,7 +138,7 @@ return array(
$prefix $prefix
); );
}, },
'api.endpoint.payments' => static function ( $container ): PaymentsEndpoint { 'api.endpoint.payments' => static function ( ContainerInterface $container ): PaymentsEndpoint {
$authorizations_factory = $container->get( 'api.factory.authorization' ); $authorizations_factory = $container->get( 'api.factory.authorization' );
$logger = $container->get( 'woocommerce.logger.woocommerce' ); $logger = $container->get( 'woocommerce.logger.woocommerce' );
@ -148,7 +149,7 @@ return array(
$logger $logger
); );
}, },
'api.endpoint.login-seller' => static function ( $container ) : LoginSeller { 'api.endpoint.login-seller' => static function ( ContainerInterface $container ) : LoginSeller {
$logger = $container->get( 'woocommerce.logger.woocommerce' ); $logger = $container->get( 'woocommerce.logger.woocommerce' );
return new LoginSeller( return new LoginSeller(
@ -157,7 +158,7 @@ return array(
$logger $logger
); );
}, },
'api.endpoint.order' => static function ( $container ): OrderEndpoint { 'api.endpoint.order' => static function ( ContainerInterface $container ): OrderEndpoint {
$order_factory = $container->get( 'api.factory.order' ); $order_factory = $container->get( 'api.factory.order' );
$patch_collection_factory = $container->get( 'api.factory.patch-collection-factory' ); $patch_collection_factory = $container->get( 'api.factory.patch-collection-factory' );
$logger = $container->get( 'woocommerce.logger.woocommerce' ); $logger = $container->get( 'woocommerce.logger.woocommerce' );
@ -182,44 +183,44 @@ return array(
$paypal_request_id $paypal_request_id
); );
}, },
'api.repository.paypal-request-id' => static function( $container ) : PayPalRequestIdRepository { 'api.repository.paypal-request-id' => static function( ContainerInterface $container ) : PayPalRequestIdRepository {
return new PayPalRequestIdRepository(); return new PayPalRequestIdRepository();
}, },
'api.repository.application-context' => static function( $container ) : ApplicationContextRepository { 'api.repository.application-context' => static function( ContainerInterface $container ) : ApplicationContextRepository {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
return new ApplicationContextRepository( $settings ); return new ApplicationContextRepository( $settings );
}, },
'api.repository.partner-referrals-data' => static function ( $container ) : PartnerReferralsData { 'api.repository.partner-referrals-data' => static function ( ContainerInterface $container ) : PartnerReferralsData {
$merchant_email = $container->get( 'api.merchant_email' ); $merchant_email = $container->get( 'api.merchant_email' );
$dcc_applies = $container->get( 'api.helpers.dccapplies' ); $dcc_applies = $container->get( 'api.helpers.dccapplies' );
return new PartnerReferralsData( $merchant_email, $dcc_applies ); return new PartnerReferralsData( $merchant_email, $dcc_applies );
}, },
'api.repository.cart' => static function ( $container ): CartRepository { 'api.repository.cart' => static function ( ContainerInterface $container ): CartRepository {
$factory = $container->get( 'api.factory.purchase-unit' ); $factory = $container->get( 'api.factory.purchase-unit' );
return new CartRepository( $factory ); return new CartRepository( $factory );
}, },
'api.repository.payee' => static function ( $container ): PayeeRepository { 'api.repository.payee' => static function ( ContainerInterface $container ): PayeeRepository {
$merchant_email = $container->get( 'api.merchant_email' ); $merchant_email = $container->get( 'api.merchant_email' );
$merchant_id = $container->get( 'api.merchant_id' ); $merchant_id = $container->get( 'api.merchant_id' );
return new PayeeRepository( $merchant_email, $merchant_id ); return new PayeeRepository( $merchant_email, $merchant_id );
}, },
'api.factory.application-context' => static function ( $container ) : ApplicationContextFactory { 'api.factory.application-context' => static function ( ContainerInterface $container ) : ApplicationContextFactory {
return new ApplicationContextFactory(); return new ApplicationContextFactory();
}, },
'api.factory.payment-token' => static function ( $container ) : PaymentTokenFactory { 'api.factory.payment-token' => static function ( ContainerInterface $container ) : PaymentTokenFactory {
return new PaymentTokenFactory(); return new PaymentTokenFactory();
}, },
'api.factory.webhook' => static function ( $container ): WebhookFactory { 'api.factory.webhook' => static function ( ContainerInterface $container ): WebhookFactory {
return new WebhookFactory(); return new WebhookFactory();
}, },
'api.factory.capture' => static function ( $container ): CaptureFactory { 'api.factory.capture' => static function ( ContainerInterface $container ): CaptureFactory {
$amount_factory = $container->get( 'api.factory.amount' ); $amount_factory = $container->get( 'api.factory.amount' );
return new CaptureFactory( $amount_factory ); return new CaptureFactory( $amount_factory );
}, },
'api.factory.purchase-unit' => static function ( $container ): PurchaseUnitFactory { 'api.factory.purchase-unit' => static function ( ContainerInterface $container ): PurchaseUnitFactory {
$amount_factory = $container->get( 'api.factory.amount' ); $amount_factory = $container->get( 'api.factory.amount' );
$payee_repository = $container->get( 'api.repository.payee' ); $payee_repository = $container->get( 'api.repository.payee' );
@ -239,34 +240,34 @@ return array(
$prefix $prefix
); );
}, },
'api.factory.patch-collection-factory' => static function ( $container ): PatchCollectionFactory { 'api.factory.patch-collection-factory' => static function ( ContainerInterface $container ): PatchCollectionFactory {
return new PatchCollectionFactory(); return new PatchCollectionFactory();
}, },
'api.factory.payee' => static function ( $container ): PayeeFactory { 'api.factory.payee' => static function ( ContainerInterface $container ): PayeeFactory {
return new PayeeFactory(); return new PayeeFactory();
}, },
'api.factory.item' => static function ( $container ): ItemFactory { 'api.factory.item' => static function ( ContainerInterface $container ): ItemFactory {
return new ItemFactory(); return new ItemFactory();
}, },
'api.factory.shipping' => static function ( $container ): ShippingFactory { 'api.factory.shipping' => static function ( ContainerInterface $container ): ShippingFactory {
$address_factory = $container->get( 'api.factory.address' ); $address_factory = $container->get( 'api.factory.address' );
return new ShippingFactory( $address_factory ); return new ShippingFactory( $address_factory );
}, },
'api.factory.amount' => static function ( $container ): AmountFactory { 'api.factory.amount' => static function ( ContainerInterface $container ): AmountFactory {
$item_factory = $container->get( 'api.factory.item' ); $item_factory = $container->get( 'api.factory.item' );
return new AmountFactory( $item_factory ); return new AmountFactory( $item_factory );
}, },
'api.factory.payer' => static function ( $container ): PayerFactory { 'api.factory.payer' => static function ( ContainerInterface $container ): PayerFactory {
$address_factory = $container->get( 'api.factory.address' ); $address_factory = $container->get( 'api.factory.address' );
return new PayerFactory( $address_factory ); return new PayerFactory( $address_factory );
}, },
'api.factory.address' => static function ( $container ): AddressFactory { 'api.factory.address' => static function ( ContainerInterface $container ): AddressFactory {
return new AddressFactory(); return new AddressFactory();
}, },
'api.factory.payment-source' => static function ( $container ): PaymentSourceFactory { 'api.factory.payment-source' => static function ( ContainerInterface $container ): PaymentSourceFactory {
return new PaymentSourceFactory(); return new PaymentSourceFactory();
}, },
'api.factory.order' => static function ( $container ): OrderFactory { 'api.factory.order' => static function ( ContainerInterface $container ): OrderFactory {
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' ); $purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
$payer_factory = $container->get( 'api.factory.payer' ); $payer_factory = $container->get( 'api.factory.payer' );
$application_context_repository = $container->get( 'api.repository.application-context' ); $application_context_repository = $container->get( 'api.repository.application-context' );
@ -280,15 +281,15 @@ return array(
$payment_source_factory $payment_source_factory
); );
}, },
'api.factory.payments' => static function ( $container ): PaymentsFactory { 'api.factory.payments' => static function ( ContainerInterface $container ): PaymentsFactory {
$authorizations_factory = $container->get( 'api.factory.authorization' ); $authorizations_factory = $container->get( 'api.factory.authorization' );
$capture_factory = $container->get( 'api.factory.capture' ); $capture_factory = $container->get( 'api.factory.capture' );
return new PaymentsFactory( $authorizations_factory, $capture_factory ); return new PaymentsFactory( $authorizations_factory, $capture_factory );
}, },
'api.factory.authorization' => static function ( $container ): AuthorizationFactory { 'api.factory.authorization' => static function ( ContainerInterface $container ): AuthorizationFactory {
return new AuthorizationFactory(); return new AuthorizationFactory();
}, },
'api.helpers.dccapplies' => static function ( $container ) : DccApplies { 'api.helpers.dccapplies' => static function ( ContainerInterface $container ) : DccApplies {
return new DccApplies(); return new DccApplies();
}, },
); );

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Button; namespace WooCommerce\PayPalCommerce\Button;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\Button\Assets\DisabledSmartButton; use WooCommerce\PayPalCommerce\Button\Assets\DisabledSmartButton;
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton; use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface; use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
@ -25,7 +26,7 @@ use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Onboarding\State;
return array( return array(
'button.client_id' => static function ( $container ): string { 'button.client_id' => static function ( ContainerInterface $container ): string {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
$client_id = $settings->has( 'client_id' ) ? $settings->get( 'client_id' ) : ''; $client_id = $settings->has( 'client_id' ) ? $settings->get( 'client_id' ) : '';
@ -43,7 +44,7 @@ return array(
return $env->current_environment_is( Environment::SANDBOX ) ? return $env->current_environment_is( Environment::SANDBOX ) ?
CONNECT_WOO_SANDBOX_CLIENT_ID : CONNECT_WOO_CLIENT_ID; CONNECT_WOO_SANDBOX_CLIENT_ID : CONNECT_WOO_CLIENT_ID;
}, },
'button.smart-button' => static function ( $container ): SmartButtonInterface { 'button.smart-button' => static function ( ContainerInterface $container ): SmartButtonInterface {
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
/** /**
@ -84,16 +85,16 @@ return array(
$settings_status $settings_status
); );
}, },
'button.url' => static function ( $container ): string { 'button.url' => static function ( ContainerInterface $container ): string {
return plugins_url( return plugins_url(
'/modules/ppcp-button/', '/modules/ppcp-button/',
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php' dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php'
); );
}, },
'button.request-data' => static function ( $container ): RequestData { 'button.request-data' => static function ( ContainerInterface $container ): RequestData {
return new RequestData(); return new RequestData();
}, },
'button.endpoint.change-cart' => static function ( $container ): ChangeCartEndpoint { 'button.endpoint.change-cart' => static function ( ContainerInterface $container ): ChangeCartEndpoint {
if ( ! \WC()->cart ) { if ( ! \WC()->cart ) {
throw new RuntimeException( 'cant initialize endpoint at this moment' ); throw new RuntimeException( 'cant initialize endpoint at this moment' );
} }
@ -104,7 +105,7 @@ return array(
$data_store = \WC_Data_Store::load( 'product' ); $data_store = \WC_Data_Store::load( 'product' );
return new ChangeCartEndpoint( $cart, $shipping, $request_data, $repository, $data_store ); return new ChangeCartEndpoint( $cart, $shipping, $request_data, $repository, $data_store );
}, },
'button.endpoint.create-order' => static function ( $container ): CreateOrderEndpoint { 'button.endpoint.create-order' => static function ( ContainerInterface $container ): CreateOrderEndpoint {
$request_data = $container->get( 'button.request-data' ); $request_data = $container->get( 'button.request-data' );
$cart_repository = $container->get( 'api.repository.cart' ); $cart_repository = $container->get( 'api.repository.cart' );
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' ); $purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
@ -124,7 +125,7 @@ return array(
$early_order_handler $early_order_handler
); );
}, },
'button.helper.early-order-handler' => static function ( $container ) : EarlyOrderHandler { 'button.helper.early-order-handler' => static function ( ContainerInterface $container ) : EarlyOrderHandler {
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
$order_processor = $container->get( 'wcgateway.order-processor' ); $order_processor = $container->get( 'wcgateway.order-processor' );
@ -132,7 +133,7 @@ return array(
$prefix = $container->get( 'api.prefix' ); $prefix = $container->get( 'api.prefix' );
return new EarlyOrderHandler( $state, $order_processor, $session_handler, $prefix ); return new EarlyOrderHandler( $state, $order_processor, $session_handler, $prefix );
}, },
'button.endpoint.approve-order' => static function ( $container ): ApproveOrderEndpoint { 'button.endpoint.approve-order' => static function ( ContainerInterface $container ): ApproveOrderEndpoint {
$request_data = $container->get( 'button.request-data' ); $request_data = $container->get( 'button.request-data' );
$order_endpoint = $container->get( 'api.endpoint.order' ); $order_endpoint = $container->get( 'api.endpoint.order' );
$session_handler = $container->get( 'session.handler' ); $session_handler = $container->get( 'session.handler' );
@ -150,7 +151,7 @@ return array(
$logger $logger
); );
}, },
'button.endpoint.data-client-id' => static function( $container ) : DataClientIdEndpoint { 'button.endpoint.data-client-id' => static function( ContainerInterface $container ) : DataClientIdEndpoint {
$request_data = $container->get( 'button.request-data' ); $request_data = $container->get( 'button.request-data' );
$identity_token = $container->get( 'api.endpoint.identity-token' ); $identity_token = $container->get( 'api.endpoint.identity-token' );
return new DataClientIdEndpoint( return new DataClientIdEndpoint(
@ -158,10 +159,10 @@ return array(
$identity_token $identity_token
); );
}, },
'button.helper.three-d-secure' => static function ( $container ): ThreeDSecure { 'button.helper.three-d-secure' => static function ( ContainerInterface $container ): ThreeDSecure {
return new ThreeDSecure(); return new ThreeDSecure();
}, },
'button.helper.messages-apply' => static function ( $container ): MessagesApply { 'button.helper.messages-apply' => static function ( ContainerInterface $container ): MessagesApply {
return new MessagesApply(); return new MessagesApply();
}, },
); );

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding; namespace WooCommerce\PayPalCommerce\Onboarding;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer; use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\ConnectBearer; use WooCommerce\PayPalCommerce\ApiClient\Authentication\ConnectBearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer; use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
@ -21,7 +22,7 @@ use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
use WooCommerce\PayPalCommerce\Onboarding\Onboarding_REST_Controller; use WooCommerce\PayPalCommerce\Onboarding\Onboarding_REST_Controller;
return array( return array(
'api.sandbox-host' => static function ( $container ): string { 'api.sandbox-host' => static function ( ContainerInterface $container ): string {
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
@ -35,7 +36,7 @@ return array(
} }
return CONNECT_WOO_SANDBOX_URL; return CONNECT_WOO_SANDBOX_URL;
}, },
'api.production-host' => static function ( $container ): string { 'api.production-host' => static function ( ContainerInterface $container ): string {
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
@ -50,7 +51,7 @@ return array(
} }
return CONNECT_WOO_URL; return CONNECT_WOO_URL;
}, },
'api.host' => static function ( $container ): string { 'api.host' => static function ( ContainerInterface $container ): string {
$environment = $container->get( 'onboarding.environment' ); $environment = $container->get( 'onboarding.environment' );
/** /**
@ -62,19 +63,19 @@ return array(
? (string) $container->get( 'api.sandbox-host' ) : (string) $container->get( 'api.production-host' ); ? (string) $container->get( 'api.sandbox-host' ) : (string) $container->get( 'api.production-host' );
}, },
'api.paypal-host-production' => static function( $container ) : string { 'api.paypal-host-production' => static function( ContainerInterface $container ) : string {
return PAYPAL_API_URL; return PAYPAL_API_URL;
}, },
'api.paypal-host-sandbox' => static function( $container ) : string { 'api.paypal-host-sandbox' => static function( ContainerInterface $container ) : string {
return PAYPAL_SANDBOX_API_URL; return PAYPAL_SANDBOX_API_URL;
}, },
'api.partner_merchant_id-production' => static function( $container ) : string { 'api.partner_merchant_id-production' => static function( ContainerInterface $container ) : string {
return CONNECT_WOO_MERCHANT_ID; return CONNECT_WOO_MERCHANT_ID;
}, },
'api.partner_merchant_id-sandbox' => static function( $container ) : string { 'api.partner_merchant_id-sandbox' => static function( ContainerInterface $container ) : string {
return CONNECT_WOO_SANDBOX_MERCHANT_ID; return CONNECT_WOO_SANDBOX_MERCHANT_ID;
}, },
'api.paypal-host' => function( $container ) : string { 'api.paypal-host' => function( ContainerInterface $container ) : string {
$environment = $container->get( 'onboarding.environment' ); $environment = $container->get( 'onboarding.environment' );
/** /**
* The current environment. * The current environment.
@ -88,7 +89,7 @@ return array(
}, },
'api.bearer' => static function ( $container ): Bearer { 'api.bearer' => static function ( ContainerInterface $container ): Bearer {
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
@ -115,17 +116,17 @@ return array(
$settings $settings
); );
}, },
'onboarding.state' => function( $container ) : State { 'onboarding.state' => function( ContainerInterface $container ) : State {
$environment = $container->get( 'onboarding.environment' ); $environment = $container->get( 'onboarding.environment' );
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
return new State( $environment, $settings ); return new State( $environment, $settings );
}, },
'onboarding.environment' => function( $container ) : Environment { 'onboarding.environment' => function( ContainerInterface $container ) : Environment {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
return new Environment( $settings ); return new Environment( $settings );
}, },
'onboarding.assets' => function( $container ) : OnboardingAssets { 'onboarding.assets' => function( ContainerInterface $container ) : OnboardingAssets {
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
$login_seller_endpoint = $container->get( 'onboarding.endpoint.login-seller' ); $login_seller_endpoint = $container->get( 'onboarding.endpoint.login-seller' );
return new OnboardingAssets( return new OnboardingAssets(
@ -135,14 +136,14 @@ return array(
); );
}, },
'onboarding.url' => static function ( $container ): string { 'onboarding.url' => static function ( ContainerInterface $container ): string {
return plugins_url( return plugins_url(
'/modules/ppcp-onboarding/', '/modules/ppcp-onboarding/',
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php' dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php'
); );
}, },
'api.endpoint.login-seller-production' => static function ( $container ) : LoginSeller { 'api.endpoint.login-seller-production' => static function ( ContainerInterface $container ) : LoginSeller {
$logger = $container->get( 'woocommerce.logger.woocommerce' ); $logger = $container->get( 'woocommerce.logger.woocommerce' );
return new LoginSeller( return new LoginSeller(
@ -152,7 +153,7 @@ return array(
); );
}, },
'api.endpoint.login-seller-sandbox' => static function ( $container ) : LoginSeller { 'api.endpoint.login-seller-sandbox' => static function ( ContainerInterface $container ) : LoginSeller {
$logger = $container->get( 'woocommerce.logger.woocommerce' ); $logger = $container->get( 'woocommerce.logger.woocommerce' );
return new LoginSeller( return new LoginSeller(
@ -162,7 +163,7 @@ return array(
); );
}, },
'onboarding.endpoint.login-seller' => static function ( $container ) : LoginSellerEndpoint { 'onboarding.endpoint.login-seller' => static function ( ContainerInterface $container ) : LoginSellerEndpoint {
$request_data = $container->get( 'button.request-data' ); $request_data = $container->get( 'button.request-data' );
$login_seller_production = $container->get( 'api.endpoint.login-seller-production' ); $login_seller_production = $container->get( 'api.endpoint.login-seller-production' );
@ -180,7 +181,7 @@ return array(
$cache $cache
); );
}, },
'api.endpoint.partner-referrals-sandbox' => static function ( $container ) : PartnerReferrals { 'api.endpoint.partner-referrals-sandbox' => static function ( ContainerInterface $container ) : PartnerReferrals {
return new PartnerReferrals( return new PartnerReferrals(
CONNECT_WOO_SANDBOX_URL, CONNECT_WOO_SANDBOX_URL,
@ -189,7 +190,7 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' ) $container->get( 'woocommerce.logger.woocommerce' )
); );
}, },
'api.endpoint.partner-referrals-production' => static function ( $container ) : PartnerReferrals { 'api.endpoint.partner-referrals-production' => static function ( ContainerInterface $container ) : PartnerReferrals {
return new PartnerReferrals( return new PartnerReferrals(
CONNECT_WOO_URL, CONNECT_WOO_URL,
@ -198,7 +199,7 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' ) $container->get( 'woocommerce.logger.woocommerce' )
); );
}, },
'onboarding.render' => static function ( $container ) : OnboardingRenderer { 'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
$partner_referrals = $container->get( 'api.endpoint.partner-referrals-production' ); $partner_referrals = $container->get( 'api.endpoint.partner-referrals-production' );
$partner_referrals_sandbox = $container->get( 'api.endpoint.partner-referrals-sandbox' ); $partner_referrals_sandbox = $container->get( 'api.endpoint.partner-referrals-sandbox' );

View file

@ -9,11 +9,12 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Session; namespace WooCommerce\PayPalCommerce\Session;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\Session\Cancellation\CancelController; use WooCommerce\PayPalCommerce\Session\Cancellation\CancelController;
use WooCommerce\PayPalCommerce\Session\Cancellation\CancelView; use WooCommerce\PayPalCommerce\Session\Cancellation\CancelView;
return array( return array(
'session.handler' => function ( $container ) : SessionHandler { 'session.handler' => function ( ContainerInterface $container ) : SessionHandler {
if ( is_null( WC()->session ) ) { if ( is_null( WC()->session ) ) {
return new SessionHandler(); return new SessionHandler();
@ -26,10 +27,10 @@ return array(
WC()->session->set( SessionHandler::ID, $session_handler ); WC()->session->set( SessionHandler::ID, $session_handler );
return $session_handler; return $session_handler;
}, },
'session.cancellation.view' => function ( $container ) : CancelView { 'session.cancellation.view' => function ( ContainerInterface $container ) : CancelView {
return new CancelView(); return new CancelView();
}, },
'session.cancellation.controller' => function ( $container ) : CancelController { 'session.cancellation.controller' => function ( ContainerInterface $container ) : CancelController {
return new CancelController( return new CancelController(
$container->get( 'session.handler' ), $container->get( 'session.handler' ),
$container->get( 'session.cancellation.view' ) $container->get( 'session.cancellation.view' )

View file

@ -14,10 +14,10 @@ use WooCommerce\PayPalCommerce\Subscription\Repository\PaymentTokenRepository;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
return array( return array(
'subscription.helper' => static function ( $container ): SubscriptionHelper { 'subscription.helper' => static function ( ContainerInterface $container ): SubscriptionHelper {
return new SubscriptionHelper(); return new SubscriptionHelper();
}, },
'subscription.renewal-handler' => static function ( $container ): RenewalHandler { 'subscription.renewal-handler' => static function ( ContainerInterface $container ): RenewalHandler {
$logger = $container->get( 'woocommerce.logger.woocommerce' ); $logger = $container->get( 'woocommerce.logger.woocommerce' );
$repository = $container->get( 'subscription.repository.payment-token' ); $repository = $container->get( 'subscription.repository.payment-token' );
$endpoint = $container->get( 'api.endpoint.order' ); $endpoint = $container->get( 'api.endpoint.order' );
@ -31,7 +31,7 @@ return array(
$payer_factory $payer_factory
); );
}, },
'subscription.repository.payment-token' => static function ( $container ): PaymentTokenRepository { 'subscription.repository.payment-token' => static function ( ContainerInterface $container ): PaymentTokenRepository {
$factory = $container->get( 'api.factory.payment-token' ); $factory = $container->get( 'api.factory.payment-token' );
$endpoint = $container->get( 'api.endpoint.payment-token' ); $endpoint = $container->get( 'api.endpoint.payment-token' );
return new PaymentTokenRepository( $factory, $endpoint ); return new PaymentTokenRepository( $factory, $endpoint );

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway; namespace WooCommerce\PayPalCommerce\WcGateway;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext; use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
@ -35,9 +36,10 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener; use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer; use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
use WpOop\TransientCache\CachePoolFactory;
return array( return array(
'wcgateway.paypal-gateway' => static function ( $container ): PayPalGateway { 'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
$order_processor = $container->get( 'wcgateway.order-processor' ); $order_processor = $container->get( 'wcgateway.order-processor' );
$settings_renderer = $container->get( 'wcgateway.settings.render' ); $settings_renderer = $container->get( 'wcgateway.settings.render' );
$authorized_payments = $container->get( 'wcgateway.processor.authorized-payments' ); $authorized_payments = $container->get( 'wcgateway.processor.authorized-payments' );
@ -61,7 +63,7 @@ return array(
$subscription_helper $subscription_helper
); );
}, },
'wcgateway.credit-card-gateway' => static function ( $container ): CreditCardGateway { 'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
$order_processor = $container->get( 'wcgateway.order-processor' ); $order_processor = $container->get( 'wcgateway.order-processor' );
$settings_renderer = $container->get( 'wcgateway.settings.render' ); $settings_renderer = $container->get( 'wcgateway.settings.render' );
$authorized_payments = $container->get( 'wcgateway.processor.authorized-payments' ); $authorized_payments = $container->get( 'wcgateway.processor.authorized-payments' );
@ -95,15 +97,15 @@ return array(
$subscription_helper $subscription_helper
); );
}, },
'wcgateway.disabler' => static function ( $container ): DisableGateways { 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
$session_handler = $container->get( 'session.handler' ); $session_handler = $container->get( 'session.handler' );
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
return new DisableGateways( $session_handler, $settings ); return new DisableGateways( $session_handler, $settings );
}, },
'wcgateway.settings' => static function ( $container ): Settings { 'wcgateway.settings' => static function ( ContainerInterface $container ): Settings {
return new Settings(); return new Settings();
}, },
'wcgateway.notice.connect' => static function ( $container ): ConnectAdminNotice { 'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice {
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
return new ConnectAdminNotice( $state, $settings ); return new ConnectAdminNotice( $state, $settings );
@ -112,14 +114,14 @@ return array(
static function ( $container ): AuthorizeOrderActionNotice { static function ( $container ): AuthorizeOrderActionNotice {
return new AuthorizeOrderActionNotice(); return new AuthorizeOrderActionNotice();
}, },
'wcgateway.settings.sections-renderer' => static function ( $container ): SectionsRenderer { 'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
return new SectionsRenderer(); return new SectionsRenderer();
}, },
'wcgateway.settings.status' => static function ( $container ): SettingsStatus { 'wcgateway.settings.status' => static function ( $container ): SettingsStatus {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
return new SettingsStatus( $settings ); return new SettingsStatus( $settings );
}, },
'wcgateway.settings.render' => static function ( $container ): SettingsRenderer { 'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
$fields = $container->get( 'wcgateway.settings.fields' ); $fields = $container->get( 'wcgateway.settings.fields' );
@ -137,7 +139,7 @@ return array(
$settings_status $settings_status
); );
}, },
'wcgateway.settings.listener' => static function ( $container ): SettingsListener { 'wcgateway.settings.listener' => static function ( ContainerInterface $container ): SettingsListener {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
$fields = $container->get( 'wcgateway.settings.fields' ); $fields = $container->get( 'wcgateway.settings.fields' );
$webhook_registrar = $container->get( 'webhook.registrar' ); $webhook_registrar = $container->get( 'webhook.registrar' );
@ -146,7 +148,7 @@ return array(
$bearer = $container->get( 'api.bearer' ); $bearer = $container->get( 'api.bearer' );
return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer ); return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer );
}, },
'wcgateway.order-processor' => static function ( $container ): OrderProcessor { 'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
$session_handler = $container->get( 'session.handler' ); $session_handler = $container->get( 'session.handler' );
$order_endpoint = $container->get( 'api.endpoint.order' ); $order_endpoint = $container->get( 'api.endpoint.order' );
@ -167,29 +169,29 @@ return array(
$environment->current_environment_is( Environment::SANDBOX ) $environment->current_environment_is( Environment::SANDBOX )
); );
}, },
'wcgateway.processor.refunds' => static function ( $container ): RefundProcessor { 'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
$order_endpoint = $container->get( 'api.endpoint.order' ); $order_endpoint = $container->get( 'api.endpoint.order' );
$payments_endpoint = $container->get( 'api.endpoint.payments' ); $payments_endpoint = $container->get( 'api.endpoint.payments' );
return new RefundProcessor( $order_endpoint, $payments_endpoint ); return new RefundProcessor( $order_endpoint, $payments_endpoint );
}, },
'wcgateway.processor.authorized-payments' => static function ( $container ): AuthorizedPaymentsProcessor { 'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor {
$order_endpoint = $container->get( 'api.endpoint.order' ); $order_endpoint = $container->get( 'api.endpoint.order' );
$payments_endpoint = $container->get( 'api.endpoint.payments' ); $payments_endpoint = $container->get( 'api.endpoint.payments' );
return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint ); return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint );
}, },
'wcgateway.admin.render-authorize-action' => static function ( $container ): RenderAuthorizeAction { 'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction {
return new RenderAuthorizeAction(); return new RenderAuthorizeAction();
}, },
'wcgateway.admin.order-payment-status' => static function ( $container ): PaymentStatusOrderDetail { 'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail {
return new PaymentStatusOrderDetail(); return new PaymentStatusOrderDetail();
}, },
'wcgateway.admin.orders-payment-status-column' => static function ( $container ): OrderTablePaymentStatusColumn { 'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ): OrderTablePaymentStatusColumn {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
return new OrderTablePaymentStatusColumn( $settings ); return new OrderTablePaymentStatusColumn( $settings );
}, },
'wcgateway.settings.fields' => static function ( $container ): array { 'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array {
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
$messages_disclaimers = $container->get( 'button.helper.messages-disclaimers' ); $messages_disclaimers = $container->get( 'button.helper.messages-disclaimers' );
@ -1862,13 +1864,13 @@ return array(
return $fields; return $fields;
}, },
'wcgateway.checkout.address-preset' => static function( $container ): CheckoutPayPalAddressPreset { 'wcgateway.checkout.address-preset' => static function( ContainerInterface $container ): CheckoutPayPalAddressPreset {
return new CheckoutPayPalAddressPreset( return new CheckoutPayPalAddressPreset(
$container->get( 'session.handler' ) $container->get( 'session.handler' )
); );
}, },
'wcgateway.url' => static function ( $container ): string { 'wcgateway.url' => static function ( ContainerInterface $container ): string {
return plugins_url( return plugins_url(
$container->get( 'wcgateway.relative-path' ), $container->get( 'wcgateway.relative-path' ),
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php' dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php'
@ -1883,7 +1885,7 @@ return array(
) . ) .
$container->get( 'wcgateway.relative-path' ); $container->get( 'wcgateway.relative-path' );
}, },
'wcgateway.endpoint.return-url' => static function ( $container ) : ReturnUrlEndpoint { 'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint {
$gateway = $container->get( 'wcgateway.paypal-gateway' ); $gateway = $container->get( 'wcgateway.paypal-gateway' );
$endpoint = $container->get( 'api.endpoint.order' ); $endpoint = $container->get( 'api.endpoint.order' );
$prefix = $container->get( 'api.prefix' ); $prefix = $container->get( 'api.prefix' );
@ -1909,7 +1911,7 @@ return array(
return new TransactionUrlProvider( $sandbox_url_base, $live_url_base ); return new TransactionUrlProvider( $sandbox_url_base, $live_url_base );
}, },
'wcgateway.helper.dcc-product-status' => static function ( $container ) : DccProductStatus { 'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DccProductStatus {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
$partner_endpoint = $container->get( 'api.endpoint.partners' ); $partner_endpoint = $container->get( 'api.endpoint.partners' );

View file

@ -18,7 +18,7 @@ use Psr\Container\ContainerInterface;
return array( return array(
'webhook.registrar' => function( $container ) : WebhookRegistrar { 'webhook.registrar' => function( ContainerInterface $container ) : WebhookRegistrar {
$factory = $container->get( 'api.factory.webhook' ); $factory = $container->get( 'api.factory.webhook' );
$endpoint = $container->get( 'api.endpoint.webhook' ); $endpoint = $container->get( 'api.endpoint.webhook' );
$rest_endpoint = $container->get( 'webhook.endpoint.controller' ); $rest_endpoint = $container->get( 'webhook.endpoint.controller' );
@ -28,7 +28,7 @@ return array(
$rest_endpoint $rest_endpoint
); );
}, },
'webhook.endpoint.controller' => function( $container ) : IncomingWebhookEndpoint { 'webhook.endpoint.controller' => function( ContainerInterface $container ) : IncomingWebhookEndpoint {
$webhook_endpoint = $container->get( 'api.endpoint.webhook' ); $webhook_endpoint = $container->get( 'api.endpoint.webhook' );
$webhook_factory = $container->get( 'api.factory.webhook' ); $webhook_factory = $container->get( 'api.factory.webhook' );
$handler = $container->get( 'webhook.endpoint.handler' ); $handler = $container->get( 'webhook.endpoint.handler' );
@ -43,7 +43,7 @@ return array(
... $handler ... $handler
); );
}, },
'webhook.endpoint.handler' => function( $container ) : array { 'webhook.endpoint.handler' => function( ContainerInterface $container ) : array {
$logger = $container->get( 'woocommerce.logger.woocommerce' ); $logger = $container->get( 'woocommerce.logger.woocommerce' );
$prefix = $container->get( 'api.prefix' ); $prefix = $container->get( 'api.prefix' );
$order_endpoint = $container->get( 'api.endpoint.order' ); $order_endpoint = $container->get( 'api.endpoint.order' );