Skip to content

Commit

Permalink
Merge pull request #545 from mollie/release/2.14.0
Browse files Browse the repository at this point in the history
Release/2.14.0
  • Loading branch information
Marvin-Magmodules authored Jul 8, 2022
2 parents d8e4e9a + adccd0d commit 895eaa2
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
- PHP_VERSION: php71-fpm
MAGENTO_VERSION: 2.3.3
- PHP_VERSION: php73-fpm
MAGENTO_VERSION: 2.3.6-p1
MAGENTO_VERSION: 2.3.7-p3
- PHP_VERSION: php73-fpm
MAGENTO_VERSION: 2.4.2
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.2
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.3-with-replacements
- PHP_VERSION: php81-fpm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- PHP_VERSION: php72-fpm
MAGENTO_VERSION: 2.3.4
- PHP_VERSION: php73-fpm
MAGENTO_VERSION: 2.3.7
MAGENTO_VERSION: 2.3.7-p3
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php81-fpm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/setup-di-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- PHP_VERSION: php71-fpm
MAGENTO_VERSION: 2.3.3
- PHP_VERSION: php73-fpm
MAGENTO_VERSION: 2.3.6-p1
MAGENTO_VERSION: 2.3.7-p3
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.2
- PHP_VERSION: php74-fpm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- PHP_VERSION: php71-fpm
MAGENTO_VERSION: 2.3.3
- PHP_VERSION: php73-fpm
MAGENTO_VERSION: 2.3.7
MAGENTO_VERSION: 2.3.7-p3
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php74-fpm
Expand Down
33 changes: 33 additions & 0 deletions Model/Adminhtml/Source/SecondChancePaymentMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Mollie\Payment\Model\Adminhtml\Source;

use Magento\Framework\Data\OptionSourceInterface;

class SecondChancePaymentMethod implements OptionSourceInterface
{
public const USE_PREVIOUS_METHOD = 'use_method_of_original_order';

/**
* @var EnabledMolliePaymentMethod
*/
private $enabledMolliePaymentMethod;

public function __construct(
EnabledMolliePaymentMethod $enabledMolliePaymentMethod
) {
$this->enabledMolliePaymentMethod = $enabledMolliePaymentMethod;
}

public function toOptionArray(): array
{
$options = $this->enabledMolliePaymentMethod->toOptionArray();

array_unshift($options, [
'value' => static::USE_PREVIOUS_METHOD,
'label' => __('Use the method of the original order'),
]);

return $options;
}
}
2 changes: 1 addition & 1 deletion Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function getActiveMethods(MollieApiClient $mollieApi, CartInterface $cart
];
}
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', 'Function: getActiveMethods: ' . $e->getMessage());
$this->mollieHelper->addTolog('info', 'Function: getActiveMethods: ' . $e->getMessage());
$this->methodData = [];
}

Expand Down
2 changes: 1 addition & 1 deletion Model/OrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function getShipmentOrderLines(ShipmentInterface $shipment): array

/** @var OrderInterface $order */
$order = $shipment->getOrder();
$orderHasDiscount = abs($order->getDiscountAmount()) > 0;
$orderHasDiscount = abs($order->getDiscountAmount() ?? 0) > 0;

/** @var \Magento\Sales\Model\Order\Shipment\Item $item */
foreach ($shipment->getItemsCollection() as $item) {
Expand Down
18 changes: 17 additions & 1 deletion Service/Order/Reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\Service\InvoiceService;
use Mollie\Payment\Config;
use Mollie\Payment\Model\Adminhtml\Source\SecondChancePaymentMethod;
use Mollie\Payment\Plugin\InventorySales\Model\IsProductSalableForRequestedQtyCondition\IsSalableWithReservationsCondition\DisableCheckForAdminOrders;

class Reorder
Expand Down Expand Up @@ -100,7 +101,7 @@ public function create(OrderInterface $originalOrder): OrderInterface

$order = $this->recreate(
$originalOrder,
$this->config->secondChanceUsePaymentMethod($originalOrder->getStoreId())
$this->getPaymentMethod($originalOrder)
);

$this->cancelOriginalOrder($originalOrder);
Expand Down Expand Up @@ -213,4 +214,19 @@ private function addCommentHistoryOriginalOrder(OrderInterface $originalOrder, $
$comment = __('We created a new order with increment ID: %1', $newIncrementId);
$this->orderCommentHistory->add($originalOrder, $comment, false);
}

/**
* @param OrderInterface $originalOrder
* @return string|null
*/
public function getPaymentMethod(OrderInterface $originalOrder): ?string
{
$value = $this->config->secondChanceUsePaymentMethod($originalOrder->getStoreId());

if ($value == SecondChancePaymentMethod::USE_PREVIOUS_METHOD) {
return $originalOrder->getPayment()->getMethod();
}

return $value;
}
}
4 changes: 2 additions & 2 deletions Service/Order/Uncancel/OrderReservation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Mollie\Payment\Service\Order\Uncancel;

use Magento\Catalog\Model\Indexer\Product\Price\Processor;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\ObjectManagerInterface;
use Magento\InventorySales\Model\SalesEvent;
use Magento\InventorySalesApi\Api\Data\ItemToSellInterface;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
Expand Down Expand Up @@ -45,7 +45,7 @@ class OrderReservation
public function __construct(
WebsiteRepositoryInterface $websiteRepository,
Processor $priceIndexer,
ObjectManager $objectManager
ObjectManagerInterface $objectManager
) {
$this->websiteRepository = $websiteRepository;
$this->priceIndexer = $priceIndexer;
Expand Down
2 changes: 1 addition & 1 deletion Service/Quote/CartContainsRecurringProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function execute(CartInterface $cart): bool
$items = $cart->getItemsCollection()->getItems();
foreach ($items as $item) {
$buyRequest = $item->getOptionByCode('info_buyRequest');
if (strstr($buyRequest->getValue(), 'is_recurring') !== false &&
if ($buyRequest && strstr($buyRequest->getValue(), 'is_recurring') !== false &&
$this->jsonContainsRecurringValue($buyRequest->getValue())) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Mollie\Payment\Test\Integration\Model\Client\Payments\Processors;

use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Mollie\Payment\Model\Client\Payments\Processors\SuccessfulPayment;
use Mollie\Payment\Model\Client\ProcessTransactionResponse;
Expand All @@ -21,7 +22,20 @@ class SuccessfulPaymentTest extends IntegrationTestCase
public function testCanceledOrderGetsUncanceled(): void
{
$order = $this->loadOrder('100000001');
$order->setBaseCurrencyCode('EUR');
$order->setMollieTransactionId('abc123');

$items = $order->getItems();
foreach ($items as $item) {
if (!$item->getSku()) {
$item->setSku($item->getProduct()->getSku());
}
}

$item = array_shift($items);
$item->setCurrencyCode('EUR');

$this->objectManager->get(OrderRepositoryInterface::class)->save($order);
$order->cancel();

$this->assertEquals(Order::STATE_CANCELED, $order->getState());
Expand Down Expand Up @@ -54,6 +68,9 @@ public function testCanceledOrderGetsUncanceled(): void
Order::STATE_PROCESSING,
Order::STATE_COMPLETE,
]
), 'We expect the order status to be "processing" or "complete".');
), sprintf(
'We expect the order status to be "processing" or "complete". Instead we got %s',
$freshOrder->getState()
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CartContainsRecurringProductTest extends IntegrationTestCase
/**
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product.php
*/
public function testReturnsFalseWhenNoItemAvailable()
public function testReturnsFalseWhenNoItemAvailable(): void
{
/** @var \Magento\Quote\Model\Quote $cart */
$cart = $this->objectManager->create(Session::class)->getQuote();
Expand All @@ -30,7 +30,7 @@ public function testReturnsFalseWhenNoItemAvailable()
/**
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_and_custom_option.php
*/
public function testReturnsTrueWhenOneOfTheItemsIsASubscriptionProduct()
public function testReturnsTrueWhenOneOfTheItemsIsASubscriptionProduct(): void
{
/** @var SerializerInterface $serializer */
$serializer = $this->objectManager->create(SerializerInterface::class);
Expand All @@ -55,4 +55,23 @@ public function testReturnsTrueWhenOneOfTheItemsIsASubscriptionProduct()

$this->assertTrue($instance->execute($cart), 'The cart should contain a subscription product');
}

/**
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_and_custom_option.php
*/
public function testHandlesCasesWhereNoBuyRequestIsAvailable(): void
{
/** @var \Magento\Quote\Model\Quote $cart */
$cart = $this->objectManager->create(Session::class)->getQuote();

/** @var CartContainsRecurringProduct $instance */
$instance = $this->objectManager->create(CartContainsRecurringProduct::class);

$items = $cart->getItemsCollection()->getItems();
foreach ($items as $item) {
$item->getOptionByCode('info_buyRequest')->delete();
}

$this->assertFalse($instance->execute($cart));
}
}
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.13.0",
"version": "2.14.0",
"keywords": [
"mollie",
"payment",
Expand Down
4 changes: 2 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@
<field id="second_chance_use_payment_method" translate="label" type="select" sortOrder="50" showInDefault="1"
showInWebsite="0" showInStore="1" canRestore="1">
<label>Payment Method To Use For Second Change Payments</label>
<source_model>Mollie\Payment\Model\Adminhtml\Source\EnabledMolliePaymentMethod</source_model>
<source_model>Mollie\Payment\Model\Adminhtml\Source\SecondChancePaymentMethod</source_model>
<config_path>payment/mollie_general/second_chance_use_payment_method</config_path>
<depends>
<field id="enable_second_chance_email">1</field>
</depends>
<comment><![CDATA[Configure the delay in hours when the "second chance email" should be sent.]]></comment>
<comment><![CDATA[If the original order is canceled, a new order is created when the customer clicks the "second chance email". The payment method here is used in that case.]]></comment>
</field>
</group>
</section>
Expand Down
4 changes: 2 additions & 2 deletions 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.13.0</version>
<version>v2.14.0</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand All @@ -24,7 +24,7 @@
<use_webhooks>enabled</use_webhooks>
<automatically_send_second_chance_emails>0</automatically_send_second_chance_emails>
<second_chance_email_delay>1</second_chance_email_delay>
<second_chance_use_payment_method>mollie_methods_ideal</second_chance_use_payment_method>
<second_chance_use_payment_method>use_method_of_original_order</second_chance_use_payment_method>
<redirect_when_transaction_fails_to>redirect_to_cart</redirect_when_transaction_fails_to>
<enable_magento_vault>0</enable_magento_vault>
</mollie_general>
Expand Down

0 comments on commit 895eaa2

Please sign in to comment.