From c03b4ec8be6060f69137c5a03b75b24ca3fc493d Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Thu, 26 Oct 2023 12:05:01 +0200 Subject: [PATCH] Bugfix: Set a default for the issuer list type #710 --- .github/workflows/end-2-end-test.yml | 2 + Config.php | 16 + Helper/General.php | 4 +- Model/MollieConfigProvider.php | 2 +- Service/Mollie/GetIssuers.php | 12 +- .../e2e/magento/graphql/place-order.cy.js | 50 ++ .../cypress/fixtures/mollie-pwa.html | 834 ++++++++++++++++++ .../support/pages/backend/OrdersPage.js | 13 + 8 files changed, 925 insertions(+), 8 deletions(-) create mode 100644 Test/End-2-end/cypress/e2e/magento/graphql/place-order.cy.js create mode 100644 Test/End-2-end/cypress/fixtures/mollie-pwa.html diff --git a/.github/workflows/end-2-end-test.yml b/.github/workflows/end-2-end-test.yml index 43455ac0f36..14ff4a960e1 100644 --- a/.github/workflows/end-2-end-test.yml +++ b/.github/workflows/end-2-end-test.yml @@ -76,10 +76,12 @@ jobs: MAGENTO_URL=$(docker exec magento-project-community-edition /bin/bash -c "curl -s ngrok:4040/api/tunnels |jq -r \".tunnels[0].public_url\"") echo "magento_url=$MAGENTO_URL" >> $GITHUB_ENV + # Note the `mollie-pwa.html` file, as it is copied to the pub folder. This is so that it can be accessed by Cypress. - name: Upload the code into the docker container run: | sed -i '/version/d' ./composer.json && \ docker cp $(pwd) magento-project-community-edition:/data/extensions/ && \ + docker cp $(pwd)/Test/End-2-end/cypress/fixtures/mollie-pwa.html magento-project-community-edition:/data/pub/opt/ && \ docker exec magento-project-community-edition ./install-composer-package mollie/magento2:@dev - name: Activate the extension diff --git a/Config.php b/Config.php index 9fcb87b2724..0a2bf109633 100644 --- a/Config.php +++ b/Config.php @@ -58,6 +58,7 @@ class Config const PAYMENT_CREDITCARD_USE_COMPONENTS = 'payment/mollie_methods_creditcard/use_components'; const PAYMENT_CREDITCARD_ENABLE_CUSTOMERS_API = 'payment/mollie_methods_creditcard/enable_customers_api'; const PAYMENT_BANKTRANSFER_STATUS_PENDING = 'payment/mollie_methods_banktransfer/order_status_pending'; + const PAYMENT_METHOD_ISSUER_LIST_TYPE = 'payment/mollie_methods_%s/issuer_list_type'; const PAYMENT_METHOD_PAYMENT_ACTIVE = 'payment/mollie_methods_%s/active'; const PAYMENT_METHOD_PAYMENT_DESCRIPTION = 'payment/mollie_methods_%s/payment_description'; const PAYMENT_METHOD_PAYMENT_SURCHARGE_FIXED_AMOUNT = 'payment/mollie_methods_%s/payment_surcharge_fixed_amount'; @@ -73,6 +74,7 @@ class Config const PAYMENT_VOUCHER_CUSTOM_ATTRIBUTE = 'payment/mollie_methods_voucher/custom_attribute'; const CURRENCY_OPTIONS_DEFAULT = 'currency/options/default'; + /** * @var ScopeConfigInterface */ @@ -726,6 +728,20 @@ public function encryptPaymentDetails($storeId = null): bool return $this->isSetFlag(static::GENERAL_ENCRYPT_PAYMENT_DETAILS, $storeId); } + /** + * @param string $method + * @param null|int|string $storeId + * + * @return string + */ + public function getIssuerListType(string $method, $storeId = null): string + { + return $this->getPath( + $this->addMethodToPath(static::PAYMENT_METHOD_ISSUER_LIST_TYPE, $method), + $storeId + ) ?? 'none'; + } + /** * @param $method * @return string diff --git a/Helper/General.php b/Helper/General.php index 06945c89d3b..36683d2556e 100755 --- a/Helper/General.php +++ b/Helper/General.php @@ -380,6 +380,8 @@ public function useImage($storeId = null) } /** + * @deprecated See \Mollie\Payment\Config::getIssuerListType instead + * * @param string $method * * @return mixed @@ -387,7 +389,7 @@ public function useImage($storeId = null) public function getIssuerListType(string $method): string { $methodXpath = str_replace('%method%', $method, self::XPATH_ISSUER_LIST_TYPE); - return $this->getStoreConfig($methodXpath); + return $this->getStoreConfig($methodXpath) ?? 'none'; } /** diff --git a/Model/MollieConfigProvider.php b/Model/MollieConfigProvider.php index bb9797195e6..3efe02cc6ad 100644 --- a/Model/MollieConfigProvider.php +++ b/Model/MollieConfigProvider.php @@ -263,7 +263,7 @@ public function getActiveMethods(MollieApiClient $mollieApi, CartInterface $cart */ private function getIssuers(MollieApiClient $mollieApi, string $code, array $config): array { - $issuerListType = $this->mollieHelper->getIssuerListType($code); + $issuerListType = $this->config->getIssuerListType($code, $this->storeManager->getStore()->getId()); $config['payment']['issuersListType'][$code] = $issuerListType; $config['payment']['issuers'][$code] = $this->getIssuers->execute($mollieApi, $code, $issuerListType); diff --git a/Service/Mollie/GetIssuers.php b/Service/Mollie/GetIssuers.php index 25a3f0986dc..d9259c5ff71 100644 --- a/Service/Mollie/GetIssuers.php +++ b/Service/Mollie/GetIssuers.php @@ -10,6 +10,7 @@ use Magento\Framework\Serialize\SerializerInterface; use Magento\Framework\Locale\Resolver; use Mollie\Api\MollieApiClient; +use Mollie\Payment\Config; use Mollie\Payment\Helper\General; use Mollie\Payment\Model\Mollie as MollieModel; @@ -36,24 +37,23 @@ class GetIssuers * @var Resolver */ private $resolver; - /** - * @var General + * @var Config */ - private $general; + private $config; public function __construct( CacheInterface $cache, SerializerInterface $serializer, MollieModel $mollieModel, Resolver $resolver, - General $general + Config $config ) { $this->cache = $cache; $this->serializer = $serializer; $this->mollieModel = $mollieModel; $this->resolver = $resolver; - $this->general = $general; + $this->config = $config; } /** @@ -106,7 +106,7 @@ public function getForGraphql($storeId, string $method): ?array $issuers = $this->execute( $mollieApi, $method, - $this->general->getIssuerListType($method) + $this->config->getIssuerListType($method) ); if (!$issuers) { diff --git a/Test/End-2-end/cypress/e2e/magento/graphql/place-order.cy.js b/Test/End-2-end/cypress/e2e/magento/graphql/place-order.cy.js new file mode 100644 index 00000000000..b4251d1c255 --- /dev/null +++ b/Test/End-2-end/cypress/e2e/magento/graphql/place-order.cy.js @@ -0,0 +1,50 @@ +/* + * Copyright Magmodules.eu. All rights reserved. + * See COPYING.txt for license details. + */ + +import Cookies from "Services/Cookies"; +import MollieHostedPaymentPage from "Pages/mollie/MollieHostedPaymentPage"; +import CheckoutSuccessPage from "Pages/frontend/CheckoutSuccessPage"; +import OrdersPage from "Pages/backend/OrdersPage"; + +const cookies = new Cookies(); +const mollieHostedPaymentPage = new MollieHostedPaymentPage(); +const checkoutSuccessPage = new CheckoutSuccessPage(); +const ordersPage = new OrdersPage(); + +describe('Check that the headless endpoints work as expected', () => { + it('C1835263: Validate that an order can be placed through GraphQL ', () => { + cy.visit('opt/mollie-pwa.html'); + + cy.get('[data-key="start-checkout-process"]').click(); + + cy.get('[data-key="mollie_methods_ideal"]').click(); + + cy.get('[data-key="mollie_methods_ideal-issuer"]').first().click(); + + cy.get('[data-key="place-order-action"]').click(); + + cy.get('[data-key="increment-id"]').then((element) => { + cy.wrap(element.text()).as('increment-id'); + }); + + cookies.disableSameSiteCookieRestrictions(); + + cy.get('[data-key="redirect-url"]').then((element) => { + cy.visit(element.attr('href')); + }); + + mollieHostedPaymentPage.selectStatus('paid'); + + checkoutSuccessPage.assertThatOrderSuccessPageIsShown(); + + cy.backendLogin(false); + + cy.get('@increment-id').then((incrementId) => { + ordersPage.openByIncrementId(incrementId); + }); + + ordersPage.assertOrderStatusIs('Processing'); + }); +}) diff --git a/Test/End-2-end/cypress/fixtures/mollie-pwa.html b/Test/End-2-end/cypress/fixtures/mollie-pwa.html new file mode 100644 index 00000000000..fcea4e2c5e7 --- /dev/null +++ b/Test/End-2-end/cypress/fixtures/mollie-pwa.html @@ -0,0 +1,834 @@ + + + + +
+
+ + +
+
+
+
Profile ID (optional)
+
+
+ +
+
+ Mode + (Must match payment/mollie_general/type) +
+
+
+ +
+
+ +
+
CurrentStep
+
{{ currentStep }}
+
+ +
+
CartId
+
{{ cartId }}
+
+ +
+ +
+
+
+
    +
  • + + + Create cart + + (from storage) + +
  • +
  • + + + Add product to cart +
  • +
  • + + + Add shipping & billing address +
  • +
  • + + + Get shippings methods ({{ shippingMethod }}) +
  • +
  • + + + Set shipping method +
  • +
  • + + + Get payment methods +
  • +
  • + + + Set the payment method +
  • +
  • + + + Place order +
  • +
  • + + + Check transaction +
  • +
+ +
+
+
+
+ + +
+
+

Order done!

+
+

Order ID: {{ orderId }}

+

1. Please open this url and select a payment status (or not):

+ {{ redirectUrl }}
+ +

2. When you have opened the url, click here to get the payment status:

+ + +
+ PaymentStatus: {{ paymentStatus }}
+ redirect_to_cart: {{ redirectToCart ? 'true' : 'false' }}
+ redirect_to_success_page: {{ redirectToSuccessPage ? 'true' : 'false' }}
+
+
+
+
+
+
+ +
+
+ + {{ method.title }} + + +
    +
  • + +
  • +
+
+ +
+
+
Card Number
+
+
+
+ +
+
Card Holder
+
+
+
+ +
+
Expiry Date
+
+
+
+ +
+
CVV
+
+
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+ + Continue!? +
+
+
+ + + diff --git a/Test/End-2-end/cypress/support/pages/backend/OrdersPage.js b/Test/End-2-end/cypress/support/pages/backend/OrdersPage.js index 56b3b537b33..41f445ff7c6 100644 --- a/Test/End-2-end/cypress/support/pages/backend/OrdersPage.js +++ b/Test/End-2-end/cypress/support/pages/backend/OrdersPage.js @@ -15,6 +15,19 @@ export default class OrdersPage { cy.visit('/admin/sales/order/view/order_id/' + id); } + openByIncrementId(incrementId) { + cy.visit('/admin/sales/order/'); + + cy.get('.data-grid-cell-content') + .contains(incrementId) + .parents('tr') + .find('a.action-menu-item') + .contains('View') + .then((element) => { + cy.visit(element.attr('href')); + }); + } + callFetchStatus() { cy.get('.fetch-mollie-payment-status').click();