From 0d01ac02dffddbabce5aeaae0a42480a4ae23a6d Mon Sep 17 00:00:00 2001 From: m-muxfeld-diw <143803170+m-muxfeld-diw@users.noreply.github.com> Date: Mon, 30 Sep 2024 16:29:55 +0200 Subject: [PATCH] PISHPS-362: billie is now hidden for none business accounts (#849) --- .../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; + } }