Skip to content

Commit

Permalink
Merge pull request #502 from mollie/release/2.8.0
Browse files Browse the repository at this point in the history
Release/2.8.0
  • Loading branch information
Marvin-Magmodules committed Mar 21, 2022
2 parents 1f66e7c + ddebb14 commit edaabdc
Show file tree
Hide file tree
Showing 19 changed files with 515 additions and 51 deletions.
12 changes: 11 additions & 1 deletion Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Config
const GENERAL_REDIRECT_WHEN_TRANSACTION_FAILS_TO = 'payment/mollie_general/redirect_when_transaction_fails_to';
const GENERAL_SECOND_CHANCE_EMAIL_TEMPLATE = 'payment/mollie_general/second_chance_email_template';
const GENERAL_SECOND_CHANCE_DELAY = 'payment/mollie_general/second_chance_email_delay';
const GENERAL_SECOND_CHANCE_USE_PAYMENT_METHOD = 'payment/mollie_general/second_chance_use_payment_method';
const GENERAL_TYPE = 'payment/mollie_general/type';
const GENERAL_USE_BASE_CURRENCY = 'payment/mollie_general/currency';
const GENERAL_USE_CUSTOM_REDIRECT_URL = 'payment/mollie_general/use_custom_redirect_url';
Expand Down Expand Up @@ -275,6 +276,15 @@ public function secondChanceEmailDelay($storeId = null)
return $this->getPath(static::GENERAL_SECOND_CHANCE_DELAY, $storeId);
}

/**
* @param null|int|string $storeId
* @return string|null
*/
public function secondChanceUsePaymentMethod(int $storeId = null): ?string
{
return $this->getPath(static::GENERAL_SECOND_CHANCE_USE_PAYMENT_METHOD, $storeId);
}

/**
* @param null|int|string $storeId
* @return bool
Expand Down Expand Up @@ -396,7 +406,7 @@ public function statusNewPaymentLink($storeId = null)
* @param int|null $storeId
* @return bool
*/
public function isMethodActive($method, $storeId = null): bool
public function isMethodActive(string $method, int $storeId = null): bool
{
return $this->isSetFlag($this->addMethodToPath(static::PAYMENT_METHOD_PAYMENT_ACTIVE, $method), $storeId);
}
Expand Down
16 changes: 16 additions & 0 deletions Controller/Checkout/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ private function cancelUnprocessedOrder(OrderInterface $order, $message)
*/
private function formatExceptionMessage(Exception $exception, MethodInterface $methodInstance = null)
{
if (stripos(
$exception->getMessage(),
'The webhook URL is invalid because it is unreachable from Mollie\'s point of view'
) !== false
) {
$this->messageManager->addErrorMessage(
__(
'The webhook URL is invalid because it is unreachable from Mollie\'s point of view. ' .
'View this article for more information: ' .
'https://github.com/mollie/magento2/wiki/Webhook-Communication-between-your-Magento-webshop-and-Mollie'
)
);

return;
}

if ($methodInstance && stripos($exception->getMessage(), 'cURL error 28') !== false) {
$this->messageManager->addErrorMessage(
__(
Expand Down
42 changes: 42 additions & 0 deletions Model/Adminhtml/Source/EnabledMolliePaymentMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Model\Adminhtml\Source;

use Magento\Framework\Data\OptionSourceInterface;
use Mollie\Payment\Config;
use Mollie\Payment\Service\Mollie\PaymentMethods;

class EnabledMolliePaymentMethod implements OptionSourceInterface
{
/**
* @var Config
*/
private $config;

/**
* @var PaymentMethods
*/
private $methods;

public function __construct(
Config $config,
PaymentMethods $methods
) {
$this->methods = $methods;
$this->config = $config;
}

/**
* @inheritDoc
*/
public function toOptionArray()
{
return array_filter($this->methods->getCodeswithTitle(), function ($method) {
return $this->config->isMethodActive($method['value']);
});
}
}
58 changes: 38 additions & 20 deletions Model/OrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,31 @@
use Magento\Sales\Api\Data\CreditmemoItemInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\ShipmentInterface;
use Magento\Sales\Api\Data\ShipmentItemInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\Handler\State;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Model\ResourceModel\OrderLines\Collection as OrderLinesCollection;
use Mollie\Payment\Model\ResourceModel\OrderLines\CollectionFactory as OrderLinesCollectionFactory;
use Mollie\Payment\Service\Order\Creditmemo as CreditmemoService;
use Mollie\Payment\Service\Order\Lines\Order as OrderOrderLines;
use Mollie\Payment\Service\Order\Lines\PaymentFee;
use Mollie\Payment\Service\Order\Lines\StoreCredit;

/**
* @method int getId()
* @method int getItemId()
* @method string getLineId()
* @method int getOrderId()
* @method string getType()
* @method string getSku()
* @method int getQtyOrdered()
* @method int getQtyPaid()
* @method int getQtyCanceled()
* @method int getQtyShipped()
* @method int getQtyRefunded()
* @method float getUnitPrice()
* @method float getDiscountAmount()
* @method float getTotalAmount()
*/
class OrderLines extends AbstractModel
{
/**
Expand All @@ -40,14 +55,6 @@ class OrderLines extends AbstractModel
* @var OrderLinesCollectionFactory
*/
private $orderLinesCollection;
/**
* @var StoreCredit
*/
private $storeCredit;
/**
* @var PaymentFee
*/
private $paymentFee;
/**
* @var CreditmemoService
*/
Expand All @@ -69,8 +76,6 @@ class OrderLines extends AbstractModel
* @param OrderLinesCollectionFactory $orderLinesCollection
* @param Context $context
* @param Registry $registry
* @param StoreCredit $storeCredit
* @param PaymentFee $paymentFee
* @param CreditmemoService $creditmemoService
* @param OrderOrderLines $orderOrderLines
* @param AbstractResource|null $resource
Expand All @@ -83,8 +88,6 @@ public function __construct(
OrderLinesCollectionFactory $orderLinesCollection,
Context $context,
Registry $registry,
StoreCredit $storeCredit,
PaymentFee $paymentFee,
CreditmemoService $creditmemoService,
OrderOrderLines $orderOrderLines,
AbstractResource $resource = null,
Expand All @@ -94,8 +97,6 @@ public function __construct(
$this->mollieHelper = $mollieHelper;
$this->orderLinesFactory = $orderLinesFactory;
$this->orderLinesCollection = $orderLinesCollection;
$this->storeCredit = $storeCredit;
$this->paymentFee = $paymentFee;
$this->creditmemoService = $creditmemoService;
$this->orderOrderLines = $orderOrderLines;
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
Expand Down Expand Up @@ -198,7 +199,7 @@ public function shipAllOrderLines($shipment)
* @param ShipmentInterface $shipment
* @return array
*/
public function getShipmentOrderLines(ShipmentInterface $shipment)
public function getShipmentOrderLines(ShipmentInterface $shipment): array
{
$orderLines = [];

Expand Down Expand Up @@ -229,22 +230,39 @@ public function getShipmentOrderLines(ShipmentInterface $shipment)
$orderLines[] = $line;
}

if ($order->getShipmentsCollection()->count() === 0) {
$this->addNonProductItems($order, $orderLines);
}

return ['lines' => $orderLines];
}

private function addNonProductItems(OrderInterface $order, array &$orderLines): void
{
$collection = $this->orderLinesCollection->create()
->addFieldToFilter('order_id', ['eq' => $order->getEntityId()])
->addFieldToFilter('type', ['nin' => ['physical', 'digital']]);

/** @var OrderLines $item */
foreach ($collection as $item) {
$orderLines[] = [
'id' => $item->getLineId(),
'quantity' => 1,
];
}
}

/**
* @param $itemId
*
* @return OrderLines
*/
public function getOrderLineByItemId($itemId)
{
$orderLine = $this->orderLinesCollection->create()
return $this->orderLinesCollection->create()
->addFieldToFilter('item_id', ['eq' => $itemId])
->addFieldToFilter('line_id', ['notnull' => true])
->getLastItem();

return $orderLine;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Plugin\InventorySales\Model\IsProductSalableForRequestedQtyCondition\IsSalableWithReservationsCondition;

use Magento\Framework\ObjectManagerInterface;
use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface;

class DisableCheckForAdminOrders
{
/**
* @var bool
*/
private $disabled = false;

/**
* @var ObjectManagerInterface
*/
private $objectManager;

public function __construct(
ObjectManagerInterface $objectManager
) {
$this->objectManager = $objectManager;
}

/**
* This method is only called from the `\Mollie\Payment\Service\Order\Reorder::recreate` method, to prevent
* any errors about no stock being available. That method cancels 1 order and recreates another so in that
* case it's valid to not check the stock.The objectmanager here is being used as not everyone has the
* `Magento\InventorySalesApi` module available.
*
* @return void
*/
public function disable(): void
{
$this->disabled = true;
}

public function aroundExecute($subject, $proceed, ...$arguments)
{
if ($this->disabled) {
return $this->objectManager->create(ProductSalableResultInterface::class, ['errors' => []]);
}

return $proceed(...$arguments);
}
}
6 changes: 5 additions & 1 deletion Service/Mollie/Compatibility/TestExtensionAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ private function allExtensionAttributesExists()
$instance = $this->objectManager->get($interface);
$extensionAttributesInstance = $instance->getExtensionAttributes();

if ($extensionAttributesInstance === null) {
return false;
}

if (!$this->allMethodsExists($extensionAttributesInstance, $attributes)) {
return false;
}
Expand Down Expand Up @@ -129,4 +133,4 @@ private function convertToMethodName($attribute)
{
return 'get' . str_replace('_', '', ucwords($attribute, '_'));
}
}
}
18 changes: 9 additions & 9 deletions Service/Mollie/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ public function __construct(
* @var array
*/
private $methods = [
'mollie_methods_applepay',
'mollie_methods_bancontact',
'mollie_methods_banktransfer',
'mollie_methods_belfius',
'mollie_methods_creditcard',
'mollie_methods_directdebit',
'mollie_methods_eps',
'mollie_methods_ideal',
'mollie_methods_kbc',
'mollie_methods_voucher',
'mollie_methods_paypal',
'mollie_methods_paysafecard',
'mollie_methods_sofort',
'mollie_methods_giropay',
'mollie_methods_eps',
'mollie_methods_giftcard',
'mollie_methods_kbc',
'mollie_methods_klarnapaylater',
'mollie_methods_klarnapaynow',
'mollie_methods_klarnasliceit',
'mollie_methods_giftcard',
'mollie_methods_przelewy24',
'mollie_methods_applepay',
'mollie_methods_mybank',
'mollie_methods_paypal',
'mollie_methods_paysafecard',
'mollie_methods_przelewy24',
'mollie_methods_sofort',
'mollie_methods_voucher',
];

public function getCodes()
Expand Down
51 changes: 51 additions & 0 deletions Service/Order/Lines/Generator/AheadworksAddFreeGift.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Service\Order\Lines\Generator;

use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Payment\Helper\General;

class AheadworksAddFreeGift implements GeneratorInterface
{
/**
* @var General
*/
private $mollieHelper;

public function __construct(
General $mollieHelper
) {
$this->mollieHelper = $mollieHelper;
}

public function process(OrderInterface $order, array $orderLines): array
{
$discount = 0;
foreach ($order->getItems() as $item) {
$discount += abs($item->getAwAfptcAmount());
}

if (!$discount) {
return $orderLines;
}

$forceBaseCurrency = (bool)$this->mollieHelper->useBaseCurrency($order->getStoreId());
$currency = $forceBaseCurrency ? $order->getBaseCurrencyCode() : $order->getOrderCurrencyCode();

$orderLines[] = [
'type' => 'surcharge',
'name' => 'Aheadworks Add Free Gift',
'quantity' => 1,
'unitPrice' => $this->mollieHelper->getAmountArray($currency, -$discount),
'totalAmount' => $this->mollieHelper->getAmountArray($currency, -$discount),
'vatRate' => 0,
'vatAmount' => $this->mollieHelper->getAmountArray($currency, 0.0),
];

return $orderLines;
}
}
Loading

0 comments on commit edaabdc

Please sign in to comment.