Skip to content

Commit

Permalink
Merge pull request #444 from mollie/release/2.1.1
Browse files Browse the repository at this point in the history
Release/2.1.1
  • Loading branch information
Marvin-Magmodules authored Oct 22, 2021
2 parents d4821ff + df3bab1 commit 478ba58
Show file tree
Hide file tree
Showing 9 changed files with 503 additions and 21 deletions.
23 changes: 23 additions & 0 deletions Gateway/Handler/OrderHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Gateway\Handler;

use Magento\Payment\Gateway\Data\PaymentDataObject;
use Magento\Payment\Gateway\Response\HandlerInterface;

class OrderHandler implements HandlerInterface
{
public function handle(array $handlingSubject, array $response)
{
/** @var PaymentDataObject $paymentDataObject */
$paymentDataObject = $handlingSubject['payment'];
$payment = $paymentDataObject->getPayment();
$order = $payment->getOrder();

$order->setCanSendNewEmailFlag(false);
}
}
8 changes: 6 additions & 2 deletions Service/Magento/Vault/AddCardToVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,23 @@ public function forPayment(OrderPaymentInterface $payment, Order $mollieOrder)
$paymentToken = $this->getPaymentToken($mollieOrder);
$extensionAttributes = $this->getExtensionAttributes($payment);

if ($extensionAttributes->getVaultPaymentToken() !== null) {
if ($paymentToken === null || $extensionAttributes->getVaultPaymentToken() !== null) {
return;
}

$extensionAttributes->setVaultPaymentToken($paymentToken);
}

private function getPaymentToken(Order $mollieOrder)
private function getPaymentToken(Order $mollieOrder): ?PaymentTokenInterface
{
/** @var Payment $molliePayment */
$molliePayment = $mollieOrder->payments()->offsetGet(0);
$details = $molliePayment->details;

if (!$details) {
return null;
}

/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->paymentTokenFactory->create(PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD);
$paymentToken->setGatewayToken($molliePayment->mandateId);
Expand Down
10 changes: 9 additions & 1 deletion Service/Order/TransactionPart/SequenceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

class SequenceType implements TransactionPartInterface
{
/**
* @var Config
*/
private $config;

/**
* @var OrderContainsSubscriptionProduct
*/
Expand All @@ -28,9 +33,11 @@ class SequenceType implements TransactionPartInterface
private $customerSession;

public function __construct(
Config $config,
OrderContainsSubscriptionProduct $orderContainsSubscriptionProduct,
Session $customerSession
) {
$this->config = $config;
$this->orderContainsSubscriptionProduct = $orderContainsSubscriptionProduct;
$this->customerSession = $customerSession;
}
Expand Down Expand Up @@ -62,7 +69,8 @@ private function shouldAddSequenceType(OrderInterface $order): bool
return false;
}

if ($order->getPayment()->getAdditionalInformation(VaultConfigProvider::IS_ACTIVE_CODE) &&
if ($this->config->isMagentoVaultEnabled($order->getStoreId()) &&
$order->getPayment()->getAdditionalInformation(VaultConfigProvider::IS_ACTIVE_CODE) &&
$order->getPayment()->getMethod() == 'mollie_methods_creditcard'
) {
return true;
Expand Down
111 changes: 111 additions & 0 deletions Test/Integration/Di/GatewayComponentsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration\Di;

use Magento\Framework\ObjectManager\ConfigInterface;
use Magento\TestFramework\ObjectManager\Config;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class GatewayComponentsTest extends IntegrationTestCase
{
public function testHasAValidatorPool()
{
/** @var Config $config */
$config = $this->objectManager->get(ConfigInterface::class);

foreach ($this->getMethods() as $method) {
$name = $method['name'];

$this->assertArrayHasKey('Mollie' . $name . 'ValidatorPool', $config->getVirtualTypes());
}
}

public function testHasTheValidatorPoolConfigured()
{
$arguments = $this->getObjectManagerArguments();

foreach ($this->getMethods() as $method) {
$class = $method['class'];
$name = $method['name'];
$classArguments = $arguments[$class];

$this->assertArrayHasKey('validatorPool', $classArguments, $name . ' does not have a ValidatorPool');
$this->assertEquals('Mollie' . $name . 'ValidatorPool', $classArguments['validatorPool']['instance']);
}
}

public function testHasACountryValidator()
{
/** @var Config $config */
$config = $this->objectManager->get(ConfigInterface::class);

foreach ($this->getMethods() as $method) {
$name = $method['name'];

$this->assertArrayHasKey('Mollie' . $name . 'CountryValidator', $config->getVirtualTypes());
}
}

public function testCountryValidatorUsesCorrectConfiguration()
{
$arguments = $this->getObjectManagerArguments();

/** @var Config $config */
$config = $this->objectManager->get(ConfigInterface::class);

foreach ($this->getMethods() as $method) {
$name = $method['name'];

$virtualTypes = $config->getVirtualTypes();

$validatorName = 'Mollie' . $name . 'CountryValidator';
$configName = 'Mollie' . $name . 'Config';
$this->assertArrayHasKey($validatorName, $virtualTypes);

$classArguments = $arguments[$validatorName];
$this->assertEquals($configName, $classArguments['config']['instance']);
}
}

private function getObjectManagerArguments(): array
{
static $arguments = null;

if ($arguments) {
return $arguments;
}

/** @var Config $config */
$config = $this->objectManager->get(ConfigInterface::class);

$reflectionObject = new \ReflectionObject($config);
$reflectionProperty = $reflectionObject->getProperty('_arguments');
$reflectionProperty->setAccessible(true);

$arguments = $reflectionProperty->getValue($config);

return $arguments;
}

private function getMethods(): array
{
$keys = array_keys($this->getObjectManagerArguments());

$methods = array_filter($keys, function ($key) {
return strpos($key, 'Mollie\\Payment\\Model\\Methods') !== false;
});

return array_map(function ($key) {
$parts = explode('\\', $key);

return [
'class' => $key,
'name' => end($parts),
];
}, $methods);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function testIncludesNothingWhenTheCustomersApiIsDisabled()
/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoConfigFixture default_store payment/mollie_general/enable_magento_vault 1
* @magentoConfigFixture default_store payment/mollie_methods_creditcard/enable_customers_api 1
*/
public function testIncludesTheSequenceTypeWhenVaultIsEnabled()
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": "2.1.0",
"version": "2.1.1",
"keywords": [
"mollie",
"payment",
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>v2.1.0</version>
<version>v2.1.1</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand Down
Loading

0 comments on commit 478ba58

Please sign in to comment.