Skip to content

Commit

Permalink
Merge pull request #585 from mollie/release/2.19.0
Browse files Browse the repository at this point in the history
Release/2.19.0
  • Loading branch information
Marvin-Magmodules authored Nov 17, 2022
2 parents 71805af + 83587ee commit 1313d52
Show file tree
Hide file tree
Showing 19 changed files with 253 additions and 56 deletions.
20 changes: 10 additions & 10 deletions Controller/ApplePay/BuyNowValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\GuestCartManagementInterface;
use Magento\Quote\Api\GuestCartRepositoryInterface;
use Magento\Quote\Model\QuoteIdMaskFactory;
use Magento\Store\Model\StoreManagerInterface;
use Mollie\Payment\Config;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Model\Mollie;
use Psr\Log\LoggerInterface;

class BuyNowValidation extends Action
{
Expand Down Expand Up @@ -75,20 +74,21 @@ class BuyNowValidation extends Action
private $url;

/**
* @var QuoteIdMaskFactory
* @var ResolverInterface
*/
private $quoteIdMaskFactory;
private $resolver;

/**
* @var ResolverInterface
* @var Config
*/
private $resolver;
private $config;

public function __construct(
Context $context,
Session $customerSession,
CustomerRepositoryInterface $customerRepository,
AccountManagementInterface $accountManagement,
Config $config,
ResolverInterface $resolver,
Validator $formKeyValidator,
GuestCartManagementInterface $cartManagement,
Expand All @@ -98,11 +98,11 @@ public function __construct(
ProductRepositoryInterface $productRepository,
MollieHelper $mollieHelper,
Mollie $mollie,
UrlInterface $url,
QuoteIdMaskFactory $quoteIdMaskFactory
UrlInterface $url
) {
parent::__construct($context, $customerSession, $customerRepository, $accountManagement);

$this->config = $config;
$this->resolver = $resolver;
$this->formKeyValidator = $formKeyValidator;
$this->cartManagement = $cartManagement;
Expand All @@ -113,7 +113,6 @@ public function __construct(
$this->mollieHelper = $mollieHelper;
$this->mollie = $mollie;
$this->url = $url;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
}

/**
Expand Down Expand Up @@ -182,7 +181,8 @@ public function execute()
$e,
__('We can\'t add this item to your shopping cart right now.')
);
$this->_objectManager->get(LoggerInterface::class)->critical($e);

$this->config->addToLog('error', $e);

$response->setHttpResponseCode(403);
return $response->setData([
Expand Down
23 changes: 10 additions & 13 deletions GraphQL/Resolver/Checkout/ProcessTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Mollie\Payment\GraphQL\Resolver\Checkout;

use Magento\Checkout\Model\Session;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
Expand All @@ -17,6 +16,7 @@
use Mollie\Api\Types\PaymentStatus;
use Mollie\Payment\Api\PaymentTokenRepositoryInterface;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Service\Mollie\ShouldRedirectToSuccessPage;

class ProcessTransaction implements ResolverInterface
{
Expand All @@ -36,20 +36,20 @@ class ProcessTransaction implements ResolverInterface
private $cartRepository;

/**
* @var Session
* @var ShouldRedirectToSuccessPage
*/
private $checkoutSession;
private $shouldRedirectToSuccessPage;

public function __construct(
Mollie $mollie,
PaymentTokenRepositoryInterface $paymentTokenRepository,
CartRepositoryInterface $cartRepository,
Session $checkoutSession
ShouldRedirectToSuccessPage $shouldRedirectToSuccessPage
) {
$this->mollie = $mollie;
$this->paymentTokenRepository = $paymentTokenRepository;
$this->cartRepository = $cartRepository;
$this->checkoutSession = $checkoutSession;
$this->shouldRedirectToSuccessPage = $shouldRedirectToSuccessPage;
}

public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
Expand All @@ -66,26 +66,23 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
}

$result = $this->mollie->processTransaction($tokenModel->getOrderId(), 'success', $token);
$redirectToSuccessPage = $this->shouldRedirectToSuccessPage->execute($result);

$cart = null;
if ($tokenModel->getCartId()) {
$cart = $this->getCart($result['status'], $tokenModel->getCartId());
$cart = $this->getCart(!$redirectToSuccessPage, $tokenModel->getCartId());
}

return [
'paymentStatus' => strtoupper($result['status']),
'cart' => $cart,
'redirect_to_cart' => !$redirectToSuccessPage,
'redirect_to_success_page' => $redirectToSuccessPage,
];
}

private function getCart(string $status, string $cartId): ?array
private function getCart(bool $restoreCart, string $cartId): ?array
{
$restoreCart = in_array($status, [
PaymentStatus::STATUS_EXPIRED,
PaymentStatus::STATUS_CANCELED,
PaymentStatus::STATUS_FAILED,
]);

try {
$cart = $this->cartRepository->get($cartId);

Expand Down
8 changes: 0 additions & 8 deletions Helper/Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\ObjectManagerInterface;
use Mollie\Payment\Model\Mollie as MollieModel;
use Mollie\Payment\Service\Mollie\Compatibility\CompatibilityTestInterface;

Expand All @@ -22,10 +21,6 @@ class Tests extends AbstractHelper
const XML_PATH_BANKTRANSFER_ACTIVE = 'payment/mollie_methods_banktransfer/active';
const XML_PATH_BANKTRANSFER_STATUS_PENDING = 'payment/mollie_methods_banktransfer/order_status_pending';

/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var MollieModel
*/
Expand All @@ -39,17 +34,14 @@ class Tests extends AbstractHelper
* Tests constructor.
*
* @param Context $context
* @param ObjectManagerInterface $objectManager
* @param MollieModel $mollieModel
* @param array $tests
*/
public function __construct(
Context $context,
ObjectManagerInterface $objectManager,
MollieModel $mollieModel,
array $tests
) {
$this->objectManager = $objectManager;
$this->mollieModel = $mollieModel;
$this->tests = $tests;
parent::__construct($context);
Expand Down
8 changes: 0 additions & 8 deletions Observer/ConfigObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\ObjectManagerInterface;
use Mollie\Payment\Model\Mollie as MollieModel;
use Mollie\Payment\Helper\General as MollieHelper;

Expand All @@ -33,27 +32,20 @@ class ConfigObserver implements ObserverInterface
* @var MollieHelper
*/
private $mollieHelper;
/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* ConfigObserver constructor.
*
* @param ManagerInterface $messageManager
* @param ObjectManagerInterface $objectManager
* @param MollieModel $mollieModel
* @param MollieHelper $mollieHelper
*/
public function __construct(
ManagerInterface $messageManager,
ObjectManagerInterface $objectManager,
MollieModel $mollieModel,
MollieHelper $mollieHelper
) {
$this->messageManager = $messageManager;
$this->objectManager = $objectManager;
$this->mollieModel = $mollieModel;
$this->mollieHelper = $mollieHelper;
}
Expand Down
7 changes: 6 additions & 1 deletion Plugin/Quote/Api/Item/MakeRecurringProductsUniqueInCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public function __construct(
public function afterRepresentProduct(CartItemInterface $item, bool $result): bool
{
$buyRequest = $item->getOptionByCode('info_buyRequest');
if ((
if (!$buyRequest) {
return $result;
}

if (
(
strstr($buyRequest->getValue(), 'is_recurring') !== false &&
$this->jsonContainsRecurringValue($buyRequest->getValue())
) ||
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ These modules are tested and known to be working with the Mollie Payment extensi
- MageWorx Reward Points
- Mirasvit Rewards
- Weee Fee
- Geissweb EU Vat

## License
[BSD (Berkeley Software Distribution) License](http://www.opensource.org/licenses/bsd-license.php).
Expand Down
15 changes: 15 additions & 0 deletions Service/Mollie/ShouldRedirectToSuccessPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Mollie\Payment\Service\Mollie;

class ShouldRedirectToSuccessPage
{
public function execute(array $result): bool
{
if (!isset($result['success'])) {
return false;
}

return (bool)$result['success'];
}
}
77 changes: 77 additions & 0 deletions Service/Order/Lines/Generator/GeisswebEuvat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

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

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

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

/**
* @var Manager
*/
private $moduleManager;

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

/**
* The Geissweb_Euvat module messes with the trigger_recollect in
* vendor/geissweb/module-euvat/Plugin/Model/Quote.php
*
* which leads to invalid order lines being generated. This is a workaround for that.
*
* @param OrderInterface $order
* @param array $orderLines
* @return array
*/
public function process(OrderInterface $order, array $orderLines): array
{
if (!$this->moduleManager->isEnabled('Geissweb_Euvat')) {
return $orderLines;
}

$forceBaseCurrency = (bool)$this->mollieHelper->useBaseCurrency($order->getStoreId());
$orderTotal = $forceBaseCurrency ? $order->getBaseGrandTotal() : $order->getGrandTotal();
$orderLinesTotal = $this->getOrderLinesTotal($orderLines);

if ($orderTotal == $orderLinesTotal) {
return $orderLines;
}

$currency = $forceBaseCurrency ? $order->getBaseCurrencyCode() : $order->getOrderCurrencyCode();

$orderLines[] = [
'type' => 'discount',
'name' => 'EU VAT',
'quantity' => 1,
'unitPrice' => $this->mollieHelper->getAmountArray($currency, $orderTotal - $orderLinesTotal),
'totalAmount' => $this->mollieHelper->getAmountArray($currency, $orderTotal - $orderLinesTotal),
'vatRate' => 0,
'vatAmount' => $this->mollieHelper->getAmountArray($currency, 0)
];

return $orderLines;
}

private function getOrderLinesTotal(array $orderLines): float
{
$total = 0;
foreach ($orderLines as $orderLine) {
$total += $orderLine['totalAmount']['value'];
}

return $total;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testDoesNotReactivateTheCartWhenTheStatusIsPending()

$tokenModel = $this->objectManager->get(Generate::class)->forOrder($order);
$mollieMock = $this->createMock(Mollie::class);
$mollieMock->method('processTransaction')->willReturn(['status' => 'pending']);
$mollieMock->method('processTransaction')->willReturn(['status' => 'pending', 'success' => true]);
$this->objectManager->addSharedInstance($mollieMock, Mollie::class);

$result = $this->graphQlQuery('mutation {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration\Plugin\Quote\Api\Item;

use Magento\Quote\Api\Data\CartItemInterface;
use Mollie\Payment\Plugin\Quote\Api\Item\MakeRecurringProductsUniqueInCart;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class MakeRecurringProductsUniqueInCartTest extends IntegrationTestCase
{
public function testDoesNotThrowAnErrorWhenNoBuyRequestIsAvailable(): void
{
/** @var MakeRecurringProductsUniqueInCart $instance */
$instance = $this->objectManager->get(MakeRecurringProductsUniqueInCart::class);

$result = rand(0, 1) === 1;
$outcome = $instance->afterRepresentProduct(
$this->objectManager->create(CartItemInterface::class),
$result
);

$this->assertEquals($result, $outcome);
}
}
Loading

0 comments on commit 1313d52

Please sign in to comment.