From 7cd337ac8db600bf065724fdd24c1efc41828c23 Mon Sep 17 00:00:00 2001 From: Marvin Muxfeld Date: Mon, 30 Sep 2024 14:28:07 +0200 Subject: [PATCH] PISHPS-362: billie is now hidden for none business accounts --- .../Payment/Remover/RegularPaymentRemover.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Service/Payment/Remover/RegularPaymentRemover.php b/src/Service/Payment/Remover/RegularPaymentRemover.php index 4a18c1bc4..e27cc6e32 100644 --- a/src/Service/Payment/Remover/RegularPaymentRemover.php +++ b/src/Service/Payment/Remover/RegularPaymentRemover.php @@ -8,6 +8,7 @@ use Kiener\MolliePayments\Struct\PaymentMethod\PaymentMethodAttributes; use Mollie\Api\Types\PaymentMethod; use Psr\Log\LoggerInterface; +use Shopware\Core\Checkout\Customer\CustomerEntity; use Shopware\Core\Checkout\Payment\SalesChannel\PaymentMethodRouteResponse; use Shopware\Core\System\SalesChannel\SalesChannelContext; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -50,8 +51,29 @@ public function removePaymentMethods(PaymentMethodRouteResponse $originalData, S if ($attributes->getMollieIdentifier() === PaymentMethod::INGHOMEPAY) { $originalData->getPaymentMethods()->remove($key); } + + # hiding billie for none business customers + if ($attributes->getMollieIdentifier() === PaymentMethod::BILLIE && $this->isBusinessAccount($context) === false) { + $originalData->getPaymentMethods()->remove($key); + } } return $originalData; } + + private function isBusinessAccount(SalesChannelContext $context): bool + { + $customer = $context->getCustomer(); + + if ($customer === null) { + return false; + } + + if (method_exists($customer, 'getAccountType') === false) { + $billingAddress = $customer->getDefaultBillingAddress(); + return $billingAddress && !empty($billingAddress->getCompany()); + } + + return $customer->getAccountType() === CustomerEntity::ACCOUNT_TYPE_BUSINESS; + } }