Skip to content

Commit

Permalink
PAYOSWXP-47: Unzer invoice purchase: if there is no company name in c…
Browse files Browse the repository at this point in the history
…onfig, paymentmethod should be hidden
  • Loading branch information
amirinterlutions committed Nov 10, 2023
1 parent 5497dc3 commit 7b760df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
53 changes: 28 additions & 25 deletions src/EventListener/CheckoutConfirmPayolutionEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
namespace PayonePayment\EventListener;

use PayonePayment\Components\ConfigReader\ConfigReaderInterface;
use PayonePayment\Configuration\ConfigurationPrefixes;
use PayonePayment\PaymentHandler\PayonePayolutionDebitPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInstallmentPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInvoicingPaymentHandler;
use PayonePayment\PaymentMethod\PayonePayolutionDebit;
use PayonePayment\PaymentMethod\PayonePayolutionInstallment;
use PayonePayment\PaymentMethod\PayonePayolutionInvoicing;
use Shopware\Core\Checkout\Payment\PaymentMethodCollection;
Expand All @@ -24,24 +29,31 @@ public function __construct(private readonly ConfigReaderInterface $configReader
public static function getSubscribedEvents(): array
{
return [
CheckoutConfirmPageLoadedEvent::class => 'hidePaymentMethodsForCompanies',
AccountPaymentMethodPageLoadedEvent::class => 'hidePaymentMethodsForCompanies',
AccountEditOrderPageLoadedEvent::class => 'hidePaymentMethodsForCompanies',
CheckoutConfirmPageLoadedEvent::class => 'hidePaymentMethods',
AccountPaymentMethodPageLoadedEvent::class => 'hidePaymentMethods',
AccountEditOrderPageLoadedEvent::class => 'hidePaymentMethods',
];
}

public function hidePaymentMethodsForCompanies(
public function hidePaymentMethods(
CheckoutConfirmPageLoadedEvent|AccountPaymentMethodPageLoadedEvent|AccountEditOrderPageLoadedEvent $event
): void {
$page = $event->getPage();

if (!$this->customerHasCompanyAddress($event->getSalesChannelContext())) {
return;
$paymentMethods = $page->getPaymentMethods();
$paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInstallment::UUID);

if ($this->companyNameMissing($event->getSalesChannelContext(), PayonePayolutionInvoicingPaymentHandler::class)) {
$paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInvoicing::UUID);
}

$paymentMethods = $page->getPaymentMethods();
if ($this->companyNameMissing($event->getSalesChannelContext(), PayonePayolutionDebitPaymentHandler::class)) {
$paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionDebit::UUID);
}

$paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInstallment::UUID);
if ($this->companyNameMissing($event->getSalesChannelContext(), PayonePayolutionInstallmentPaymentHandler::class)) {
$paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInstallment::UUID);
}

if ($this->companyDataHandlingIsDisabled($event->getSalesChannelContext())) {
$paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInvoicing::UUID);
Expand All @@ -57,27 +69,18 @@ private function removePaymentMethod(PaymentMethodCollection $paymentMethods, st
);
}

private function customerHasCompanyAddress(SalesChannelContext $context): bool
private function companyDataHandlingIsDisabled(SalesChannelContext $context): bool
{
$customer = $context->getCustomer();

if ($customer === null) {
return false;
}

$billingAddress = $customer->getActiveBillingAddress();

if ($billingAddress === null) {
return false;
}

return !empty($billingAddress->getCompany());
return !($this->getConfiguration($context, 'payolutionInvoicingTransferCompanyData'));
}

private function companyDataHandlingIsDisabled(SalesChannelContext $context): bool
private function companyNameMissing(SalesChannelContext $context, string $paymentHandler): bool
{
$configuration = $this->configReader->read($context->getSalesChannel()->getId());
return empty($this->getConfiguration($context, ConfigurationPrefixes::CONFIGURATION_PREFIXES[$paymentHandler] . 'CompanyName'));
}

return !($configuration->get('payolutionInvoicingTransferCompanyData'));
private function getConfiguration(SalesChannelContext $context, string $configName): array|bool|int|string|null
{
return $this->configReader->read($context->getSalesChannel()->getId())->get($configName);
}
}
2 changes: 1 addition & 1 deletion src/Resources/snippet/en_GB/messages.en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
"consentCheckbox": {
"introduction": "With the transmission of the data necessary for the completion of the invoice purchase, an identity check and credit check to payolution GmbH, Am Euro Platz 2, 1120 Wien I agree.",
"textWithLink": "I can revoke my <a href=\"%link%\" data-url=\"%link%\" data-modal-class=\"payolution\" data-toggle=\"modal\" title=\"Einwilligung\">consent</a> at any time with effect for the future."
"textWithLink": "I can revoke my <a data-toggle=\"modal\" data-bs-toggle=\"modal\" data-url=\"%link%\" href=\"%link%\" title=\"Einwilligung\">consent</a> at any time with effect for the future."
},
"mandateCheckbox": {
"textWithLink": "I hereby issue the <a href=\"%link%\" target=\"_blank\" title=\"Paysafe Pay Later SEPA mandate\">SEPA direct debit mandate</a>."
Expand Down

0 comments on commit 7b760df

Please sign in to comment.