diff --git a/vendor/magento/module-company-payment/Plugin/Payment/Model/MethodInterfacePlugin.php b/vendor/magento/module-company-payment/Plugin/Payment/Model/MethodInterfacePlugin.php new file mode 100644 index 000000000000..c18f876f0d5c --- /dev/null +++ b/vendor/magento/module-company-payment/Plugin/Payment/Model/MethodInterfacePlugin.php @@ -0,0 +1,86 @@ +userContext = $userContext; + $this->companyManagement = $companyManagement; + $this->availabilityChecker = $availabilityChecker; + } + + /** + * Checking if payment is available on company level + * + * @param MethodInterface $subject + * @param bool $result + * @return bool + */ + public function afterIsAvailable(MethodInterface $subject, bool $result): bool + { + $customerId = $this->userContext->getUserId(); + if ($customerId) { + $company = $this->companyManagement->getByCustomerId($customerId); + if ($company) { + $paymentMethodCode = $subject->getCode(); + $isAvailable = $this->availabilityChecker->isAvailableForCompany($paymentMethodCode, $company); + if (!$isAvailable) { + return false; + } + } + } + return $result; + } +} diff --git a/vendor/magento/module-company-payment/Plugin/Paypal/Block/Express/InContext/SmartButtonPlugin.php b/vendor/magento/module-company-payment/Plugin/Paypal/Block/Express/InContext/SmartButtonPlugin.php new file mode 100644 index 000000000000..836b4a5100e4 --- /dev/null +++ b/vendor/magento/module-company-payment/Plugin/Paypal/Block/Express/InContext/SmartButtonPlugin.php @@ -0,0 +1,86 @@ +userContext = $userContext; + $this->companyManagement = $companyManagement; + $this->availabilityChecker = $availabilityChecker; + } + + /** + * Checking if PayPal express smart button is available on company level + * + * @param SmartButton $subject + * @param string $result + * @return string + */ + public function afterToHtml(SmartButton $subject, string $result): string + { + $customerId = $this->userContext->getUserId(); + if ($customerId) { + $company = $this->companyManagement->getByCustomerId($customerId); + if ($company) { + $isAvailable = $this->availabilityChecker->isAvailableForCompany(Config::METHOD_EXPRESS, $company); + if (!$isAvailable) { + return ''; + } + } + } + return $result; + } +} diff --git a/vendor/magento/module-company-payment/etc/frontend/di.xml b/vendor/magento/module-company-payment/etc/frontend/di.xml index 5cd9933f8a44..978a1db5f31a 100644 --- a/vendor/magento/module-company-payment/etc/frontend/di.xml +++ b/vendor/magento/module-company-payment/etc/frontend/di.xml @@ -12,4 +12,10 @@ + + + + + +