-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAYOSWXP-115: generic-express: prevent changing addresses/payment-met…
…hod and add back-link
- Loading branch information
1 parent
eac0da5
commit e522438
Showing
15 changed files
with
180 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Components/PaymentFilter/GenericExpressCheckoutFilterOther.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\PaymentFilter; | ||
|
||
use PayonePayment\PaymentHandler\PaymentHandlerGroups; | ||
use Shopware\Core\Checkout\Payment\PaymentMethodCollection; | ||
|
||
class GenericExpressCheckoutFilterOther implements PaymentFilterServiceInterface | ||
{ | ||
/** | ||
* if AmazonPay/PayPal Express is selected, no other payment methods should be available. | ||
*/ | ||
public function filterPaymentMethods(PaymentMethodCollection $methodCollection, PaymentFilterContext $filterContext): PaymentMethodCollection | ||
{ | ||
$actualPaymentMethod = $filterContext->getSalesChannelContext()->getPaymentMethod(); | ||
|
||
if ($methodCollection->has($actualPaymentMethod->getId()) | ||
&& \in_array($actualPaymentMethod->getHandlerIdentifier(), PaymentHandlerGroups::GENERIC_EXPRESS, true) | ||
) { | ||
return new PaymentMethodCollection([$actualPaymentMethod]); | ||
} | ||
|
||
return $methodCollection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/EventListener/CheckoutConfirmGenericExpressCheckoutEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\EventListener; | ||
|
||
use PayonePayment\PaymentHandler\PaymentHandlerGroups; | ||
use PayonePayment\Storefront\Struct\CheckoutConfirmPaymentData; | ||
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class CheckoutConfirmGenericExpressCheckoutEventListener implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmLoaded', | ||
]; | ||
} | ||
|
||
public function onCheckoutConfirmLoaded(CheckoutConfirmPageLoadedEvent $event): void | ||
{ | ||
$paymentMethod = $event->getSalesChannelContext()->getPaymentMethod(); | ||
if (\in_array($paymentMethod->getHandlerIdentifier(), PaymentHandlerGroups::GENERIC_EXPRESS, true) === false) { | ||
// payment handler is not a generic express-checkout | ||
return; | ||
} | ||
|
||
$extension = $event->getPage()->getExtension(CheckoutConfirmPaymentData::EXTENSION_NAME) ?? new CheckoutConfirmPaymentData(); | ||
$extension->assign([ | ||
'showExitExpressCheckoutLink' => true, | ||
'preventAddressEdit' => true, | ||
]); | ||
$event->getPage()->addExtension(CheckoutConfirmPaymentData::EXTENSION_NAME, $extension); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Resources/views/storefront/page/checkout/confirm/confirm-address.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% sw_extends '@Storefront/storefront/page/checkout/confirm/confirm-address.html.twig' %} | ||
|
||
{% block page_checkout_confirm_address_shipping_actions %} | ||
{% if not page.extensions.payone or not page.extensions.payone.preventAddressEdit %} | ||
{{ parent() }} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block page_checkout_confirm_address_billing_actions %} | ||
{% if not page.extensions.payone or not page.extensions.payone.preventAddressEdit %} | ||
{{ parent() }} | ||
{% endif %} | ||
{% endblock %} |
14 changes: 14 additions & 0 deletions
14
src/Resources/views/storefront/page/checkout/confirm/confirm-payment.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% sw_extends '@Storefront/storefront/page/checkout/confirm/confirm-payment.html.twig' %} | ||
|
||
{% block page_checkout_change_payment_form %} | ||
{{ parent() }} | ||
|
||
{% block page_checkout_change_payment_form_payone_back_to_standard_checkout %} | ||
{% if page.extensions.payone and page.extensions.payone.showExitExpressCheckoutLink|default(false) %} | ||
<div class="card-actions"> | ||
<a href="{{ url('frontend.payone.delete-checkout-data') }}">{{ 'PayonePayment.checkoutConfirmPage.back-to-standard-checkout' | trans }}</a> | ||
</div> | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Storefront\Controller; | ||
|
||
use PayonePayment\Storefront\Struct\CheckoutCartPaymentData; | ||
use Shopware\Core\Checkout\Cart\SalesChannel\CartService; | ||
use Shopware\Core\System\SalesChannel\SalesChannelContext; | ||
use Shopware\Storefront\Controller\StorefrontController; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
#[Route(defaults: ['_routeScope' => ['storefront']])] | ||
class CheckoutController | ||
{ | ||
public function __construct( | ||
private readonly CartService $cartService, | ||
private readonly RouterInterface $router, | ||
private readonly TranslatorInterface $translator | ||
) { | ||
} | ||
|
||
#[Route(path: '/payone/delete-checkout-data', name: 'frontend.payone.delete-checkout-data')] | ||
public function deleteCheckoutData( | ||
Request $request, | ||
SalesChannelContext $salesChannelContext | ||
): Response { | ||
$cart = $this->cartService->getCart($salesChannelContext->getToken(), $salesChannelContext); | ||
$cart->removeExtension(CheckoutCartPaymentData::EXTENSION_NAME); | ||
$this->cartService->recalculate($cart, $salesChannelContext); | ||
|
||
$session = $request->getSession(); | ||
if (method_exists($session, 'getFlashBag')) { | ||
$session->getFlashBag()->add( | ||
StorefrontController::SUCCESS, | ||
$this->translator->trans('PayonePayment.checkoutConfirmPage.express-checkout-canceled') | ||
); | ||
} | ||
|
||
return new RedirectResponse($this->router->generate('frontend.checkout.confirm.page')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters