Skip to content

Commit

Permalink
Merge pull request #42 from p1fb/SW6-43-ideal-payment-integration
Browse files Browse the repository at this point in the history
SW6-43: Integrate iDeal Payment
  • Loading branch information
hreinberger authored Jun 30, 2020
2 parents 396b94b + 3ca1155 commit 1048f4e
Show file tree
Hide file tree
Showing 24 changed files with 699 additions and 5 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\PayoneIDealPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionDebitPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInstallmentPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInvoicingPaymentHandler;
Expand All @@ -23,6 +24,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_IDEAL = 'iDeal';

public const CONFIGURATION_PREFIXES = [
PayoneCreditCardPaymentHandler::class => self::CONFIGURATION_PREFIX_CREDITCARD,
Expand All @@ -33,5 +35,6 @@ interface ConfigurationPrefixes
PayonePayolutionInstallmentPaymentHandler::class => self::CONFIGURATION_PREFIX_PAYOLUTION_INSTALLMENT,
PayonePayolutionDebitPaymentHandler::class => self::CONFIGURATION_PREFIX_PAYOLUTION_DEBIT,
PayoneSofortBankingPaymentHandler::class => self::CONFIGURATION_PREFIX_SOFORT,
PayoneIDealPaymentHandler::class => self::CONFIGURATION_PREFIX_IDEAL,
];
}
2 changes: 1 addition & 1 deletion src/Controller/RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(RedirectHandler $redirectHandler)

/**
* @RouteScope(scopes={"storefront"})
* @Route("/payone/redirect", name="payone_redirect")
* @Route("/payone/redirect", name="payone_redirect", defaults={"csrf_protected": false})
*/
public function execute(Request $request): Response
{
Expand Down
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\PayoneIDealPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionDebitPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInstallmentPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInvoicingPaymentHandler;
Expand Down Expand Up @@ -204,6 +205,22 @@ private function getPaymentParameters(string $paymentClass): array
'successurl' => 'https://www.payone.com',
];

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

break;
case PayonePayolutionInvoicingPaymentHandler::class:
return [
Expand Down
12 changes: 12 additions & 0 deletions src/DependencyInjection/handler/payment_handler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,17 @@

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

<service id="PayonePayment\PaymentHandler\PayoneIDealPaymentHandler">
<argument type="service" id="PayonePayment\Components\ConfigReader\ConfigReader" />
<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" />
<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 @@ -51,5 +51,9 @@

<tag name="kernel.event_subscriber"/>
</service>

<service id="PayonePayment\EventListener\CheckoutConfirmIDealEventListener">
<tag name="kernel.event_subscriber"/>
</service>
</services>
</container>
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>

<!-- iDeal Banking -->
<service id="PayonePayment\Payone\Request\IDeal\IDealAuthorizeRequest">
<argument type="service" id="PayonePayment\Components\RedirectHandler\RedirectHandler" />
<argument type="service" id="currency.repository" />
</service>

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

<service id="PayonePayment\Payone\Request\IDeal\IDealAuthorizeRequestFactory">
<argument type="service" id="PayonePayment\Payone\Request\IDeal\IDealAuthorizeRequest" />
<argument type="service" id="PayonePayment\Payone\Request\Customer\CustomerRequest" />
<argument type="service" id="PayonePayment\Payone\Request\System\SystemRequest" />
</service>

<service id="PayonePayment\Payone\Request\IDeal\IDealPreAuthorizeRequestFactory">
<argument type="service" id="PayonePayment\Payone\Request\IDeal\IDealPreAuthorizeRequest" />
<argument type="service" id="PayonePayment\Payone\Request\Customer\CustomerRequest" />
<argument type="service" id="PayonePayment\Payone\Request\System\SystemRequest" />
</service>

<!-- ManageMandate -->
<service id="PayonePayment\Payone\Request\ManageMandate\ManageMandateRequest">
<argument type="service" id="currency.repository" />
Expand Down
85 changes: 85 additions & 0 deletions src/EventListener/CheckoutConfirmIDealEventListener.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\PayoneIDeal;
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 iDeal payment method for customers
* which have a billing address that is outside from NL.
*/
class CheckoutConfirmIDealEventListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
CheckoutConfirmPageLoadedEvent::class => 'hideIDealForNonNlCustomers',
AccountPaymentMethodPageLoadedEvent::class => 'hideIDealForNonNlCustomers',
];
}

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

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

$paymentMethods = $this->removePaymentMethod($paymentMethods, PayoneIDeal::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 NL or not. Or false if no customer or billing
* address is given.
*/
private function isNlCustomer(SalesChannelContext $context): bool
{
$customer = $context->getCustomer();

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

$billingAddress = $customer->getActiveBillingAddress();

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

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

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\PayoneIDeal;
use PayonePayment\PaymentMethod\PayonePayolutionDebit;
use PayonePayment\PaymentMethod\PayonePayolutionInstallment;
use PayonePayment\PaymentMethod\PayonePayolutionInvoicing;
Expand Down Expand Up @@ -37,6 +38,7 @@ class PaymentMethodInstaller implements InstallerInterface
PayonePayolutionInvoicing::class,
PayonePayolutionDebit::class,
PayoneSofortBanking::class,
PayoneIDeal::class,
];

/** @var PluginIdProvider */
Expand Down
Loading

0 comments on commit 1048f4e

Please sign in to comment.