From b9ff50f356df61db46c3a4314977a8c02c39c51a Mon Sep 17 00:00:00 2001 From: "joeri.lock" Date: Wed, 6 Jan 2021 09:26:33 +0100 Subject: [PATCH 1/9] Bugfix: Add localecode to cache_indentifier --- Service/Mollie/GetIssuers.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Service/Mollie/GetIssuers.php b/Service/Mollie/GetIssuers.php index b5281464f6f..58febff3b59 100644 --- a/Service/Mollie/GetIssuers.php +++ b/Service/Mollie/GetIssuers.php @@ -8,6 +8,7 @@ use Magento\Framework\App\CacheInterface; use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Locale\Resolver; use Mollie\Api\MollieApiClient; use Mollie\Payment\Model\Mollie as MollieModel; @@ -33,11 +34,13 @@ class GetIssuers public function __construct( CacheInterface $cache, SerializerInterface $serializer, - MollieModel $mollieModel + MollieModel $mollieModel, + Resolver $resolver ) { $this->cache = $cache; $this->serializer = $serializer; $this->mollieModel = $mollieModel; + $this->resolver = $resolver; } /** @@ -48,7 +51,7 @@ public function __construct( */ public function execute(MollieApiClient $mollieApi, $method, $type) { - $identifier = static::CACHE_IDENTIFIER_PREFIX . $method . $type; + $identifier = static::CACHE_IDENTIFIER_PREFIX . $method . $type . $this->resolver->getLocale(); $result = $this->cache->load($identifier); if ($result) { return $this->serializer->unserialize($result); From 15ba5393f971b8c54dcca7d09d54a7bac826d47d Mon Sep 17 00:00:00 2001 From: "joeri.lock" Date: Wed, 6 Jan 2021 09:47:18 +0100 Subject: [PATCH 2/9] + define Resolver property --- Service/Mollie/GetIssuers.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Service/Mollie/GetIssuers.php b/Service/Mollie/GetIssuers.php index 58febff3b59..e2ae2489ab7 100644 --- a/Service/Mollie/GetIssuers.php +++ b/Service/Mollie/GetIssuers.php @@ -31,6 +31,11 @@ class GetIssuers */ private $mollieModel; + /** + * @var Resolver + */ + private $resolver; + public function __construct( CacheInterface $cache, SerializerInterface $serializer, From d68ea20f3c1849cc274254e5ca7a4b54665fd4b1 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Fri, 8 Jan 2021 10:01:12 +0100 Subject: [PATCH 3/9] Feature: Added the payment method image to the GraphQL response of 'AvailablePaymentMethod' --- GraphQL/Resolver/Cart/PaymentMethodMeta.php | 43 ++++++++++++ .../Resolver/Cart/PaymentMethodMetaTest.php | 68 +++++++++++++++++++ etc/schema.graphqls | 11 ++- 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 GraphQL/Resolver/Cart/PaymentMethodMeta.php create mode 100644 Test/Integration/GraphQL/Resolver/Cart/PaymentMethodMetaTest.php diff --git a/GraphQL/Resolver/Cart/PaymentMethodMeta.php b/GraphQL/Resolver/Cart/PaymentMethodMeta.php new file mode 100644 index 00000000000..d280d6df537 --- /dev/null +++ b/GraphQL/Resolver/Cart/PaymentMethodMeta.php @@ -0,0 +1,43 @@ +assetRepository = $assertRepository; + } + + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + $method = $value['code']; + if (strpos($method, 'mollie_method') !== 0) { + return ['image' => null]; + } + + $cleanCode = str_replace('mollie_methods_', '', $method); + + return [ + 'image' => $this->assetRepository->getUrl('Mollie_Payment::images/methods/' . $cleanCode . '.svg'), + ]; + } +} diff --git a/Test/Integration/GraphQL/Resolver/Cart/PaymentMethodMetaTest.php b/Test/Integration/GraphQL/Resolver/Cart/PaymentMethodMetaTest.php new file mode 100644 index 00000000000..994c061e9fe --- /dev/null +++ b/Test/Integration/GraphQL/Resolver/Cart/PaymentMethodMetaTest.php @@ -0,0 +1,68 @@ +objectManager->get(ProductMetadataInterface::class)->getVersion(); + if (version_compare($version, '2.3', '<=')) { + $this->markTestSkipped('This test only works on Magento 2.3 and higher.'); + } + } + + public function testReturnsAnEmptyResponseForNonMollieMethods() + { + $instance = $this->objectManager->create(PaymentMethodMeta::class); + + $result = $this->callResolve($instance, ['code' => 'checkmo']); + + $this->assertNull($result['image']); + } + + public function testReturnsTheImageForMollieMethods() + { + $instance = $this->objectManager->create(PaymentMethodMeta::class); + + $result = $this->callResolve($instance, ['code' => 'mollie_methods_ideal']); + + $this->assertStringContainsString('Mollie_Payment/images/methods/ideal.svg', $result['image']); + } + + public function callResolve(PaymentMethodMeta $instance, $value = null, $args = null) + { + return $instance->resolve( + $this->objectManager->create(\Magento\Framework\GraphQl\Config\Element\Field::class, [ + 'name' => 'testfield', + 'type' => 'string', + 'required' => false, + 'isList' => false, + ]), + $this->objectManager->create(\Magento\Framework\GraphQl\Query\Resolver\ContextInterface::class), + $this->objectManager->create(\Magento\Framework\GraphQl\Schema\Type\ResolveInfo::class, [ + 'values' => [], + 'fieldName' => 'testfield', + 'fieldNodes' => [], + 'returnType' => 'string', + 'parentType' => new \GraphQL\Type\Definition\ObjectType(['name' => 'testfield']), + 'path' => [], + 'schema' => $this->objectManager->create(\GraphQL\Type\Schema::class, ['config' => []]), + 'fragments' => [], + 'rootValue' => '', + 'operation' => null, + 'variableValues' => [], + ]), + $value, + $args + ); + } +} diff --git a/etc/schema.graphqls b/etc/schema.graphqls index d361fc89de0..ca3f6bb2839 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -16,6 +16,11 @@ type Cart { type AvailablePaymentMethod { mollie_available_issuers: [MollieIssuer!] @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\Cart\\AvailableIssuersForMethod") @doc(description: "Available issuers for this payment method") + mollie_meta: MolliePaymentMethodMeta! @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\Cart\\PaymentMethodMeta") @doc(description: "Retrieve meta information for this payment method (image)") +} + +type SelectedPaymentMethod { + mollie_meta: MolliePaymentMethodMeta! @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\Cart\\PaymentMethodMeta") @doc(description: "Retrieve meta information for this payment method (image)") } type MollieIssuer { @@ -25,6 +30,10 @@ type MollieIssuer { svg: String! } +type MolliePaymentMethodMeta { + image: String +} + input MollieTransactionInput { payment_token: String! issuer: String @@ -34,4 +43,4 @@ type Query { mollieCustomerOrder ( hash: String @doc(description: "The hash added to your custom URL") ): CustomerOrder @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\Checkout\\MollieCustomerOrder") -} \ No newline at end of file +} From ee40c8df2690aa845412106ef548aea675042e29 Mon Sep 17 00:00:00 2001 From: Vladimir Malik Date: Mon, 11 Jan 2021 14:00:20 +0300 Subject: [PATCH 4/9] =?UTF-8?q?Fixes=20for=20ACL:=20=E2=80=A8-=20No=20chan?= =?UTF-8?q?ge=20definition=20for=20Magento=5FSales:sales=20-=20Fixed=20tit?= =?UTF-8?q?les=20for=20consistent=20view=20-=20Added=20translatable=20for?= =?UTF-8?q?=20ACL=20titles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- etc/acl.xml | 10 +++++----- etc/adminhtml/menu.xml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/etc/acl.xml b/etc/acl.xml index 610be44cc0f..505f04be630 100644 --- a/etc/acl.xml +++ b/etc/acl.xml @@ -6,14 +6,14 @@ - + - - - - + + + + diff --git a/etc/adminhtml/menu.xml b/etc/adminhtml/menu.xml index 6c139d63487..afca7e5a238 100644 --- a/etc/adminhtml/menu.xml +++ b/etc/adminhtml/menu.xml @@ -2,7 +2,7 @@ - - + + From 65ad1de752237eaa469d20334be5725d46032c50 Mon Sep 17 00:00:00 2001 From: Billydg Date: Mon, 11 Jan 2021 13:26:04 +0100 Subject: [PATCH 5/9] compatible: afterPlaceOrder super gets called so other modules can use the function --- view/frontend/web/js/view/payment/method-renderer/default.js | 1 + 1 file changed, 1 insertion(+) diff --git a/view/frontend/web/js/view/payment/method-renderer/default.js b/view/frontend/web/js/view/payment/method-renderer/default.js index 020eef147d5..3e3938f1cfe 100644 --- a/view/frontend/web/js/view/payment/method-renderer/default.js +++ b/view/frontend/web/js/view/payment/method-renderer/default.js @@ -81,6 +81,7 @@ define( return promise; }, afterPlaceOrder: function () { + this._super(); window.location = url.build('mollie/checkout/redirect/paymentToken/' + this.paymentToken()); } } From 98547948cf182d819301c5827cb3a43eeb372fc4 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 18 Jan 2021 10:39:48 +0100 Subject: [PATCH 6/9] Add the base urls to the custom return url --- Service/Order/Transaction.php | 24 +++++++++---- .../Service/Order/TransactionTest.php | 34 +++++++++++++++++-- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Service/Order/Transaction.php b/Service/Order/Transaction.php index 0d9d1441c55..b9ea6eaa0b3 100644 --- a/Service/Order/Transaction.php +++ b/Service/Order/Transaction.php @@ -6,10 +6,12 @@ namespace Mollie\Payment\Service\Order; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Helper\Context; use Magento\Framework\Encryption\Encryptor; use Magento\Framework\UrlInterface; use Magento\Sales\Api\Data\OrderInterface; +use Magento\Store\Model\ScopeInterface as StoreScope; use Mollie\Payment\Config; use Mollie\Payment\Model\Adminhtml\Source\WebhookUrlOptions; @@ -30,14 +32,21 @@ class Transaction */ private $encryptor; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + public function __construct( Config $config, Context $context, - Encryptor $encryptor + Encryptor $encryptor, + ScopeConfigInterface $scopeConfig ) { $this->config = $config; $this->urlBuilder = $context->getUrlBuilder(); $this->encryptor = $encryptor; + $this->scopeConfig = $scopeConfig; } /** @@ -85,14 +94,17 @@ public function getWebhookUrl($storeId = null) private function addParametersToCustomUrl(OrderInterface $order, string $paymentToken, int $storeId = null) { $replacements = [ - '{{ORDER_ID}}' => $order->getId(), - '{{INCREMENT_ID}}' => $order->getIncrementId(), - '{{PAYMENT_TOKEN}}' => $paymentToken, - '{{ORDER_HASH}}' => base64_encode($this->encryptor->encrypt((string)$order->getId())), + '{{order_id}}' => $order->getId(), + '{{increment_id}}' => $order->getIncrementId(), + '{{payment_token}}' => $paymentToken, + '{{order_hash}}' => base64_encode($this->encryptor->encrypt((string)$order->getId())), + '{{base_url}}' => $this->scopeConfig->getValue('web/unsecure/base_url', StoreScope::SCOPE_STORE, $storeId), + '{{unsecure_base_url}}' => $this->scopeConfig->getValue('web/unsecure/base_url', StoreScope::SCOPE_STORE, $storeId), + '{{secure_base_url}}' => $this->scopeConfig->getValue('web/secure/base_url', StoreScope::SCOPE_STORE, $storeId), ]; $customUrl = $this->config->customRedirectUrl($storeId); - $customUrl = str_replace( + $customUrl = str_ireplace( array_keys($replacements), array_values($replacements), $customUrl diff --git a/Test/Integration/Service/Order/TransactionTest.php b/Test/Integration/Service/Order/TransactionTest.php index 05efa72de91..7de7f0328dc 100644 --- a/Test/Integration/Service/Order/TransactionTest.php +++ b/Test/Integration/Service/Order/TransactionTest.php @@ -6,6 +6,7 @@ namespace Mollie\Payment\Test\Integration\Service\Order; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Encryption\Encryptor; use Magento\Sales\Api\Data\OrderInterface; use Mollie\Payment\Service\Order\Transaction; @@ -68,12 +69,29 @@ public function testRedirectUrlWithFilledCustomUrl() /** * @magentoConfigFixture current_store payment/mollie_general/use_custom_redirect_url 1 - * @magentoConfigFixture current_store payment/mollie_general/custom_redirect_url https://www.mollie.com/?order_id={{ORDER_ID}}&payment_token={{PAYMENT_TOKEN}}&increment_id={{INCREMENT_ID}} + * @magentoConfigFixture current_store payment/mollie_general/custom_redirect_url https://www.mollie.com/?order_id={{ORDER_ID}}&payment_token={{PAYMENT_TOKEN}}&increment_id={{INCREMENT_ID}}&short_base_url={{base_url}}&unsecure_base_url={{unsecure_base_url}}&secure_base_url={{secure_base_url}} */ public function testAppendsTheParamsToTheUrl() { + $configMock = $this->createMock(ScopeConfigInterface::class); + + $configMock + ->method('getValue') + ->withConsecutive( + ['web/unsecure/base_url', 'store', null], + ['web/unsecure/base_url', 'store', null], + ['web/secure/base_url', 'store', null] + ) + ->willReturnOnConsecutiveCalls( + 'http://base_url.test/', + 'http://unsecure_base_url.test/', + 'https://secure_base_url.test/' + ); + /** @var Transaction $instance */ - $instance = $this->objectManager->create(Transaction::class); + $instance = $this->objectManager->create(Transaction::class, [ + 'scopeConfig' => $configMock, + ]); /** @var OrderInterface $order */ $order = $this->objectManager->create(OrderInterface::class); @@ -85,6 +103,18 @@ public function testAppendsTheParamsToTheUrl() $this->assertStringContainsString('order_id=9999', $result); $this->assertStringContainsString('increment_id=8888', $result); $this->assertStringContainsString('payment_token=paymenttoken', $result); + $this->assertStringContainsString('short_base_url=http://base_url.test/', $result); + $this->assertStringContainsString('unsecure_base_url=http://unsecure_base_url.test/', $result); + $this->assertStringContainsString('secure_base_url=https://secure_base_url.test/', $result); + } + + /** + * @magentoConfigFixture current_store payment/mollie_general/use_custom_redirect_url 1 + * @magentoConfigFixture current_store payment/mollie_general/custom_redirect_url https://www.mollie.com/?order_id={{order_id}}&payment_token={{payment_token}}&increment_id={{increment_id}}&short_base_url={{base_url}}&unsecure_base_url={{unsecure_base_url}}&secure_base_url={{secure_base_url}} + */ + public function testTheVariablesAreCaseInsensitive() + { + $this->testAppendsTheParamsToTheUrl(); } /** From ebdf8085815c115c075abbda1c9632f17aed00c7 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 18 Jan 2021 10:40:08 +0100 Subject: [PATCH 7/9] Mark the custom return url as system specific --- etc/di.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etc/di.xml b/etc/di.xml index 2bfa50dd726..35f25d7b35c 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -49,6 +49,8 @@ 1 1 1 + 1 + 1 From 9712abbedf45a00e9fb2f325c63f8751d8f51d2d Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 18 Jan 2021 10:47:48 +0100 Subject: [PATCH 8/9] Updated the custom return url comment with the available placeholders --- etc/adminhtml/system.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index d2b7bfd9889..d54b6c408d3 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -263,7 +263,17 @@ showInStore="1"> payment/mollie_general/custom_redirect_url - Note: This URL is not being parsed.
You need to enter the complete url.]]>
+ Note: You can use the following placeholders:
+
+ {{order_id}}: The entity ID of the order.
+ {{increment_id}}: The increment ID of the order.
+ {{payment_token}}: The generated payment token.
+ {{order_hash}}: The entity ID encrypted and base64 encoded.
+ {{base_url}}: The store base url.
+ {{unsecure_base_url}}: The store base url.
+ {{secure_base_url}}: The secure store base url. + ]]>
validate-url 1 From 49f3a87278d8617afc3bca8b9aacb983c95629cd Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Tue, 19 Jan 2021 17:15:26 +0100 Subject: [PATCH 9/9] Version bump --- composer.json | 2 +- etc/config.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 7725ec3ee79..6987683a01b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mollie/magento2", "description": "Mollie Payment Module for Magento 2", - "version": "1.20.1", + "version": "1.21.0", "keywords": [ "mollie", "payment", diff --git a/etc/config.xml b/etc/config.xml index 1816c2561c1..835d741ad1a 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -3,7 +3,7 @@ - v1.20.1 + v1.21.0 0 0 test