From 14327ed6cb7fea9923676d46f296f9a762abcf3f Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Mon, 27 May 2024 14:37:31 +0200 Subject: [PATCH] NTR: PISHPW-221: remove ideal dropdown --- .phpstan.lvl8.neon | 6 - Components/Services/PaymentService.php | 25 +-- Components/iDEAL/iDEAL.php | 111 ------------ Components/iDEAL/iDEALInterface.php | 28 --- Controllers/Frontend/Mollie.php | 49 +---- Gateways/Mollie/MollieGateway.php | 25 --- Gateways/MollieGatewayInterface.php | 6 +- Resources/services/subscriber.xml | 7 +- .../frontend/plugins/payment/mollie_ideal.tpl | 12 -- Subscriber/IdealIssuersSubscriber.php | 170 ------------------ .../e2e/storefront/payments/ideal.cy.js | 30 ---- .../Subscriber/iDealSubscriberTest.php | 25 --- .../Utils/Fakes/Gateway/FakeMollieGateway.php | 7 - 13 files changed, 7 insertions(+), 494 deletions(-) delete mode 100644 Components/iDEAL/iDEAL.php delete mode 100644 Components/iDEAL/iDEALInterface.php delete mode 100644 Resources/views/frontend/plugins/payment/mollie_ideal.tpl delete mode 100644 Subscriber/IdealIssuersSubscriber.php delete mode 100644 Tests/PHPUnit/Subscriber/iDealSubscriberTest.php diff --git a/.phpstan.lvl8.neon b/.phpstan.lvl8.neon index 94df2c56..12c1013d 100644 --- a/.phpstan.lvl8.neon +++ b/.phpstan.lvl8.neon @@ -2,7 +2,6 @@ parameters: level: 8 paths: - ./Command/OrdersShippingCommand.php - - ./Components/iDEAL - ./Components/Config - ./Exceptions - ./Services @@ -16,11 +15,6 @@ parameters: # ignore Shopware attributes with magic getters and setters - '#Call to method getMollieReturn\(\) on an unknown class Shopware\\Models\\Attribute\\OrderDetail#' - '#Call to method setMollieReturn\(\) on an unknown class Shopware\\Models\\Attribute\\OrderDetail#' - - '#Call to method getMollieShopwareIdealIssuer\(\) on an unknown class Shopware\\Models\\Attribute\\Customer#' - - '#Call to method setMollieShopwareIdealIssuer\(\) on an unknown class Shopware\\Models\\Attribute\\Customer#' - # ----------------------------------------------------------------------------------------------------------- - # ignore magic getters and setters in Mollie API objects - - '#Access to an undefined property Mollie\\Api\\Resources\\Issuer::\$isSelected#' # ----------------------------------------------------------------------------------------------------------- services: diff --git a/Components/Services/PaymentService.php b/Components/Services/PaymentService.php index fb72da7e..7c8f4dbc 100644 --- a/Components/Services/PaymentService.php +++ b/Components/Services/PaymentService.php @@ -15,7 +15,7 @@ use MollieShopware\Components\Constants\PaymentMethodType; use MollieShopware\Components\Constants\PaymentStatus; use MollieShopware\Components\CurrentCustomer; -use MollieShopware\Components\iDEAL\iDEALInterface; + use MollieShopware\Components\Mollie\Builder\MolliePaymentBuilder; use MollieShopware\Components\Mollie\MollieShipping; use MollieShopware\Components\Mollie\Services\TransactionUUID\TransactionUUID; @@ -121,10 +121,7 @@ class PaymentService */ private $applePayFactory; - /** - * @var iDEALInterface $idealService - */ - private $idealService; + /** * @var CurrentCustomer @@ -233,7 +230,7 @@ public function startMollieSession($paymentMethodName, Transaction $transaction, # a shop service is somewhere used in there... $this->creditCardService = Shopware()->Container()->get('mollie_shopware.credit_card_service'); $this->applePayFactory = Shopware()->Container()->get('mollie_shopware.components.apple_pay_direct.factory'); - $this->idealService = Shopware()->Container()->get('mollie_shopware.ideal_service'); + $this->customer = Shopware()->Container()->get('mollie_shopware.customer'); $shopID = Shopware()->Shop()->getId(); @@ -632,22 +629,6 @@ private function configurePaymentSettings(PaymentInterface $paymentMethodObject, } - if ($paymentMethodObject instanceof IDeal) { - # test if we have a current customer (we should have one) - # if so, get his selected iDeal issuer. - # if an issuer has been set, then also use it for our payment, - # otherwise just continue without a prefilled issuer. - $currentCustomer = $this->customer->getCurrent(); - - if ($currentCustomer instanceof Customer) { - $issuer = $this->idealService->getCustomerIssuer($currentCustomer); - if (!empty($issuer)) { - /** @var IDeal $paymentMethodObject */ - $paymentMethodObject->setIssuer($issuer); - } - } - } - if ($paymentMethodObject instanceof CreditCard) { # prevent this method from failing, because at this # point we're not sure if the credit card token diff --git a/Components/iDEAL/iDEAL.php b/Components/iDEAL/iDEAL.php deleted file mode 100644 index 43d3ca90..00000000 --- a/Components/iDEAL/iDEAL.php +++ /dev/null @@ -1,111 +0,0 @@ -gwMollie = $mollieGateway; - $this->modelManager = $modelManager; - } - - /** - * @return Issuer[] - */ - public function getIssuers(Customer $customer) - { - /** @var Issuer[] $issuers */ - $issuers = $this->gwMollie->getIdealIssuers(); - - # we have to iterate through all issuers - # and mark the currently selected one also - # as selected within the list - $customerIssuer = $this->getCustomerIssuer($customer); - - foreach ($issuers as &$issuer) { - if ($issuer->id === $customerIssuer) { - $issuer->isSelected = true; - break; - } - } - - return $issuers; - } - - /** - * @param Customer $customer - * @return string - */ - public function getCustomerIssuer(Customer $customer) - { - $attributes = $customer->getAttribute(); - - if (!empty($attributes)) { - return (string)$attributes->getMollieShopwareIdealIssuer(); - } - - $sql = 'SELECT s_user_attributes.mollie_shopware_ideal_issuer - FROM s_user - JOIN s_user_attributes ON (s_user.id = s_user_attributes.userID) - WHERE s_user.customernumber = ? - AND s_user_attributes.mollie_shopware_ideal_issuer IS NOT NULL - LIMIT 1'; - - /** - * In B2b a contact customer doesn't have attributes, - * so take the attributes of the debtor user it belongs to - */ - $issuer = $this->modelManager->getConnection()->fetchColumn($sql, [$customer->getNumber()]); - - if (empty($issuer)) { - return ''; - } - - return $issuer; - } - - /** - * @param Customer $customer - * @param string $issuer - * @throws \Doctrine\ORM\OptimisticLockException - * @throws \Doctrine\ORM\ORMException - * @return void - */ - public function updateCustomerIssuer(Customer $customer, $issuer) - { - $attributes = $customer->getAttribute(); - - if (empty($attributes)) { - return; - } - - $attributes->setMollieShopwareIdealIssuer($issuer); - - $this->modelManager->persist($attributes); - $this->modelManager->flush($attributes); - } -} diff --git a/Components/iDEAL/iDEALInterface.php b/Components/iDEAL/iDEALInterface.php deleted file mode 100644 index 7cd7735b..00000000 --- a/Components/iDEAL/iDEALInterface.php +++ /dev/null @@ -1,28 +0,0 @@ -redirectToShopwareCheckoutFailed($this); } - /** - * Get the issuers for the iDEAL payment method. - * Called in an ajax call on the frontend. - */ - public function idealIssuersAction() - { - Shopware()->Plugins()->Controller()->ViewRenderer()->setNoRender(); - - try { - $this->loadServices(); - - $customer = $this->customers->getCurrent(); - - if (!$customer instanceof Customer) { - throw new \Exception('No active customer found for iDEAL AJAX list'); - } - - /** @var array $idealIssuers */ - $idealIssuers = $this->iDEAL->getIssuers($customer); - - $this->sendResponse([ - 'data' => $idealIssuers, - 'success' => true, - ]); - } catch (\Exception $ex) { - $this->logger->error( - 'Error iDEAL issuer AJAX action.', - [ - 'error' => $ex->getMessage(), - ] - ); - - $this->sendResponse( - [ - 'message' => $ex->getMessage(), - 'success' => false - ], - 500 - ); - } - } /** * @@ -589,7 +544,7 @@ private function loadServices() $paymentService = Shopware()->Container()->get('mollie_shopware.payment_service'); $orderService = Shopware()->Container()->get('mollie_shopware.order_service'); - $this->iDEAL = $this->container->get('mollie_shopware.components.ideal'); + $this->customers = $this->container->get('mollie_shopware.customer'); diff --git a/Gateways/Mollie/MollieGateway.php b/Gateways/Mollie/MollieGateway.php index a8cc25fd..4508ab4c 100644 --- a/Gateways/Mollie/MollieGateway.php +++ b/Gateways/Mollie/MollieGateway.php @@ -128,31 +128,6 @@ public function getPayment($paymentId) return $payment; } - /** - * @throws \Mollie\Api\Exceptions\ApiException - * @return Issuer[] - */ - public function getIdealIssuers() - { - $paymentMethods = $this->apiClient->methods->allActive( - [ - 'include' => 'issuers' - ] - ); - - $issuers = []; - - foreach ($paymentMethods as $paymentMethod) { - if ($paymentMethod->id === PaymentMethod::IDEAL) { - foreach ($paymentMethod->issuers() as $key => $issuer) { - $issuers[] = $issuer; - } - break; - } - } - - return $issuers; - } /** * @param array $requestData diff --git a/Gateways/MollieGatewayInterface.php b/Gateways/MollieGatewayInterface.php index 44236d7a..eb46646b 100644 --- a/Gateways/MollieGatewayInterface.php +++ b/Gateways/MollieGatewayInterface.php @@ -3,7 +3,6 @@ namespace MollieShopware\Gateways; use Mollie\Api\MollieApiClient; -use Mollie\Api\Resources\Issuer; use Mollie\Api\Resources\Order; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Shipment; @@ -38,10 +37,7 @@ public function getOrder($orderId); */ public function getPayment($paymentId); - /** - * @return Issuer[] - */ - public function getIdealIssuers(); + /** * @param array $requestData diff --git a/Resources/services/subscriber.xml b/Resources/services/subscriber.xml index f2154ad9..b7a8c10f 100644 --- a/Resources/services/subscriber.xml +++ b/Resources/services/subscriber.xml @@ -14,12 +14,7 @@ - - - - - - + diff --git a/Resources/views/frontend/plugins/payment/mollie_ideal.tpl b/Resources/views/frontend/plugins/payment/mollie_ideal.tpl deleted file mode 100644 index 9a3c5240..00000000 --- a/Resources/views/frontend/plugins/payment/mollie_ideal.tpl +++ /dev/null @@ -1,12 +0,0 @@ -{namespace name='frontend/plugins/payment/mollie_ideal'} - -

{s name="PluginsIdealHeadline" namespace="frontend/mollie/plugins"}Select iDEAL issuer{/s}

- -
- -
diff --git a/Subscriber/IdealIssuersSubscriber.php b/Subscriber/IdealIssuersSubscriber.php deleted file mode 100644 index 68b3a03c..00000000 --- a/Subscriber/IdealIssuersSubscriber.php +++ /dev/null @@ -1,170 +0,0 @@ -iDeal = $iDEAL; - $this->customers = $customers; - $this->logger = $logger; - } - - /** - * @return string[] - */ - public static function getSubscribedEvents() - { - return [ - 'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => 'onCheckoutPaymentPage', - 'Enlight_Controller_Action_PostDispatchSecure_Frontend_Account' => 'onAccountPaymentPage', - # ------------------------------------------------------------------------------------------------- - 'Shopware_Modules_Admin_UpdatePayment_FilterSql' => 'onUpdatePaymentForUser', - ]; - } - - /** - * @param \Enlight_Event_EventArgs $args - */ - public function onCheckoutPaymentPage(\Enlight_Event_EventArgs $args) - { - /** @var Enlight_Controller_Request_RequestHttp $request */ - $request = $args->get('request'); - - if ($request->getActionName() === 'shippingPayment') { - $this->loadPaymentPageData($args); - } - } - - /** - * @param \Enlight_Event_EventArgs $args - */ - public function onAccountPaymentPage(\Enlight_Event_EventArgs $args) - { - /** @var Enlight_Controller_Request_RequestHttp $request */ - $request = $args->get('request'); - - if ($request->getActionName() === 'payment') { - $this->loadPaymentPageData($args); - } - } - - /** - * When a payment method is changed, the chosen payment method is saved on the user - * For iDEAL an issuer should also be saved to the database. - * - * @param \Enlight_Event_EventArgs $args - * @throws \Exception - * @return mixed - */ - public function onUpdatePaymentForUser(\Enlight_Event_EventArgs $args) - { - $query = $args->getReturn(); - - $this->updateSelectedIssuer(); - - return $query; - } - - /** - * @param \Enlight_Event_EventArgs $args - */ - private function loadPaymentPageData(\Enlight_Event_EventArgs $args) - { - /** @var \Enlight_Controller_Action $controller */ - $controller = $args->getSubject(); - - /** @var \Enlight_View $view */ - $view = $controller->View(); - - $view->addTemplateDir(__DIR__ . '/../Resources/views'); - - try { - $customer = $this->customers->getCurrent(); - - if (!$customer instanceof Customer) { - throw new \Exception('No active customer found for iDEAL list'); - } - - $idealIssuers = $this->iDeal->getIssuers($customer); - - # always update our selected issuer - # if the page is rendered, we update the - # used issuer in the database for the user - $this->updateSelectedIssuer(); - - $view->assign('mollieIdealIssuers', $idealIssuers); - $view->assign('mollieIssues', false); - } catch (\Exception $ex) { - $this->logger->error( - 'Error when loading iDEAL issuers for payment screen!', - [ - 'error' => $ex->getMessage(), - ] - ); - - $view->assign('mollieIdealIssuers', []); - $view->assign('mollieIssues', true); - } - } - - /** - * @throws \Exception - */ - private function updateSelectedIssuer() - { - try { - $issuer = (string)Shopware()->Front()->Request()->getPost('mollie-ideal-issuer'); - - if (empty($issuer)) { - return; - } - - $customer = $this->customers->getCurrent(); - - if ($customer instanceof Customer) { - $this->iDeal->updateCustomerIssuer($customer, $issuer); - } - } catch (\Exception $ex) { - $this->logger->error( - 'Error when updating selected iDeal issuer for customer!', - [ - 'error' => $ex->getMessage(), - ] - ); - - throw $ex; - } - } -} diff --git a/Tests/Cypress/cypress/e2e/storefront/payments/ideal.cy.js b/Tests/Cypress/cypress/e2e/storefront/payments/ideal.cy.js index fc9d134a..7c2d37f4 100644 --- a/Tests/Cypress/cypress/e2e/storefront/payments/ideal.cy.js +++ b/Tests/Cypress/cypress/e2e/storefront/payments/ideal.cy.js @@ -34,37 +34,7 @@ describe('iDEAL Issuers', () => { payments.selectPayment('iDEAL'); - // now verify that we have an existing list - // of issuers by simply selecting one of them - payments.selectIDealIssuer('bunq'); }) - it('C4237: iDEAL (XHR) Issuer List can only be retrieved for signed in users', () => { - - // we start the request and make sure - // that we get a 500 error - cy.request({ - url: '/Mollie/idealIssuers', - failOnStatusCode: false, - }).then((resp) => { - expect(resp.status).to.eq(500); - }) - - - register.doRegister("dev@localhost.de", "MollieMollie111", 'Mollie', 'Mollie'); - login.doLogin("dev@localhost.de", "MollieMollie111"); - - // we start the request - // and make sure that we have a 200 status code - // and at least 1 found issuer. - cy.request({ - url: '/Mollie/idealIssuers', - failOnStatusCode: false, - }).then((resp) => { - expect(resp.status).to.eq(200); - expect(resp.body.data.length).to.be.at.least(1); - - }) - }) }) diff --git a/Tests/PHPUnit/Subscriber/iDealSubscriberTest.php b/Tests/PHPUnit/Subscriber/iDealSubscriberTest.php deleted file mode 100644 index b1f4a691..00000000 --- a/Tests/PHPUnit/Subscriber/iDealSubscriberTest.php +++ /dev/null @@ -1,25 +0,0 @@ -assertEquals($expected, array_keys(IdealIssuersSubscriber::getSubscribedEvents())); - } -} diff --git a/Tests/PHPUnit/Utils/Fakes/Gateway/FakeMollieGateway.php b/Tests/PHPUnit/Utils/Fakes/Gateway/FakeMollieGateway.php index e03e09c3..9cc68a48 100644 --- a/Tests/PHPUnit/Utils/Fakes/Gateway/FakeMollieGateway.php +++ b/Tests/PHPUnit/Utils/Fakes/Gateway/FakeMollieGateway.php @@ -132,13 +132,6 @@ public function getPayment($paymentId): Payment return new Payment(null); } - /** - * @return array - */ - public function getIdealIssuers(): array - { - return []; - } /** * @param $mollieId