Skip to content

Commit

Permalink
Merge pull request #645 from mollie/release/2.26.0
Browse files Browse the repository at this point in the history
Release/2.26.0
  • Loading branch information
Marvin-Magmodules authored May 26, 2023
2 parents 0a8e772 + a77e3ca commit e48222d
Show file tree
Hide file tree
Showing 44 changed files with 1,251 additions and 163 deletions.
1 change: 1 addition & 0 deletions .github/workflows/end-2-end-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ jobs:
name: E2E logs - ${{ matrix.PHP_VERSION }} - ${{ matrix.MAGENTO_VERSION }}
path: |
Test/End-2-end/cypress/videos
Test/End-2-end/cypress/screenshots
magento-logs
magento.log
nginx-proxy.log
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ view/adminhtml/web/css/styles.css
view/frontend/web/css/styles.css
Test/End-2-end/node_modules
Test/End-2-end/cypress/videos
Test/End-2-end/cypress/screenshots
8 changes: 6 additions & 2 deletions Controller/Checkout/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public function execute()
$this->checkoutSession->start();

$redirect = new DataObject([
'path' => 'checkout/onepage/success?utm_nooverride=1',
'path' => 'checkout/onepage/success',
'query' => ['utm_nooverride' => 1],
]);

$this->eventManager->dispatch('mollie_checkout_success_redirect', [
Expand All @@ -119,7 +120,10 @@ public function execute()
'response' => $this->getResponse(),
]);

return $this->_redirect($redirect->getData('path'));
return $this->_redirect($redirect->getData('path'), [
'_query' => $redirect->getData('query'),
'_use_rewrite' => false,
]);
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
$this->messageManager->addErrorMessage(__('Transaction failed. Please verify your billing information and payment method, and try again.'));
Expand Down
71 changes: 21 additions & 50 deletions Controller/Checkout/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Mollie\Payment\Model\Methods\ApplePay;
use Mollie\Payment\Model\Methods\CreditcardVault;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Service\Mollie\FormatExceptionMessages;
use Mollie\Payment\Service\Mollie\Order\RedirectUrl;

/**
Expand Down Expand Up @@ -70,20 +71,25 @@ class Redirect extends Action
* @var RedirectUrl
*/
private $redirectUrl;
/**
* @var FormatExceptionMessages
*/
private $formatExceptionMessages;

/**
* Redirect constructor.
*
* @param Context $context
* @param Session $checkoutSession
* @param PageFactory $resultPageFactory
* @param PaymentHelper $paymentHelper
* @param MollieHelper $mollieHelper
* @param OrderManagementInterface $orderManagement
* @param Config $config
* @param PaymentTokenRepositoryInterface $paymentTokenRepository,
* @param OrderRepositoryInterface $orderRepository
* @param RedirectUrl $redirectUrl
* @param Context $context
* @param Session $checkoutSession
* @param PageFactory $resultPageFactory
* @param PaymentHelper $paymentHelper
* @param MollieHelper $mollieHelper
* @param OrderManagementInterface $orderManagement
* @param Config $config
* @param PaymentTokenRepositoryInterface $paymentTokenRepository ,
* @param OrderRepositoryInterface $orderRepository
* @param RedirectUrl $redirectUrl
* @param FormatExceptionMessages $formatExceptionMessages
*/
public function __construct(
Context $context,
Expand All @@ -95,7 +101,8 @@ public function __construct(
Config $config,
PaymentTokenRepositoryInterface $paymentTokenRepository,
OrderRepositoryInterface $orderRepository,
RedirectUrl $redirectUrl
RedirectUrl $redirectUrl,
FormatExceptionMessages $formatExceptionMessages
) {
$this->checkoutSession = $checkoutSession;
$this->resultPageFactory = $resultPageFactory;
Expand All @@ -106,6 +113,7 @@ public function __construct(
$this->paymentTokenRepository = $paymentTokenRepository;
$this->orderRepository = $orderRepository;
$this->redirectUrl = $redirectUrl;
$this->formatExceptionMessages = $formatExceptionMessages;
parent::__construct($context);
}

Expand Down Expand Up @@ -151,8 +159,8 @@ public function execute()
return $this->_redirect('checkout/cart');
}
} catch (Exception $exception) {
// @phpstan-ignore-next-line
$this->formatExceptionMessage($exception, $methodInstance ?? null);
$errorMessage = $this->formatExceptionMessages->execute($exception, $methodInstance ?? null);
$this->messageManager->addErrorMessage($errorMessage);
$this->mollieHelper->addTolog('error', $exception->getMessage());
$this->checkoutSession->restoreQuote();
$this->cancelUnprocessedOrder($order, $exception->getMessage());
Expand Down Expand Up @@ -183,43 +191,6 @@ private function cancelUnprocessedOrder(OrderInterface $order, $message)
}
}

/**
* @param Exception $exception
* @param MethodInterface|null $methodInstance
*/
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(
__(
'A Timeout while connecting to %1 occurred, this could be the result of an outage. ' .
'Please try again or select another payment method.',
$methodInstance->getTitle()
)
);

return;
}

$this->messageManager->addExceptionMessage($exception, __($exception->getMessage()));
}

/**
* @return OrderInterface
* @throws LocalizedException
Expand Down
26 changes: 26 additions & 0 deletions Model/Client/Orders/Processors/PaymentLinkPaymentMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Mollie\Payment\Model\Client\Orders\Processors;

use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Api\Resources\Order;
use Mollie\Payment\Model\Client\OrderProcessorInterface;
use Mollie\Payment\Model\Client\ProcessTransactionResponse;

class PaymentLinkPaymentMethod implements OrderProcessorInterface
{
public function process(
OrderInterface $magentoOrder,
Order $mollieOrder,
string $type,
ProcessTransactionResponse $response
): ?ProcessTransactionResponse {
if ($magentoOrder->getPayment()->getMethod() !== 'mollie_methods_paymentlink') {
return $response;
}

$magentoOrder->getPayment()->setAdditionalInformation('payment_link_method_used', $mollieOrder->method);

return $response;
}
}
4 changes: 4 additions & 0 deletions Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ public function startTransaction(Order $order)
{
$this->eventManager->dispatch('mollie_start_transaction', ['order' => $order]);

// When clicking the back button from the hosted payment we need a way to verify if the order was paid or not.
// If this is not the case, we restore the quote. This flag is used to determine if it was paid or not.
$order->getPayment()->setAdditionalInformation('mollie_success', false);

$storeId = $order->getStoreId();
if (!$apiKey = $this->mollieHelper->getApiKey($storeId)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Magento\Checkout\Model\Session;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Payment\Config;
use Mollie\Payment\Model\Mollie;
Expand All @@ -26,19 +25,12 @@ class RestoreQuoteOfUnsuccessfulPayment implements ObserverInterface
*/
private $config;

/**
* @var TimezoneInterface
*/
private $timezone;

public function __construct(
Session $checkoutSession,
TimezoneInterface $timezone,
Config $config
) {
$this->checkoutSession = $checkoutSession;
$this->config = $config;
$this->timezone = $timezone;
}

public function execute(Observer $observer)
Expand Down
42 changes: 42 additions & 0 deletions Service/Mollie/FormatExceptionMessages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Mollie\Payment\Service\Mollie;

use Magento\Payment\Model\MethodInterface;

class FormatExceptionMessages
{
private $allowedErrorMessages = [
'The billing country is not supported for this payment method.',
'A billing organization name is required for this payment method.',
];

private $convertErrorMessages = [
'The webhook URL is invalid because it is unreachable from Mollie\'s point of view' => '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',
];

public function execute(\Exception $exception, MethodInterface $methodInstance = null): string
{
foreach ($this->allowedErrorMessages as $message) {
if (stripos($exception->getMessage(), $message) !== false) {
return $message;
}
}

foreach ($this->convertErrorMessages as $search => $replacement) {
if (stripos($exception->getMessage(), $search) !== false) {
return __($replacement)->render();
}
}

if ($methodInstance && stripos($exception->getMessage(), 'cURL error 28') !== false) {
return __(
'A Timeout while connecting to %1 occurred, this could be the result of an outage. ' .
'Please try again or select another payment method.',
$methodInstance->getTitle()
)->render();
}

return $exception->getMessage();
}
}
13 changes: 13 additions & 0 deletions Service/Order/PaymentReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Mollie\Payment\Api\Data\PendingPaymentReminderInterface;
use Mollie\Payment\Api\Data\SentPaymentReminderInterface;
use Mollie\Payment\Api\Data\SentPaymentReminderInterfaceFactory;
Expand Down Expand Up @@ -74,6 +75,18 @@ public function __construct(
public function send(PendingPaymentReminderInterface $pendingPaymentReminder): OrderInterface
{
$order = $this->orderRepository->get($pendingPaymentReminder->getOrderId());

if (in_array($order->getState(), [Order::STATE_PROCESSING, Order::STATE_COMPLETE])) {
$this->logger->addInfoLog(
'info',
sprintf('Order #%s is already completed, not sending payment reminder', $order->getIncrementId())
);

$this->pendingPaymentReminderRepository->delete($pendingPaymentReminder);

return $order;
}

$this->logger->addInfoLog(
'info',
sprintf('Preparing to send the payment reminder for order #%s', $order->getIncrementId())
Expand Down
78 changes: 77 additions & 1 deletion Test/End-2-end/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,88 @@
const { defineConfig } = require("cypress");

const defaultProductId = process.env.DEFAULT_PRODUCT_ID || 2;

module.exports = defineConfig({
projectId: "44bnds",
chromeWebSecurity: false,
retries: {
runMode: 2,
},
env: {
defaultProductId: defaultProductId,
},
e2e: {
experimentalWebKitSupport: true,
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
require('./cypress/plugins/index.js')(on, config);

return new Promise((resolve, reject) => {
var https = require('follow-redirects').https;
var fs = require('fs');

const baseUrl = config.baseUrl;
const urlObj = new URL(baseUrl);
const hostname = urlObj.hostname;

const query = `
query {
molliePaymentMethods(input:{amount:100, currency:"EUR"}) {
methods {
code
image
name
}
}
}
`;

var options = {
'method': 'GET',
'hostname': hostname,
'path': '/graphql?query=' + encodeURIComponent(query),
'headers': {
'Content-Type': 'application/json',
// 'Cookie': 'XDEBUG_SESSION=PHPSTORM'
},
'maxRedirects': 20
};

var req = https.request(options, function (res) {
var chunks = [];

res.on("data", function (chunk) {
chunks.push(chunk);
});

res.on("end", function (chunk) {
const body = Buffer.concat(chunks);

console.info('Received body', body.toString());

const methods = JSON.parse(body.toString()).data.molliePaymentMethods.methods.map(data => {
return data.code
})

config.env.mollie_available_methods = methods;

console.log('Available Mollie payment methods: ', methods);

resolve(config);
});

res.on("error", function (error) {
console.error('Error while fetching Mollie Payment methods', error);
reject(error);
});
});

var postData = JSON.stringify({
query: '',
variables: {}
});

req.end();
});
},
},
});
Loading

0 comments on commit e48222d

Please sign in to comment.