Skip to content

Commit

Permalink
Merge pull request #93 from vippsas/publication-2.4.8
Browse files Browse the repository at this point in the history
Publication 2.4.8
  • Loading branch information
voleye authored Mar 18, 2021
2 parents c5d5b76 + 981aeba commit 756efc4
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 16 deletions.
56 changes: 44 additions & 12 deletions Controller/Payment/Fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Payment\Gateway\ConfigInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\Quote;
use Magento\Sales\Api\OrderManagementInterface;
Expand Down Expand Up @@ -102,6 +103,11 @@ class Fallback implements ActionInterface, CsrfAwareActionInterface
*/
private $resultFactory;

/**
* @var ConfigInterface
*/
private $config;

/**
* Fallback constructor.
*
Expand All @@ -115,6 +121,9 @@ class Fallback implements ActionInterface, CsrfAwareActionInterface
* @param OrderManagementInterface $orderManagement
* @param Compliance $compliance
* @param LoggerInterface $logger
* @param ConfigInterface $config
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
ResultFactory $resultFactory,
Expand All @@ -126,7 +135,8 @@ public function __construct(
QuoteRepositoryInterface $vippsQuoteRepository,
OrderManagementInterface $orderManagement,
Compliance $compliance,
LoggerInterface $logger
LoggerInterface $logger,
ConfigInterface $config
) {
$this->resultFactory = $resultFactory;
$this->request = $request;
Expand All @@ -138,13 +148,15 @@ public function __construct(
$this->gdprCompliance = $compliance;
$this->orderManagement = $orderManagement;
$this->logger = $logger;
$this->config = $config;
}

/**
* @return ResponseInterface|Redirect|ResultInterface
*/
public function execute()
{
$transaction = null;
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
try {
Expand All @@ -164,7 +176,20 @@ public function execute()
. ' Please contact to store administrator.')
);
} finally {
$this->storeLastOrderOrRestoreQuote();
$vippsQuote = $this->getVippsQuote(true);
$cartPersistence = $this->config->getValue('cancellation_cart_persistence');
$transactionWasCancelled = $transaction && $transaction->transactionWasCancelled();

if ($vippsQuote->getOrderId()) {
if ($transactionWasCancelled && $cartPersistence) {
$this->restoreQuote($vippsQuote);
} else {
$this->storeLastOrder($vippsQuote);
}
} else {
$this->restoreQuote($vippsQuote);
}

if (isset($e)) {
if ($this->getVippsQuote()->getOrderId()) {
$resultRedirect->setPath('checkout/onepage/failure', ['_secure' => true]);
Expand Down Expand Up @@ -287,9 +312,8 @@ private function prepareResponse(Redirect $resultRedirect, Transaction $transact
* Method to update Checkout session with Last Placed Order
* Or restore quote if order was not placed (ex. Express Checkout)
*/
private function storeLastOrderOrRestoreQuote()
private function storeLastOrder(QuoteInterface $vippsQuote)
{
$vippsQuote = $this->getVippsQuote(true);
if ($vippsQuote->getOrderId()) {
$this->checkoutSession
->clearStorage()
Expand All @@ -300,15 +324,23 @@ private function storeLastOrderOrRestoreQuote()
->setLastOrderStatus(
$this->orderManagement->getStatus($vippsQuote->getOrderId())
);
} else {
$quote = $this->cartRepository->get($vippsQuote->getQuoteId());
}
}

/** @var Quote $quote */
$quote->setIsActive(true);
$quote->setReservedOrderId(null);
/**
* @param QuoteInterface $vippsQuote
*
* @throws NoSuchEntityException
*/
private function restoreQuote(QuoteInterface $vippsQuote)
{
$quote = $this->cartRepository->get($vippsQuote->getQuoteId());

$this->cartRepository->save($quote);
$this->checkoutSession->replaceQuote($quote);
}
/** @var Quote $quote */
$quote->setIsActive(true);
$quote->setReservedOrderId(null);

$this->cartRepository->save($quote);
$this->checkoutSession->replaceQuote($quote);
}
}
2 changes: 2 additions & 0 deletions Gateway/Validator/AvailabilityValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function __construct(
*
* @return ResultInterface
* @throws NoSuchEntityException
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function validate(array $validationSubject)
{
Expand Down
1 change: 0 additions & 1 deletion Model/TransactionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ private function acquireLock($reservedOrderId)
throw new AcquireLockException(
__('Can not acquire lock for order "%1"', $reservedOrderId)
);

}

return $lockName;
Expand Down
2 changes: 0 additions & 2 deletions Observer/OrderPaymentAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,5 @@ public function execute(Observer $observer)
$order->setState(Order::STATE_PAYMENT_REVIEW);
$order->setStatus(Order::STATE_PAYMENT_REVIEW);
}

return;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "magento2-module",
"description": "Vipps Payment Method",
"license": "proprietary",
"version": "2.4.7",
"version": "2.4.8",
"require": {
"magento/framework": "103.0.*",
"magento/module-sales": "103.0.*",
Expand Down
10 changes: 10 additions & 0 deletions etc/adminhtml/system/cancellation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
<group id="cancellation" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1"
sortOrder="200">
<label>Cancellation</label>
<field id="cart_persistence" translate="label" type="select" showInDefault="1" showInWebsite="1" showInStore="1"
sortOrder="0">
<label>Cart Persistence</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>
<![CDATA[Cart persistence in case when transaction was cancelled in Vipps.]]>
</comment>
<config_path>payment/vipps/cancellation_cart_persistence</config_path>
</field>

<field id="attempts_count" translate="label" type="text" showInDefault="1" showInWebsite="1" showInStore="1"
sortOrder="10">
<label>Number of Attempts</label>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<subscription_key1 backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
<client_id backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
<merchant_serial_number backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
<cancellation_cart_persistence>1</cancellation_cart_persistence>
<cancellation_type>auto</cancellation_type>
<cancellation_attempts_count>3</cancellation_attempts_count>
<cancellation_customer_inactivity_time>10</cancellation_customer_inactivity_time>
Expand Down
5 changes: 5 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@
<type name="Magento\Sales\Api\OrderManagementInterface">
<plugin name="disable_send_email" type="Vipps\Payment\Plugin\Sales\OrderManagement\AfterPlaceOrder"/>
</type>
<type name="Vipps\Payment\Controller\Payment\Fallback">
<arguments>
<argument name="config" xsi:type="object">Vipps\Payment\Gateway\Config\Config</argument>
</arguments>
</type>
</config>

0 comments on commit 756efc4

Please sign in to comment.