Skip to content

Commit

Permalink
Merge pull request #348 from mollie/1.21.0
Browse files Browse the repository at this point in the history
1.21.0
  • Loading branch information
Marvin-Magmodules authored Jan 19, 2021
2 parents 9fd9460 + f2e5722 commit c345675
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 21 deletions.
43 changes: 43 additions & 0 deletions GraphQL/Resolver/Cart/PaymentMethodMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\GraphQL\Resolver\Cart;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

class PaymentMethodMeta implements \Magento\Framework\GraphQl\Query\ResolverInterface
{
/**
* @var \Magento\Framework\View\Asset\Repository
*/
private $assetRepository;

public function __construct(
\Magento\Framework\View\Asset\Repository $assertRepository
) {
$this->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'),
];
}
}
12 changes: 10 additions & 2 deletions Service/Mollie/GetIssuers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,14 +31,21 @@ class GetIssuers
*/
private $mollieModel;

/**
* @var Resolver
*/
private $resolver;

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;
}

/**
Expand All @@ -48,7 +56,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);
Expand Down
24 changes: 18 additions & 6 deletions Service/Order/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions Test/Integration/GraphQL/Resolver/Cart/PaymentMethodMetaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration\GraphQL\Resolver\Cart;

use Magento\Framework\App\ProductMetadataInterface;
use Mollie\Payment\GraphQL\Resolver\Cart\PaymentMethodMeta;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class PaymentMethodMetaTest extends IntegrationTestCase
{
protected function setUpWithoutVoid()
{
$version = $this->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
);
}
}
34 changes: 32 additions & 2 deletions Test/Integration/Service/Order/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions etc/acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<resource id="Magento_Backend::stores">
<resource id="Magento_Backend::stores_settings">
<resource id="Magento_Config::config">
<resource id="Mollie_Payment::config" title="Mollie configuration"/>
<resource id="Mollie_Payment::config" title="Mollie Configuration" translate="title" />
</resource>
</resource>
</resource>
<resource id="Magento_Sales::sales" title="Sales" translate="title" sortOrder="20">
<resource id="Mollie_Payment::payment_reminders" title="Mollie payment reminders">
<resource id="Mollie_Payment::pending_payment_reminders" title="Mollie pending payment reminders" />
<resource id="Mollie_Payment::sent_payment_reminders" title="Mollie sent payment reminders" />
<resource id="Magento_Sales::sales">
<resource id="Mollie_Payment::payment_reminders" title="Mollie Payment Reminders" translate="title">
<resource id="Mollie_Payment::pending_payment_reminders" title="Pending Payment Reminders" translate="title" />
<resource id="Mollie_Payment::sent_payment_reminders" title="Sent Payment Reminders" translate="title" />
</resource>
</resource>
</resource>
Expand Down
4 changes: 2 additions & 2 deletions etc/adminhtml/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Mollie_Payment::payment_reminders" title="Mollie Payment Reminders" translate="title" module="Mollie_Payment" sortOrder="10" parent="Magento_Sales::sales" resource="Mollie_Payment::payment_reminders" />
<add id="Mollie_Payment::pending_payment_reminders" title="Pending" translate="title" module="Magento_Sales" sortOrder="10" parent="Mollie_Payment::payment_reminders" action="mollie/reminder/pending" resource="Mollie_Payment::pending_payment_reminders"/>
<add id="Mollie_Payment::sent_payment_reminders" title="Sent" translate="title" module="Magento_Sales" sortOrder="20" parent="Mollie_Payment::payment_reminders" action="mollie/reminder/sent" resource="Mollie_Payment::sent_payment_reminders"/>
<add id="Mollie_Payment::pending_payment_reminders" title="Pending" translate="title" module="Mollie_Payment" sortOrder="10" parent="Mollie_Payment::payment_reminders" action="mollie/reminder/pending" resource="Mollie_Payment::pending_payment_reminders"/>
<add id="Mollie_Payment::sent_payment_reminders" title="Sent" translate="title" module="Mollie_Payment" sortOrder="20" parent="Mollie_Payment::payment_reminders" action="mollie/reminder/sent" resource="Mollie_Payment::sent_payment_reminders"/>
</menu>
</config>
12 changes: 11 additions & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,17 @@
showInStore="1">
<label>Custom return url</label>
<config_path>payment/mollie_general/custom_redirect_url</config_path>
<comment><![CDATA[<strong>Note:</strong> This URL is not being parsed.<br>You need to enter the complete url.]]></comment>
<comment><![CDATA[
<strong>Note:</strong> You can use the following placeholders:<br>
<br>
<strong>{{order_id}}</strong>: The entity ID of the order.<br>
<strong>{{increment_id}}</strong>: The increment ID of the order.<br>
<strong>{{payment_token}}</strong>: The generated payment token.<br>
<strong>{{order_hash}}</strong>: The entity ID encrypted and base64 encoded.<br>
<strong>{{base_url}}</strong>: The store base url.<br>
<strong>{{unsecure_base_url}}</strong>: The store base url.<br>
<strong>{{secure_base_url}}</strong>: The secure store base url.
]]></comment>
<validate>validate-url</validate>
<depends>
<field id="use_custom_redirect_url">1</field>
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<default>
<payment>
<mollie_general>
<version>v1.20.1</version>
<version>v1.21.0</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand Down
2 changes: 2 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<item name="payment/mollie_general/debug" xsi:type="string">1</item>
<item name="payment/mollie_general/use_webhooks" xsi:type="string">1</item>
<item name="payment/mollie_general/custom_webhook_url" xsi:type="string">1</item>
<item name="payment/mollie_general/use_custom_redirect_url" xsi:type="string">1</item>
<item name="payment/mollie_general/custom_redirect_url" xsi:type="string">1</item>
</argument>
</arguments>
</type>
Expand Down
11 changes: 10 additions & 1 deletion etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,6 +30,10 @@ type MollieIssuer {
svg: String!
}

type MolliePaymentMethodMeta {
image: String
}

input MollieTransactionInput {
payment_token: String!
issuer: String
Expand All @@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ define(
return promise;
},
afterPlaceOrder: function () {
this._super();
window.location = url.build('mollie/checkout/redirect/paymentToken/' + this.paymentToken());
}
}
Expand Down

0 comments on commit c345675

Please sign in to comment.