Skip to content

Commit

Permalink
Merge pull request #43 from p1fb/SW6-46-eps-payment-integration
Browse files Browse the repository at this point in the history
SW6-46: Integrate EPS payment
  • Loading branch information
hreinberger authored Jul 1, 2020
2 parents 1048f4e + 4997430 commit 0832e86
Show file tree
Hide file tree
Showing 24 changed files with 740 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Configuration/ConfigurationPrefixes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PayonePayment\PaymentHandler\PayoneCreditCardPaymentHandler;
use PayonePayment\PaymentHandler\PayoneDebitPaymentHandler;
use PayonePayment\PaymentHandler\PayoneEpsPaymentHandler;
use PayonePayment\PaymentHandler\PayoneIDealPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionDebitPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInstallmentPaymentHandler;
Expand All @@ -24,6 +25,7 @@ interface ConfigurationPrefixes
public const CONFIGURATION_PREFIX_PAYOLUTION_INSTALLMENT = 'payolutionInstallment';
public const CONFIGURATION_PREFIX_PAYOLUTION_DEBIT = 'payolutionDebit';
public const CONFIGURATION_PREFIX_SOFORT = 'sofort';
public const CONFIGURATION_PREFIX_EPS = 'eps';
public const CONFIGURATION_PREFIX_IDEAL = 'iDeal';

public const CONFIGURATION_PREFIXES = [
Expand All @@ -35,6 +37,7 @@ interface ConfigurationPrefixes
PayonePayolutionInstallmentPaymentHandler::class => self::CONFIGURATION_PREFIX_PAYOLUTION_INSTALLMENT,
PayonePayolutionDebitPaymentHandler::class => self::CONFIGURATION_PREFIX_PAYOLUTION_DEBIT,
PayoneSofortBankingPaymentHandler::class => self::CONFIGURATION_PREFIX_SOFORT,
PayoneEpsPaymentHandler::class => self::CONFIGURATION_PREFIX_EPS,
PayoneIDealPaymentHandler::class => self::CONFIGURATION_PREFIX_IDEAL,
];
}
17 changes: 17 additions & 0 deletions src/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PayonePayment\Configuration\ConfigurationPrefixes;
use PayonePayment\PaymentHandler\PayoneCreditCardPaymentHandler;
use PayonePayment\PaymentHandler\PayoneDebitPaymentHandler;
use PayonePayment\PaymentHandler\PayoneEpsPaymentHandler;
use PayonePayment\PaymentHandler\PayoneIDealPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionDebitPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInstallmentPaymentHandler;
Expand Down Expand Up @@ -205,6 +206,22 @@ private function getPaymentParameters(string $paymentClass): array
'successurl' => 'https://www.payone.com',
];

case PayoneEpsPaymentHandler::class:
return [
'request' => 'preauthorization',
'clearingtype' => 'sb',
'onlinebanktransfertype' => 'EPS',
'bankcountry' => 'AT',
'bankgrouptype' => 'ARZ_HTB',
'amount' => 100,
'currency' => 'EUR',
'reference' => sprintf('%s%d', self::REFERENCE_PREFIX_TEST, random_int(1000000000000, 9999999999999)),
'firstname' => 'Test',
'lastname' => 'Test',
'country' => 'AT',
'successurl' => 'https://www.payone.com',
];

case PayoneIDealPaymentHandler::class:
return [
'request' => 'preauthorization',
Expand Down
14 changes: 14 additions & 0 deletions src/DependencyInjection/handler/payment_handler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@

<service id="PayonePayment\PaymentHandler\PayoneIDealPaymentHandler">
<argument type="service" id="PayonePayment\Components\ConfigReader\ConfigReader" />
<argument type="service" id="order_line_item.repository" />
<argument type="service" id="PayonePayment\Payone\Request\IDeal\IDealPreAuthorizeRequestFactory" />
<argument type="service" id="PayonePayment\Payone\Request\IDeal\IDealAuthorizeRequestFactory" />
<argument type="service" id="PayonePayment\Payone\Client\PayoneClient" />
Expand All @@ -117,5 +118,18 @@

<tag name="shopware.payment.method.async" />
</service>

<service id="PayonePayment\PaymentHandler\PayoneEpsPaymentHandler">
<argument type="service" id="PayonePayment\Components\ConfigReader\ConfigReader" />
<argument type="service" id="order_line_item.repository" />
<argument type="service" id="PayonePayment\Payone\Request\Eps\EpsPreAuthorizeRequestFactory" />
<argument type="service" id="PayonePayment\Payone\Request\Eps\EpsAuthorizeRequestFactory" />
<argument type="service" id="PayonePayment\Payone\Client\PayoneClient" />
<argument type="service" id="translator" />
<argument type="service" id="PayonePayment\Components\DataHandler\Transaction\TransactionDataHandler" />
<argument type="service" id="PayonePayment\Components\PaymentStateHandler\PaymentStateHandler" />

<tag name="shopware.payment.method.async" />
</service>
</services>
</container>
4 changes: 4 additions & 0 deletions src/DependencyInjection/listeners.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<tag name="kernel.event_subscriber"/>
</service>

<service id="PayonePayment\EventListener\CheckoutConfirmEpsEventListener">
<tag name="kernel.event_subscriber"/>
</service>

<service id="PayonePayment\EventListener\CheckoutConfirmIDealEventListener">
<tag name="kernel.event_subscriber"/>
</service>
Expand Down
23 changes: 23 additions & 0 deletions src/DependencyInjection/requests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@
<argument type="service" id="PayonePayment\Payone\Request\System\SystemRequest" />
</service>

<!-- EPS Banking -->
<service id="PayonePayment\Payone\Request\Eps\EpsAuthorizeRequest">
<argument type="service" id="PayonePayment\Components\RedirectHandler\RedirectHandler" />
<argument type="service" id="currency.repository" />
</service>

<service id="PayonePayment\Payone\Request\Eps\EpsPreAuthorizeRequest">
<argument type="service" id="PayonePayment\Components\RedirectHandler\RedirectHandler" />
<argument type="service" id="currency.repository" />
</service>

<service id="PayonePayment\Payone\Request\Eps\EpsAuthorizeRequestFactory">
<argument type="service" id="PayonePayment\Payone\Request\Eps\EpsAuthorizeRequest" />
<argument type="service" id="PayonePayment\Payone\Request\Customer\CustomerRequest" />
<argument type="service" id="PayonePayment\Payone\Request\System\SystemRequest" />
</service>

<service id="PayonePayment\Payone\Request\Eps\EpsPreAuthorizeRequestFactory">
<argument type="service" id="PayonePayment\Payone\Request\Eps\EpsPreAuthorizeRequest" />
<argument type="service" id="PayonePayment\Payone\Request\Customer\CustomerRequest" />
<argument type="service" id="PayonePayment\Payone\Request\System\SystemRequest" />
</service>

<!-- iDeal Banking -->
<service id="PayonePayment\Payone\Request\IDeal\IDealAuthorizeRequest">
<argument type="service" id="PayonePayment\Components\RedirectHandler\RedirectHandler" />
Expand Down
85 changes: 85 additions & 0 deletions src/EventListener/CheckoutConfirmEpsEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

namespace PayonePayment\EventListener;

use PayonePayment\PaymentMethod\PayoneEps;
use Shopware\Core\Checkout\Payment\PaymentMethodCollection;
use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoadedEvent;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* This event listener removes the EPS payment method for customers
* which have a billing address that is outside from AT.
*/
class CheckoutConfirmEpsEventListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
CheckoutConfirmPageLoadedEvent::class => 'hideEpsForNonAtCustomers',
AccountPaymentMethodPageLoadedEvent::class => 'hideEpsForNonAtCustomers',
];
}

/**
* @param AccountPaymentMethodPageLoadedEvent|CheckoutConfirmPageLoadedEvent $event
*/
public function hideEpsForNonAtCustomers($event): void
{
$paymentMethods = $event->getPage()->getPaymentMethods();

if (
$this->isEuroCurrency($event->getSalesChannelContext()) &&
$this->isAtCustomer($event->getSalesChannelContext())
) {
return;
}

$paymentMethods = $this->removePaymentMethod($paymentMethods, PayoneEps::UUID);
$event->getPage()->setPaymentMethods($paymentMethods);
}

/**
* Returns whether or not the currency is EUR.
*/
private function isEuroCurrency(SalesChannelContext $context): bool
{
return $context->getCurrency()->getIsoCode() === 'EUR';
}

/**
* Returns whether or not the customer's billing address
* is inside AT or not. Or false if no customer or billing
* address is given.
*/
private function isAtCustomer(SalesChannelContext $context): bool
{
$customer = $context->getCustomer();

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

$billingAddress = $customer->getActiveBillingAddress();

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

return $billingAddress->getCountry()->getIso() === 'AT';
}

private function removePaymentMethod(PaymentMethodCollection $paymentMethods, string $paymentMethodId): PaymentMethodCollection
{
return $paymentMethods->filter(
static function (PaymentMethodEntity $paymentMethod) use ($paymentMethodId) {
return $paymentMethod->getId() !== $paymentMethodId;
}
);
}
}
2 changes: 2 additions & 0 deletions src/Installer/PaymentMethodInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PayonePayment\PaymentMethod\PaymentMethodInterface;
use PayonePayment\PaymentMethod\PayoneCreditCard;
use PayonePayment\PaymentMethod\PayoneDebit;
use PayonePayment\PaymentMethod\PayoneEps;
use PayonePayment\PaymentMethod\PayoneIDeal;
use PayonePayment\PaymentMethod\PayonePayolutionDebit;
use PayonePayment\PaymentMethod\PayonePayolutionInstallment;
Expand Down Expand Up @@ -38,6 +39,7 @@ class PaymentMethodInstaller implements InstallerInterface
PayonePayolutionInvoicing::class,
PayonePayolutionDebit::class,
PayoneSofortBanking::class,
PayoneEps::class,
PayoneIDeal::class,
];

Expand Down
Loading

0 comments on commit 0832e86

Please sign in to comment.