Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/2.30.1 #683

Merged
merged 5 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Block/Form/Pointofsale.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\View\Element\Template\Context;
use Magento\Payment\Block\Form;
use Mollie\Api\Resources\Terminal;
use Mollie\Payment\Logger\MollieLogger;
use Mollie\Payment\Service\Mollie\MollieApiClient;

/**
Expand All @@ -26,15 +27,21 @@ class Pointofsale extends Form
* @var MollieApiClient
*/
private $mollieApiClient;
/**
* @var MollieLogger
*/
private $logger;

public function __construct(
Context $context,
MollieApiClient $mollieApiClient,
MollieLogger $logger,
array $data = []
) {
parent::__construct($context, $data);

$this->mollieApiClient = $mollieApiClient;
$this->logger = $logger;
}

/**
Expand All @@ -47,14 +54,18 @@ public function __construct(
* }
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getTerminals(): array
{
$storeId = $this->_storeManager->getStore()->getId();

$mollieApiClient = $this->mollieApiClient->loadByStore((int)$storeId);
$terminals = $mollieApiClient->terminals->page();
try {
$mollieApiClient = $this->mollieApiClient->loadByStore((int)$storeId);
$terminals = $mollieApiClient->terminals->page();
} catch (\Mollie\Api\Exceptions\ApiException $exception) {
$this->logger->addErrorLog('terminals', $exception->getMessage());
return [];
}

$output = [];
/** @var Terminal $terminal */
Expand Down
25 changes: 15 additions & 10 deletions Controller/Checkout/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Sales\Api\OrderRepositoryInterface;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Model\Mollie as MollieModel;
use Mollie\Payment\Service\OrderLockService;

/**
* Class Webhook
Expand Down Expand Up @@ -50,31 +51,27 @@ class Webhook extends Action
* @var EncryptorInterface
*/
private $encryptor;

/**
* Webhook constructor.
*
* @param Context $context
* @param Session $checkoutSession
* @param MollieModel $mollieModel
* @param MollieHelper $mollieHelper
* @param OrderRepositoryInterface $orderRepository
* @param EncryptorInterface $encryptor
* @var OrderLockService
*/
private $orderLockService;

public function __construct(
Context $context,
Session $checkoutSession,
MollieModel $mollieModel,
MollieHelper $mollieHelper,
OrderRepositoryInterface $orderRepository,
EncryptorInterface $encryptor
EncryptorInterface $encryptor,
OrderLockService $orderLockService
) {
$this->checkoutSession = $checkoutSession;
$this->resultFactory = $context->getResultFactory();
$this->mollieModel = $mollieModel;
$this->mollieHelper = $mollieHelper;
$this->orderRepository = $orderRepository;
$this->encryptor = $encryptor;
$this->orderLockService = $orderLockService;
parent::__construct($context);
}

Expand All @@ -99,6 +96,14 @@ public function execute()
}

foreach ($orders as $order) {
// If this returns true, it means that the order is just created but did go straight to "paid".
// That can happen for Apple Pay and Credit Card. In that case, Mollie immediately sends a webhook,
// but we are not ready to process it yet.
if ($this->orderLockService->isLocked($order)) {
$this->mollieHelper->addTolog('info', 'Order is locked, skipping webhook');
continue;
}

$order->setMollieTransactionId($transactionId);
$this->mollieModel->processTransactionForOrder($order, 'webhook');
}
Expand Down
14 changes: 13 additions & 1 deletion Service/OrderLockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(

public function execute(OrderInterface $order, callable $callback)
{
$key = 'mollie.order.' . $order->getEntityId();
$key = $this->getKeyName($order);
if ($this->lockService->checkIfIsLockedWithWait($key)) {
throw new LocalizedException(__('Unable to get lock for %1', $key));
}
Expand Down Expand Up @@ -85,4 +85,16 @@ public function execute(OrderInterface $order, callable $callback)

return $result;
}

public function isLocked(OrderInterface $order): bool
{
$key = $this->getKeyName($order);

return $this->lockService->isLocked($key);
}

private function getKeyName(OrderInterface $order): string
{
return 'mollie.order.' . $order->getEntityId();
}
}
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.30.0",
"version": "2.30.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.30.0</version>
<version>v2.30.1</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/web/template/payment/giftcard.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!-- ko if: getIssuers() -->
<!-- ko if: getIssuerListType() == 'dropdown' -->
<div class="field-select-billing">
<strong><span data-bind="i18n: 'Select Bank'"></span></strong>
<strong><span data-bind="i18n: 'Select Giftcard'"></span></strong>
<select data-bind="options: getIssuers(), optionsText: 'name', optionsValue: 'id', value: selectedIssuer"></select>
</div>
<br/>
Expand Down